How to Wipe a Hard Drive Using Command Prompt (Windows)

How to Wipe a Hard Drive Using Command Prompt (Windows)

In 2017, researchers at the University of Hertfordshire purchased 200 used hard drives from eBay and second-hand sellers. They recovered sensitive data — including financial records, medical information, and personal photos — from over half of them. The previous owners thought they had erased their drives, but most had only performed a quick format. If you are selling, donating, or recycling a PC, Windows Command Prompt includes built-in tools that can actually overwrite your data — no third-party software required.

Key Takeaways:

  • diskpart clean all writes zeros to every sector on a hard drive, making data unrecoverable — this is the primary Command Prompt wiping method
  • cipher /w only overwrites free space and does not erase active files — useful for cleanup, not full-drive wiping
  • format /p:1 formats a partition with one overwrite pass, but only covers a single partition rather than the entire disk
  • None of these commands work reliably on SSDs — they require firmware-level erase commands available through dedicated erasure software
  • Always triple-check the disk number before running destructive commands — selecting the wrong disk means permanent, irreversible data loss

Three Command Prompt Methods for Wiping a Hard Drive

Windows includes three built-in command-line tools that can overwrite data on a hard drive. Each works differently and serves a different purpose:

Method Scope What It Does Best For
diskpart clean all Entire disk Writes zeros to every sector Full drive wiping before disposal
cipher /w Free space only Three-pass overwrite of unused space Cleaning up after deleting files
format /p:N Single partition Formats + N overwrite passes Reformatting a secondary partition

All three methods are classified as Clear under NIST 800-88 — they perform software-based overwriting that protects against simple data recovery tools. They are not Purge-level, which requires firmware commands or specialized equipment. For HDDs being sold or recycled, Clear is generally sufficient.

These methods only work reliably on traditional spinning hard drives (HDDs). SSDs use wear leveling and over-provisioning to manage writes across flash cells, which means software-based overwriting cannot reach all storage areas. If you need to wipe an SSD, see our guide to secure erasing an SSD.

Method 1: Diskpart Clean All (Recommended)

This is the most thorough built-in option. Diskpart clean all writes zeros to every accessible sector on the disk, destroying all partitions and data in one operation.

Step-by-Step Instructions

  1. Open Command Prompt as Administrator. Press Win + S, type cmd, right-click Command Prompt, and select Run as administrator. Click Yes on the User Account Control prompt.

  2. Launch diskpart. Type the following and press Enter:

    diskpart

    You will see the prompt change to DISKPART>.

  3. List all connected disks. Type:

    list disk

    This displays every disk connected to your system with its number, size, and status. You will see something like:

    Disk ###  Status         Size     Free     Dyn  Gpt
    --------  -------------  -------  -------  ---  ---
    Disk 0    Online          476 GB  1024 KB        *
    Disk 1    Online          931 GB      0 B        *
    Disk 2    Online          232 GB      0 B
  4. Identify the correct disk. Match the disk number to the drive you want to wipe by checking the Size column. If your target is a 1 TB external drive, look for the disk showing approximately 931 GB. Do not guess. If you are unsure, open Disk Management (diskmgmt.msc) in another window to cross-reference drive letters and sizes.

  5. Select the target disk. Replace X with the correct disk number:

    select disk X

    Diskpart will confirm: Disk X is now the selected disk.

  6. Run clean all. Type:

    clean all

    This begins writing zeros to every sector on the disk. There is no progress bar. The cursor will blink at a blank line until the operation completes. For a 1 TB HDD, expect 1-4 hours.

  7. Wait for completion. When finished, diskpart will display: DiskPart succeeded in cleaning the disk. Do not close the window or disconnect the drive during this process.

  8. Exit diskpart. Type:

    exit

After clean all finishes, the disk will show as uninitialized with no partitions. If you want to reuse the drive, you will need to initialize it and create new partitions in Disk Management.

What Happens at the Disk Level

Clean all writes 0x00 (zeros) to every addressable sector on the disk via the operating system's storage driver. This is functionally identical to a single-pass zero-fill — the same result you would get from dedicated tools like DBAN. For modern HDDs, one pass of zeros is sufficient to prevent data recovery according to NIST SP 800-88 Rev. 2.

The plain clean command (without all) only erases the partition table and MBR/GPT metadata. The actual data remains on the platters and can be recovered with free tools in minutes. Always use clean all for data erasure.

Backlit keyboard focused on Enter key

Method 2: Cipher /W (Free Space Overwrite)

The cipher /w command overwrites free space on an NTFS volume. It does not erase existing files — only the free space where previously deleted files may still reside.

Bottom Line: Use cipher /w only when you want to scrub free space after manually deleting files. For full-drive erasure before selling or recycling, use diskpart clean all instead — it is faster, more thorough, and covers the entire disk.

Step-by-Step Instructions

  1. Delete any files you want erased from the target drive first. Empty the Recycle Bin.

  2. Open Command Prompt as Administrator.

  3. Run cipher /w. Replace D: with the drive letter of your target volume:

    cipher /w:D:
  4. Wait for three passes. Cipher performs three overwrite passes on the free space:

    • Pass 1: Writes 0x00 (zeros)
    • Pass 2: Writes 0xFF (ones)
    • Pass 3: Writes random data

    The command displays progress as it works through each pass.

  5. Done. When all three passes complete, the free space has been overwritten. Previously deleted files in that space are no longer recoverable.

Limitations

Cipher /w has several significant limitations:

  • Only overwrites free space — active files are untouched
  • Only works on NTFS volumes
  • Cannot wipe an entire drive — just the unused portions of a single volume
  • Creates a temporary folder called EFSTMPWP during the operation (deleted automatically when complete)
  • Considerably slower than diskpart clean all for full-drive purposes because it performs three passes

Method 3: Format /P (Format with Overwrite)

The format command with the /p switch performs a full format followed by one or more overwrite passes on a single partition.

Step-by-Step Instructions

  1. Open Command Prompt as Administrator.

  2. Identify the drive letter of the partition you want to format and wipe. Open File Explorer or Disk Management to confirm.

  3. Run format with overwrite. Replace D: with the correct drive letter:

    format D: /fs:NTFS /p:1
    • /fs:NTFS — formats as NTFS (use /fs:exFAT for external drives if preferred)
    • /p:1 — performs one overwrite pass after formatting
  4. Confirm the operation. Type Y and press Enter when prompted.

  5. Wait for completion. The format runs first, then the overwrite pass. Progress is displayed as a percentage.

How /P Differs from Clean All

Format /p:1 operates on a single partition, not the entire disk. If your drive has multiple partitions, you would need to format each one separately. It also does not overwrite the space between partitions or the disk's partition table area. Diskpart clean all operates at the disk level and covers everything.

For single-partition secondary drives, format /p:1 is a reasonable option. For full-disk erasure, diskpart clean all is the better choice.

Wiping Your System Drive (Boot Drive)

You cannot wipe the drive Windows is running from because the OS locks its own files. To wipe your system drive using Command Prompt tools:

Option A: Windows Recovery Environment

  1. Boot from a Windows installation USB.
  2. On the install screen, press Shift + F10 to open Command Prompt.
  3. Run diskpart, list disk, select disk X, and clean all as described above.
  4. Note that disk numbers may differ from what you see inside Windows.

Option B: Bootable Erasure Tool Use a dedicated bootable tool like DBAN (free, for HDDs) or BitRaser Drive Eraser (paid, supports SSDs and provides compliance certificates). These boot from USB and can wipe any connected drive. See our complete guide to wiping a hard drive for full instructions.

PowerShell Alternative

Windows PowerShell provides its own disk-clearing cmdlet. Open PowerShell as Administrator and run:

Clear-Disk -Number X -RemoveData -Confirm:$false

Replace X with the disk number (use Get-Disk to list disks). This removes all partitions and data, but like diskpart clean (without all), it does not perform a sector-by-sector overwrite. Data may still be recoverable.

For a zero-fill equivalent in PowerShell, you would still need to call diskpart or use a third-party module. There is no built-in PowerShell cmdlet that replicates clean all behavior.

Why Command Prompt Methods Fall Short for SSDs

Software-based overwriting — whether through diskpart, cipher, or format — writes data through the operating system's storage driver. The OS sends write commands, and the drive's controller decides where to physically place the data.

On HDDs, this works as expected: the controller writes to the exact sectors requested, overwriting whatever was there before.

On SSDs, the flash controller uses wear leveling to distribute writes evenly across all NAND cells, extending the drive's lifespan. It also reserves over-provisioned space that the OS cannot directly address. When you run clean all on an SSD:

  • The controller may redirect writes to different physical cells than where the original data resides
  • Over-provisioned areas (typically 7-28% of the drive's capacity) are never touched
  • Worn-out or remapped cells may still contain old data

The result: fragments of your original data may survive a software overwrite on an SSD. For SSDs, you need firmware-level commands — NVMe Sanitize, ATA Secure Erase, or manufacturer tools. Our SSD secure erase guide covers these methods in detail.

If you need verified erasure with a compliance certificate for any drive type, BitRaser Drive Eraser supports both HDD overwriting and SSD firmware commands, and generates tamper-proof erasure reports.

Command Prompt vs. Dedicated Erasure Software

Feature Command Prompt Dedicated Software
Cost Free (built-in) Free to $299+
HDD wiping Yes (clean all) Yes
SSD firmware commands No Yes (BitRaser, Parted Magic)
Verification after wipe No Yes
Certificate of erasure No Yes (paid tools)
Multiple overwrite patterns Limited (/p:N) Full (NIST, DoD, Gutmann, etc.)
Progress indicator None (diskpart) Yes
Compliance reporting No Yes (HIPAA, GDPR, PCI-DSS)

For personal use on an HDD, diskpart clean all is perfectly adequate. For business, compliance, or SSD erasure, dedicated software is the better path. See our best data erasure software roundup for recommendations.

Common Mistakes to Avoid

Selecting the wrong disk in diskpart. This is the most dangerous error. Clean all is irreversible. Always verify the disk number using the size column, and cross-reference with Disk Management if there is any doubt.

Using clean instead of clean all. Plain clean only wipes the partition table. Your data remains intact and recoverable. Always use clean all for actual data erasure.

Running cipher /w and thinking the drive is wiped. Cipher only overwrites free space. If you did not delete the files first, they are still there untouched.

Using these commands on an SSD. The commands will run without error, but data may persist in areas the OS cannot reach. Use firmware-level commands for SSDs.

Not running as Administrator. All of these commands require elevated privileges. Standard Command Prompt sessions will return access-denied errors.

Frequently Asked Questions

Does diskpart clean all securely erase a hard drive?

Diskpart clean all writes zeros to every sector on an HDD, equivalent to a single-pass overwrite. NIST 800-88 confirms one pass is sufficient to render data unrecoverable on modern hard drives. However, it does not provide verification or certificates, and it is not effective for SSDs.

How long does diskpart clean all take?

Expect 1-4 hours for a 1 TB hard drive over SATA. A 500 GB drive may finish in 30-90 minutes, while a 4 TB drive can take 8 hours or more. USB-connected external drives will be considerably slower due to interface overhead.

Can I use diskpart clean all on an SSD?

The command will execute, but it will not reliably erase all data. SSDs use wear leveling and over-provisioning, hiding some storage from the operating system. For SSDs, use firmware-level commands through dedicated tools or manufacturer utilities.

What is the difference between diskpart clean and clean all?

Clean only removes partition table data — it takes seconds and leaves all file data intact on the disk. Clean all writes zeros to every sector, actually overwriting the data. Only clean all qualifies as data erasure.

Does cipher /w delete files?

No. Cipher /w only overwrites free space on a volume. You must delete files and empty the Recycle Bin first, then run cipher /w to overwrite the free space where those files were stored.

Can I wipe my Windows system drive from Command Prompt?

Not while Windows is running from it. Boot from a Windows installation USB and press Shift + F10 to access Command Prompt, or use a bootable erasure tool like DBAN.

Is format /p the same as diskpart clean all?

They are similar but not identical. Format /p operates on a single partition, while diskpart clean all covers the entire disk including all partitions and inter-partition space. Clean all is more thorough for full-drive erasure.

What happens if I select the wrong disk in diskpart?

All data on that disk will be permanently destroyed with no recovery option. This is why identifying the correct disk number by checking size and cross-referencing with Disk Management is critical before running any destructive command.

Do I need Administrator privileges?

Yes. Diskpart, cipher /w, and format /p all require Administrator access. Right-click Command Prompt and select "Run as administrator" before starting.

Is one overwrite pass enough to securely wipe a hard drive?

Yes. NIST Special Publication 800-88 Rev. 2 confirms that a single overwrite pass prevents data recovery on modern HDDs. The notion that multiple passes are necessary comes from outdated research on older drive technology with lower recording densities.

The Bottom Line

For wiping an HDD using only Windows built-in tools, diskpart clean all is the most effective option — it writes zeros to every sector and meets NIST Clear-level requirements. It costs nothing and requires no downloads. For SSDs, compliance needs, or verified erasure with certificates, switch to dedicated erasure software. Whatever method you choose, triple-check your disk selection before executing any destructive command.


Last updated: February 2026. We regularly review and update our guides to ensure accuracy.

Sources: