Is it really gone?
You delete a file and empty the bin. The space comes back and the file no longer appears anywhere. It seems reasonable to assume the data has been destroyed.
Usually it has not. To see why, you need to know what a file actually is.
A file is a name pointing at blocks
A disk is a very long row of numbered blocks. The contents of a file are written into some of those blocks.
Separately, the file system keeps a record for each file: its name, its size, and which blocks hold its data. A folder is just a list of such records.
So a "file" is really two things:
- the data, sitting in blocks on the disk, and
- the entry that gives it a name and says where the data is.
The entry is tiny. The data can be gigabytes.
What delete does
The folder
- photo.jpgblocks 2, 3, 4
- notes.txtblocks 7, 8
The disk
Red: marked as available, but still holding the deleted file's data.
Start. A disk is a long row of numbered blocks. A file is two things: its data, spread over some blocks, and an entry in a folder that gives it a name and says which blocks are its own.
- Files you can see
- 2
- Blocks still holding deleted data
- 0
The entry is removed from the folder
The name is gone. No program that lists files will see it.
The file's blocks are marked as available
The file system notes that these blocks may be reused.
That is all
The blocks themselves are not touched. The data is still there, byte for byte.
This is why deleting a 50-gigabyte file takes a fraction of a second, when writing it took minutes. Nothing is erased. A few small records are updated.
When it actually disappears
The data survives until the file system gives those blocks to another file and that file's contents are written over them. That might happen within seconds on a busy, nearly full disk. On a large, half-empty one it might not happen for months.
And it need not happen all at once. In the animation, a new file reused two of the three blocks. The remaining block still holds the last part of the deleted photo.
Example
Recovering a deleted file
Recovery tools work by ignoring the folder and reading the raw blocks. They look for blocks marked as available that still contain recognisable data, such as the pattern that begins every photo file, and stitch the pieces together.
This is why the first rule after deleting something by accident is: stop using that disk. Every new file written is a chance of overwriting what you want back.
The bin is one more layer
Moving a file to the bin does even less. The entry is simply moved to a special folder. Nothing is marked as available, which is why restoring from the bin is instant and always works. Emptying the bin is the step described above.
Why this matters for privacy
If the data stays on the disk, then selling, donating or throwing away a computer can hand its contents to the next person, even after everything was "deleted" or the disk was quickly reformatted. A quick format mostly resets the records, like tearing out a book's table of contents and leaving the pages.
To really remove data:
Encrypt the disk from the start
This is the best protection. With full-disk encryption, the blocks only ever contain scrambled data. Destroy the key and every block is unreadable at once. Modern phones and laptops do this by default.
Use the system's secure erase or reset
A proper "erase all content" or secure-erase function instructs the drive itself to wipe everything.
Overwrite, on older spinning disks
Writing zeros or random data over the whole disk destroys what was there.
The same idea elsewhere
"Remove the reference, leave the data" appears all over computing, because it is fast.
- Databases often mark a deleted row as dead and reclaim its space later.
- Garbage collectors free memory once nothing refers to it. See Garbage Collection.
- Git keeps commits you "deleted" for weeks, which is why they can be recovered. See Undo Anything in Git.
Key takeaways
- A file is a name and record pointing at blocks of data on the disk.
- Deleting removes the record and marks the blocks as available. The data is not erased.
- The data stays until another file happens to be written over those blocks.
- That is why deletion is instant, and why deleted files can often be recovered.
- To truly remove data, use disk encryption and the system's secure erase.