Flashing guides frequently include a "wipe cache and data" step without explaining what the underlying commands actually do or why one partition needs a full filesystem format while another only needs its blocks zeroed. Getting this wrong on the wrong partition is one of the more common ways a routine ROM flash turns into a device stuck in a boot loop.
fastboot erase <partition> zeroes out the raw blocks of a partition without writing a new filesystem structure to it. The next time Android boots, it detects the partition is unformatted and creates a fresh filesystem on first mount.
fastboot format <partition> does both steps at once: it erases the blocks and immediately writes a new, empty filesystem (typically ext4 or f2fs depending on the partition and device) so the partition is mountable right away, without waiting for Android to do it on first boot.
For most user-triggered wipes, format is the safer choice because it guarantees a consistent filesystem state immediately. erase is more commonly used inside flashing scripts where the ROM installer itself creates the filesystem afterward, making a pre-formatted partition redundant work.
fastboot erase cache
fastboot format userdata
fastboot format cache
fastboot erase metadata
Flashing a new ROM build from the same source and same Android version as the currently installed one usually does not require wiping userdata — a "dirty flash" over the existing installation works in most cases. A wipe becomes necessary when:
Never run fastboot erase or fastboot format against boot, system, vendor, persist, or any partition holding calibration data (Wi-Fi MAC address, IMEI-related data, DRM keys) unless you have a verified backup and know exactly what you are restoring. These are not filesystem partitions in the same sense as userdata — several of them hold raw binary images that a generic erase or format command will corrupt rather than reset cleanly, and some (persist, calibration partitions) cannot be regenerated from a stock firmware package at all.
All of the erase and format commands above fail with a permission error on a locked bootloader, the same restriction that applies to flashing. If fastboot format userdata returns something like "FAILED (remote: 'Erase is not allowed'"), the bootloader is locked and the unlock step needs to happen first — there is no wipe workaround for a locked device.
After wiping userdata and rebooting, the device should boot to the initial Android setup wizard rather than a lock screen prompting for a PIN or password. If it instead boots directly past setup to a home screen with old apps still present, the wipe did not actually complete, most often because the device was still communicating with a stale Fastboot session; reboot into Fastboot fresh and repeat the command.