When the normal right-click format fails - RAW file system, wrong size, stubborn errors - the diskpart clean route rebuilds the pendrive from an empty partition table. It is the strongest format Windows has built in, and it demands respect: one wrong disk number erases the wrong drive.
Diskpart works below the level of the normal format tool. Instead of repairing the existing partition, clean deletes the partition structure itself, and you then create a fresh partition and format it. That is why this route fixes drives that defeat the normal format - and why the disk-selection step matters more than every other step combined.
Use diskpart clean when the normal format fails with errors, the file system shows RAW, the drive reports a wrong smaller size because of a broken partition (common after making a bootable USB), or a previous format was interrupted. Do not use it as a first step for a simple write-protected message - try clearing the read-only attribute first, because clean erases everything while the attribute fix erases nothing.
cmd, press Enterdiskpart and press EnterEvery command below is typed in that Diskpart window, one at a time, pressing Enter after each.
Type list disk. You will see every disk in the PC, including the internal drive Windows lives on. Find the pendrive by its capacity - a 32 GB pendrive shows about 29 GB, a 64 GB one about 58 GB. Selecting the wrong disk and running clean erases that disk completely, including your Windows drive. If two disks show the same size and you cannot tell them apart, unplug the pendrive, run list disk again, and note which number disappears. That is your disk.
select disk X - X is your pendrive's numberattributes disk clear readonly - removes a software lock if one is setclean - wipes the partition tablecreate partition primaryformat fs=exfat quick - or fs=fat32 for small drives and old devicesassign - gives the drive its letterexitEach step should answer with a success message before you move to the next.
Diskpart failures are informative. Write protected returning at the clean step means the controller lock - the drive is dying, not misconfigured. An I/O device error means the PC cannot reliably talk to the memory at all - try another port once, then accept the verdict. Access denied usually means the Diskpart window is not running as administrator. Read the error instead of retrying blindly; it is pointing at the real cause.
After assign, the pendrive appears in Explorer with its full size. Do not trust it yet. Copy a large file onto it - a video of a few hundred MB - then copy it back and compare, or simply play it from the drive. Eject with Safely Remove Hardware, reinsert, and confirm the file is still there. A drive that survives this test is genuinely rebuilt; a drive that corrupts the test file has a hardware problem no format will fix.
Watch the video for the live run of this sequence, including the list disk output and how the correct disk is chosen.
▶️ Watch Full Videoclean only removes the partition table - fast, and the old data still physically sits on the memory until overwritten. clean all additionally writes zeros over every sector, which takes a long time on flash drives and wears them. For fixing a format problem, plain clean is enough.
Stop immediately - do not create partitions or format that disk, and do not install anything on it. Partition recovery software can often rebuild the table if nothing new was written. Every write after the mistake lowers the chance, so the disk should stay untouched until recovery is attempted.
For a rebuild after clean, quick is fine - the partition is brand new. Leave quick off only when you want Windows to scan every sector for damage, which is a diagnostic choice: a full format that stalls is itself evidence of dying flash.