On a hard drive, you can securely delete a file by overwriting it before removing it: shred -u file on Linux or sdelete file on Windows. On an SSD, phone or any flash storage, file-level overwriting is unreliable, so the dependable method is to keep the drive encrypted (BitLocker or FileVault) and, when you dispose of the device, use its built-in erase or reset.
The reason is how each kind of storage writes data. This article shows what each tool does, where it stops working, and what to use instead.
Why normal delete is not secure
Deleting a file, even emptying the Recycle Bin or Trash, removes its directory entry and marks the space as free. The contents stay on the disk until new data happens to land there. Microsoft's SDelete documentation puts it plainly: when the operating system is not running, "it is possible to use raw disk editors and recovery tools to view and recover data that the operating system has deallocated."
Secure deletion tools fix this by writing over the file's contents first. That works only if the new data goes to the same physical place as the old data, and that assumption is exactly what modern storage breaks.
Linux: shred
shred is part of GNU coreutils. To overwrite a file three times with random data, add a final pass of zeros, then delete it:
shred -v -n 3 -z -u test-secret.txt
Real output from GNU shred 8.32 on a 17-byte test file (the middle renames are trimmed):
shred: test-secret.txt: pass 1/4 (random)...
shred: test-secret.txt: pass 2/4 (random)...
shred: test-secret.txt: pass 3/4 (random)...
shred: test-secret.txt: pass 4/4 (000000)...
shred: test-secret.txt: removing
shred: test-secret.txt: renamed to 000000000000000
shred: 000000000000000: renamed to 00000000000000
...
shred: 00: renamed to 0
shred: test-secret.txt: removed
The four passes are the three random ones plus the zero pass from -z. The renames replace the name with zeros of the same length and then shorten it one character at a time, so the original file name does not stay in the directory. The options:
-n 3: number of overwrite passes. 3 is the default.-z: "add a final overwrite with zeros to hide shredding".-u: "deallocate and remove file after overwriting". Without it, shred overwrites the file but leaves it in place, because it is also used on whole devices.-v: show progress.
shred's own help carries the limitation in capitals: "CAUTION: shred assumes the file system and hardware overwrite data in place. Although this is common, many platforms operate otherwise. Also, backups and mirrors may contain unremovable copies." Copy-on-write file systems write changes to new locations by design, snapshots and RAID mirrors keep extra copies, and SSDs relocate every write, so on all of them the old data can survive somewhere shred cannot reach.
Windows: SDelete and cipher /w
Windows has no built-in command that overwrites a single file. Microsoft's Sysinternals SDelete fills that gap:
sdelete -p 1 C:\work\secret.txt
sdelete -s -p 1 C:\work\old-project
-p sets the number of passes (default 1) and -s recurses into subdirectories. SDelete handles NTFS compressed, encrypted and sparse files specially, because for those NTFS writes changes to new clusters; SDelete finds the real clusters through the defragmentation API and overwrites them directly. It also renames a file 26 times to scrub its name. One limit Microsoft states: SDelete "securely deletes file data, but not file names located in free disk space."
To clean data from files you already deleted the normal way, overwrite the free space instead. Windows includes a command for that:
cipher /w:C:\
Microsoft's description: it "removes data from available unused disk space on the entire volume". The path only selects the volume, so cipher /w:C:\work still cleans all free space on C:. Expect it to take a long time on a large drive. sdelete -c C: ("clean free space") does the same job with SDelete, which works by allocating the largest file it can and overwriting it.
Why overwriting fails on SSDs
An SSD never overwrites a block in place. When you rewrite a file, the drive's controller writes the new data to a fresh flash location, updates its internal map, and leaves the old copy to be erased later. It also keeps spare capacity you cannot address. NIST's media-sanitization guideline (SP 800-88 Rev. 2, September 2025) gives an example of a device with 1024 GB of physical flash but only 900 GB of user-accessible capacity, and states that devices "that contain spare cells and perform wear levelling make it infeasible for a user to sanitize all previous data" by overwriting, because the old data is in locations the normal read and write commands cannot reach.
NIST goes further: for SSDs with overprovisioning, multi-pass overwriting "should be avoided as very little confidentiality protection is achieved." So shred, SDelete and cipher /w on an SSD give a false sense of security: the file disappears from view while copies may remain in flash. Apple says the same from the other side: "With a solid-state drive (SSD), secure erase options are not available in Disk Utility."
What works on SSDs: encryption, then erase the key
If the whole drive is encrypted from the start, every copy the controller ever wrote, including stale ones in spare blocks, is ciphertext. Destroying the key makes all of it unreadable at once. NIST calls this cryptographic erase and classifies it as a Purge technique: key sanitization that makes "recovery of the decrypted target data infeasible".
- Turn on full-disk encryption now. BitLocker or Device Encryption on Windows, FileVault on a Mac (Apple's Disk Utility guide recommends turning it on "when you start using your SSD drive"), LUKS on Linux. Encryption protects files deleted from today onward, not the unencrypted copies written before you enabled it.
- To dispose of a Windows PC: Settings > System > Recovery > Reset PC > Remove everything, and turn on Clean data. Microsoft says it "removes files and cleans the drive" and recommends it "if you're planning to donate, recycle, or sell your PC".
- To dispose of a Mac: on Apple silicon or T2 Macs with macOS Monterey 12 or later, System Settings > General > Transfer or Reset > Erase All Content and Settings, which Apple says will "quickly and securely erase all of your data, settings, and apps".
- For a loose SSD: use the drive vendor's dedicated sanitization function, usually through the manufacturer's management tool. NIST notes these interfaces "typically operate at the device level", so they erase the whole drive rather than single files.
NIST's three levels: Clear, Purge, Destroy
Current guidance is NIST SP 800-88, not the old DoD 5220.22-M overwrite patterns many tools still advertise (NIST notes the DoD removed its overwriting specifications in 2006). It sorts methods by how much effort recovery would take:
| Level | NIST definition (shortened) | Examples |
|---|---|---|
| Clear | Logical techniques on all user-addressable locations, protecting against "simple, non-invasive data recovery" | Overwriting a hard drive; a factory reset |
| Purge | Makes recovery infeasible "using state-of-the-art laboratory techniques" | Cryptographic erase; the drive vendor's device-level sanitize function |
| Destroy | Purge-level result plus the media can no longer store data | Shredding, disintegrating or pulverising the drive |
For a personal laptop, encryption plus the built-in reset is the practical target. For a drive that held regulated or highly sensitive data, follow your organisation's policy, which may require Purge with verification or physical destruction.
Copies you forgot about
Wiping the original rarely removes every copy. Before you rely on any of the above, check:
- Cloud sync and backups: OneDrive, iCloud Drive, Dropbox, Time Machine and File History keep their own copies and often deleted-file history.
- Snapshots: file system snapshots, such as Btrfs or ZFS snapshots or a NAS's snapshot feature, keep old versions of files as they were.
- Temporary and swap files: editors and apps write autosave and temp files; the system may page file contents to disk.
- Email attachments and chat apps where the file was shared.
Deleting a file securely is mostly about where else it lives. Encryption covers the device; the copies elsewhere need their own deletion. For how encryption differs from hashing, which is sometimes confused with it, see hashing vs encryption.
Frequently asked questions
- Does emptying the Recycle Bin or Trash delete a file permanently?
- No. It removes the file's entry from the file system and marks its space as free, but the data stays on the disk until something overwrites it. Until then, recovery tools that read the raw disk can often get it back.
- How many overwrite passes do I need?
- For a hard drive, one pass is the practical standard: SDelete defaults to 1 pass and shred to 3. NIST SP 800-88 notes that older multi-pass schemes ranged up to 39 passes and that overwriting gives very little protection on SSDs with overprovisioning, where extra passes do not help. For flash storage, rely on encryption and the drive's own sanitize or reset functions instead.
- Is the DoD 5220.22-M method still required?
- No. NIST SP 800-88 Rev. 2 notes that the U.S. Department of Defense removed overwriting specifications from that manual in 2006. Tools still advertise it, but current guidance is NIST's Clear, Purge and Destroy categories.
- What is the safest way to wipe a laptop before selling it?
- Use full-disk encryption (BitLocker or FileVault) during normal use, then the built-in reset. On Windows 11 that is Settings > System > Recovery > Reset PC > Remove everything with Clean data turned on. On a Mac with Apple silicon or a T2 chip, use System Settings > General > Transfer or Reset > Erase All Content and Settings.
Sources
- NIST SP 800-88 Rev. 2: Guidelines for Media Sanitization (September 2025)
- Linux man-pages: shred(1)
- Microsoft Learn: SDelete (Sysinternals)
- Microsoft Learn: cipher
- Microsoft Support: Reset your PC
- Apple Support: Erase and reformat a storage device in Disk Utility
- Apple Support: Erase your Mac and reset it to factory settings