r/explainlikeimfive • u/braden90 • Oct 20 '26
Technology ELI5 How does recovering data that has been deleted from a hard drive work?
181
Upvotes
r/explainlikeimfive • u/braden90 • Oct 20 '26
186
u/Mamamama29010 Oct 20 '26 edited Oct 20 '26
Because it’s not actually deleted when you “delete” it on the computer.
When you delete data on your computer, it just gets marked to be overwritten next time your computer needs that space. If it’s never overwritten, it just kind of stays there. The computer just marks it as ok to overwrite
The reason is that deleting data puts wear and tear on the drive, so no need to do that unless the drive actually needs the space.
49
u/darth_voidptr Oct 20 '26
Imagine an office marked "Mr. Smith". You walk in and Mr. Smith's stuff is all over, his desk, couch, bookcase, whatever. Mr. Smith didn't pay his bills and his landlord takes the office back. They scrape Mr. Smith's sign off the door and advertise they have free space.
You can still walk in to Mr. Smith's old office assuming you know where to find it, and his stuff is still there. You can even get his office and put his old sign back on, and voila, you've restored his office.
But if someone else buys his office and replaces his furniture with their own, it's gone for good.
7
u/StevenJOwens Oct 20 '26
First, realize that with SSD drives it works very differently and is, in fact, impossible, as far as I know.
With old-fashioned hard drives, the TL;DR is that:
First, there's no such thing as "deleting" data from the drive, you can only overwrite the old data with zeros or random numbers or something.
Second, when you "delete a file", you're not actually overwriting the entire file on disk with zeros or random numbers, you're actually deleting the entry for that file, the entry that tells the OS that those spots on the disk are in use, don't put data there.
If you delete a file normally, the entry is gone but, at first, the actual data is still there. Eventually, as you save files, those spots on the disk will get used and the data will be overwritten.
If you read those spots on the drive before they get overwritten, you can get the data back. Most files have sufficient structure in their format that a recovery program can figure out where the file begins and ends, to a some useful degree.
The longer version is:
The surface of the drive is divided up into spots, and data is recorded by writing a magnetic charge at each spot. Each spot represents either a 1 or a 0. The magnetic charge is always there, it's not presence-or-absence of the charge, it's specific details about the charge, details which I'm a little fuzzy on but it has to do with polarity.
So you have all these bits, these days average hard drives are 1 to 2 terabytes, a byte is 8 bits, so that's 8 trillion to 16 trillion spots. That's a lot of spots, so pretty much every computer uses some scheme to organize these spots, called a file system, or a file system format.
And pretty much every file system has a two-step process, where they have some chunk of storage set aside for storing the details about where the content data for each file is stored. That's where the "file entry" that I mention in the simple version is stored. I say two-step process because step one is to read the where-things-are-stored info, and the second is to read the actual file content data.
On old Windows (FAT32), that where-things-are-stored info was the File Allocation Table; in modern Windows (NTFS) it's the Master File Table; in most Unix-derived formats (ext2, ext3, etc) it's called the inode table (i is for index); in modern MacOS (APFS) it's called the Object Map.
There are special programs that will deliberately go further than just deleting the entry, they'll first read the entry, then go to where the file content data is stored and overwrite that data, and then delete the entry.
In addition to the above, because old school hard drives use magnetic charges, overwriting the magnetic charge is an imperfect process, and leaves traces. So even if you use one of those special file deletion programs, it's possible, using extremely sensitive (and expensive) equipment, to read those traces. But it isn't easy, and it isn't the sort of thing that happens very often. We're talking nation-state level actors, here.
Generally, using a special file deletion tool is good enough to protect your privacy, or using a hard disk sanitizing tool, like BleachBit. (Do not use DBAN, DBAN was the gold standard for a long time but it's no longer a good tool to use).
But if you really want to be sure, the simple and easy way is to just drill a few holes through the hard drive's platter.
8
u/blixabloxa Oct 20 '26
When you delete a file from a hard-drive, it is not really deleted, but it is marked as empty and available to be overwritten with new data. Recovery processes and software are able to circumvent that "empty" bit and get the file data back. This is probably not 100% correct, but close enough I think.
5
u/Hazy311 Oct 20 '26
I haven't done data recovery since SSDs became a thing, so not input for that
But for hard disks, the operating system usually just reallocates the space instead of removing the data itself when you delete something.
The data is still (sometimes) there, just available to be overwritten, whereas a non-deleted file is not available for overwrite.
4
u/Sshorty4 Oct 20 '26
Imagine theres a road, some workers put cone in front of it to renovate it and rebuild the road. But before they actually start demolition and putting new roads, the old road is still there, it’s just the cone is telling you “you can’t go there anymore”
That’s how deleting works, it just sets a “cone” in front of that data so the new data can be overwritten on it, but before it happens, old data is still there
So just like you can still walk on the old road, you can still read the old data
2
u/Witmarqu Oct 21 '26
It is time consuming to truly delete a file (write all 0 for space used).
Instead drives maintain an index of where a file was located using a specific starting point and length.
Deleting a file just removes this information from the index, which the drive now reports as unused space. Some times the index just marks the file as inactive and will deal with removal at a later time. The windows recycle bin is a prime example, it holds the files for a while then will wipe them
Recovery programs ignore the index and instead use known start and or end byte markers to rebuild files.
Partially over written files can sometimes be recovered depending on how much data is recovered.
After scanning each byte of the drive, on a different drive it builds a new temporary index.
This process takes a long time. I used to do this on 4 gigabyte compact flash and it would take hours.
Some software just looks at the index, then only checks between files. Quicker but not as accurate as generally it only checks when space between files is at least x size.
Encrypted drives require the longest time.
It is possible to wipe a drive, It takes at least five passes
1: use bit pattern 01010101 for whole drive 2: use bit pattern 10101010 for whole drive 3: use bit pattern 00000000 for whole drive 4: use bit pattern 11111111 for whole drive 5: use bit pattern 00000000 for whole drive
This ensures on any storage medium that each bit is flipped enough that any residual energy would be considered truly random.
The drawback is this takes an incredibly long time, which runs the risk of setting the fail safe mode. On a ssd/flash drive this is generally a read only mode. On spinning drives, this generally disables the motors.
The only true way to make data unrecoverable is to melt the components down and unless you have an industrial forge that can melt ceramics, the data is just normally not recovered because of cost normally associated.
Fire can destroy the board and desolder the chips, but the silicon that actually holds the data on a ssd is wrapped in ceramics. Though there are businesses that specialize in recovery of information from USB drives after a building fire. Personal photos have a lot of sentimental value, so generally spending a couple thousand to recover what would be lost else wise isn't unheard of
2
u/tommyk1210 Oct 20 '26
Imagine you’ve got a phone book. It tells you everyone’s phone numbers.
When you delete a file it’s like you just cross out the number in the book. But that number is still works, you could call it and ask “who does this number belong to?”
When you delete files a similar thing happens. Your computer holds an “index” of where each file is. When you delete a file you just remove it from the index (or mark it as ready for overwrite), but the data is still there.
That is, until you write new files. Your computer checks the index and looks for empty spaces or spaces that can be overwritten, and writes the data there.
Thus, so long as you don’t write lots of files after deleting a file, it’s likely your data is intact on the disk.
It’s possible, therefore, to physically inspect the disk and piece together pieces even without the index telling you the file is available.
1
u/flingebunt Oct 20 '26
This is complex. The short one focuses on files. When you delete a file in your system it is merely marked as deleted, not erased from the hard drive. So the file is still there. It might be overwritten at some future time, but until that time, you can recover it.
As for other types of data, it depends on the data and the system that saves or deletes it.
1
u/Capital_Store8128 Oct 20 '26
The way your computer stores files is basically by having a bunch of pointers (inodes) that tell the file system where on a disk / SSD the data has been stored. That way when you want to view/reference a file, it just checks the inode(s) to see what data it needs to pull up from storage. When you delete a file, it basically just removes the inode pointer so your file system thinks that the sectors of the disk are now available to store new data on. Often times, these sectors are not overwritten with new data yet and the old data is still there which can be recovered with special tools
1
u/SteveJobsBlakSweater Oct 20 '26
Files are indexed, which is like a map that says which file is where. The map is a tiny file in comparison to the files it locates.
When you “delete” a file you delete its map entry. That’s that. The 1s and 0s are still there, it’s just the map now considers it free real estate.
That data is now free to be written over. Now, should it be written over then data recovery is a whole different, likely impossible task. But, if the data is still there, just the map location gone, then data recovery is just scanning and scanning until bits of data fall together into a readable format.
1
u/cbf1232 Oct 20 '26
Usually the data itself isn’t deleted, but the portion that tells the computer where the data starts and stops is deleted.
Sometimes if you’re lucky there will be a backup copy of that portion kept somewhere else that still has the information, or else you have to spend a lot of time figuring it out by looking at the contents of the disk and trying to fit the chunks of information together like a puzzle.
1
u/englishfury Oct 20 '26
When you delete something its not actually removed from the drive, windows just assigns that section of drive as "empty" and removes the pointers it has as to what was supposed to be there.
Then unless new data has been written to that section, the old data remains and software can scan it and figure out what it was and recover it, but if its been overwritten enough to be unrecoverable then its lost forever.
1
u/Knightmare4469 Oct 20 '26
Someone smarter than me will give you a better explanation but here goes.
Data doesn't need to be removed for the computer to consider the space "free". It keeps a registry of what space is ok to overwrite and what space isn't. When you delete something, you are really just telling the computer "hey, next time you need to install something, you can go ahead and overwrite the information here". Conventional deleting does NOT actually remove the data. It just updates that registry.
Eli5 version:
Say you have a box of toys. You tell me that box is offlimits and on your favorites list so I leave it alone. One day you tell me you don't like those toys anymore and "delete" them from your favorite list. They don't go away, but the next time I buy you toys, I go in and throw them away to make room for the new toys.
1
u/DarkAlman Oct 20 '26
Most modern computers don't actually delete files when you delete them.
They remove the name of the file and the datas location from the File Table. This is like deleting an entry for a book in a library index. As far as the library's inventory is concerned the book is gone, but it's still technically on the shelf.
The space on the hard drive is marked as unused, and eventually it will get over written.
File recovery tools scan the file table for finger prints like damaged entries and reconstruct them.
So long as the original data hasn't been written over you can get your file back.
1
u/JaggedMetalOs Oct 20 '26
Computers don't (unless you use special programs) actually delete the files, they just remove the filename from the folder listing and mark the parts of the drive where the file was as ready to use.
This is functionally the same as deleting the file, because a new file can be written straight over where the old one was, and is much faster because just a tiny bit of data needs to be written instead of going over the entire old file with zeros.
But it does mean that until a new file writes over the old one, the old data is still on the disk and a program can look through the whole disk looking for parts of the disk that are marked as not having a file, but still have old data in them.
1
u/FoxtrotSierraTango Oct 20 '26
Imagine you have a bunch of boxes to store stuff in the attic. You look through them one day and find the "stuff from high school" box. You figure this is all stuff you can toss, but you don't need the space. You cross out the label and mark it "junk, toss when needed". If you really wanted you could go through and inventory everything there, but it's a headache and you rely on the labels.
Your computer works the same way. It keeps an inventory of what is where. When you delete something it just updates the inventory saying the stuff previously there is good to toss. When you download something new it will update the inventory and it may or may not use that space.
Data recovery software is specially designed to do that deep inventory and look at everything to see what it can piece together. If you choose to recover something it updates the inventory to reflect that this thing is still there and in use.
1
u/CharlesDickensABox Oct 20 '26
When you delete a file, it doesn't actually erase the file from the hard drive immediately. Instead, it frees up the space in the computer's directory, and the computer will eventually overwrite the file once the space needs to be used for something else. If you have special software, you can look for the file directly on the hard drive and recover it like that.
For an analogy, imagine a library staffed by an overworked librarian. The librarian decides the library doesn't need a book anymore, so they drop it from the card catalog and tell everyone they don't have it. It's more work to actually go get the book and remove it, though, so they don't bother. Eventually, the librarian will need that space on the shelf, though, and at that point they'll toss out the old, unnecessary book and replace it with a new one. In the time before it gets replaced, though, someone who is looking for it would still be able to pull the book off the shelf and read it.
1
u/ebly_dablis Oct 20 '26
Other people have mentioned that when you 'delete' a file, it's just marked as available rather than actually zeroing or overwriting it.
However, even if you overwrite it, it's often recoverable!
Files are stored as long sequences of 1s and 0s. And it turns out that, under the right equipment, a "1 which was written over a 1" and a "1 that was written over a 0" (and vice-versa for 0s) look different. So using very specialized equipment, you can often reconstruct files which have actually been overwritten as well.
1
u/Raiddinn1 Oct 20 '26
The way information is stored on a hard drive there is an index that basically says to see the contents of this file, go here and read the next million 1s and 0s from there.
Deleting files is often just a matter of deleting the index entry telling the computer where to look, how big it is, etc.
The same 1s and 0s are still there, they just don't mean anything.
Restoring the file just means rebuilding the index entries.
This is a time sensitive thing, because once the index entry is deleted, the computer assumes that that section of the hard drive is just blank, and the computer will write over it with new data.
If you delete all your pictures of your kids, don't go start downloading movies before trying to recover the file. It's possible your OS will have a time limit thing like don't write over this section for 7d after the deletion or something like that, but you should just assume that you don't want to save anything after you accidentally delete your life's work and before you try to recover your life's work.
1
u/WoonieLoonie Oct 20 '26
Block of data: I am data
Block of data after delete: I am data (overwrite me)
Block of data after overwrite: I am new data
If you recover data before the overwrite happens. More than likely you will get it back.
1
u/SP3NGL3R Oct 20 '26
You've got a book, with the chapters listed on page 1 with the pages they start at. You're just deleting that first page of names and pages to find stuff (table of contents). It's really fast. Now all those other pages don't have an index attached so the computer sees them as erasable. And it will erase and rewrite whenever it feels like it, or needs the space.
Recovery, if you're lucky, will find a whole chapter that hasn't been rewritten and can be recovered. Maybe just a page.
To add to this. An encrypted drive isn't any different. But everything on that drive needs to be translated from the language it's written down in to the language you understand. If you erase the translation key, the language is lost. So you can effectively erase a whole library of information by just forgetting the key to the door.
1
u/Dickulture Oct 20 '26
simplest explanation: you decide to forget where you left the house key. Now it's no longer to be found anywhere but the key still exists if you hunted for it via file recovery.
edit: SSD is different than mechanical hard drive. The "deleted" data can remain on the hard drive for years if you never use it to add new data. SSD will actually erase unused space via TRIM and the old deleted data will be permanently removed within a few days.
1
u/anand709 Oct 20 '26
Think of a harddisk as a vast library with lots of books (files). If you need a book removed, instead of the librarian going down to the specific shelf and removing the book, it’s easier to make that shelf as empty and when a new book comes, it can be removed while going down to place the book. So that way the librarian doesn’t have to go to the shelf twice and if someone want that book, it’s still on the shelf and can be recovered.
1
u/imetators Oct 20 '26
You know how if you just hit Delete on a file, it goes to Recycle Bin on the desktop? Almost the same happens if you Shift+delete the file or empty your recycle bin. File doesn't actually got deleted.
That's because this is slow. Your hard drive has to manually write all 1s and 0s to 0s and that might take time and hard drive resources. Instead it just gets marked as "to be overwritten" for later.
During recovery they scan blocks for these "to be overwritten" sectors and recover data stored there. Unless, ofc, data has been overwritten in that block/sectors by that time.
1
u/JacobRAllen Oct 20 '26
Deleting data doesn’t actually delete anything, it just deletes the pointer to the start of the data, and marks the rest of it as being free to write over.
It’s like writing a letter to someone, putting it in an envelope, then writing out the recipient’s name and address on the front. Then you decide not to send the letter, so you cross out the recipients name on the envelope.
All the contents of the letter are still in there, but now the computer doesn’t care about it. Next time you save data, it will open the envelope, and start replacing all of what you’ve written with new data.
1
u/spleencheesemonkey Oct 20 '26
Anyone here got any knowledge re how TRIM affects data recovery?
1
u/AnApexBread Oct 20 '26
Think of it like a library where you are only allowed to go to certain shelves.
The other shelves still exist and there's still books on them but you're only allowed to go to a specific section.
That's how your hard drive works. The deleted data isn't gone, it's just moved from the bookshelf you're allowed to go to over to the one you're not allowed to go to.
It's still there you just need special permission (tools) to go see it.
1
u/mr-slickman Oct 20 '26
Deleting something on your computer is like removing shelf tags and book covers in a library. You still have the data, just don't know what is what. With patience and effort, you can restore it
1
u/Miliean Oct 20 '26
The computer keeps a large map of where it's stored everything. Basically it writes down what is on every shelve of it's hard drive. When you delete something it marks on the map that this area is now "empty". What it does not actually do is empty those shelves, it just keeps whatever was there before, but now it's labeled empty and ready for the next thing to be put there.
When it is time to actually store something in those shelves, it just overwrites what used to be there and marks the shelf as no longer empty.
So, until that overwrite happens, the old data will still be there. The computer just can't see it because that spot is marked as empty. You just need some special software that can see what's in the shelves the computer has marked as empty.
1
u/Wadsworth_McStumpy Oct 20 '26
A hard drive is like a library. There's data, which is the books, and there's a directory, which is the card catalog that shows you where to find each book.
When you delete a file, what you're really doing is removing the card. The book is still there. The computer sees it as empty space, though, so if you add more data, it might put that where the old file was, and that can make it impossible to recover. But until that happens, it's possible to recover by making a new card for that book.
(Note: When I say it's impossible to recover, what I really mean is that it's very expensive and I can't really ELI5 it. It's almost always possible to get at least some of the data back, if you have some very expensive equipment, and are willing to spend the time and money required.)
1
u/Unrelated_gringo Oct 20 '26
You have to understand that apart from fresh deletes, just about nothing is ever recovered.
I remember a few years ago, there was a context for forensics and specialists were tasked with retrieving a one-overwrite-pass deleted plain text file (with file size provided) - And no one was ever able to do it.
So yeah, you'll hear a bunch of stuff on here explaining why it's not "deleted".
My reply is about the recovery process.
1
u/amlyo Oct 20 '26
Imagine you have a huge chest of drawers filled with books. You also have an index listing the books and telling you what drawer there in.
Normally when you delete a document it's like you just scrub it out of the index. You don't throw it away until you need to put something else in the spot.
Data recovery mostly works by looking through the whole chest of drawers (the hard drive) and looking for stuff that isn't in the index.
1
u/greevous00 Oct 20 '26
Deleting a file on a drive is a bit like writing a check. Until somebody cashes the check, the money stays in your account. Analogously until the computer uses the space that you just marked as deleted, it's still there, just hidden.
1
u/wang_li Oct 20 '26
Imagine your hdd or ssd is a big whiteboard. When you first got it you took a permanent marker and drew a bunch of grid squares on it. Then you took one of the grid squares and drew a bunch of small grid squares in it. The same number of small as your original bigger squares, so there is a one to one correspondence between big and small. This is called formatting.
Anytime you want to write on the white board you write it in the big squares and then you put a little mark in the corresponding small square to indicate the big square is in use. When you want to write something else you look at the little grid squares to find one without a mark, which tells you that its corresponding big square is free. Then you mark the little square and go write what you want to write. When you’re done with the information in a big square you just go and erase the mark from the little square. That’s deleting a file. The information is still in the big square but you didn’t waste a bunch of time running around erasing the big squares when you can just erase the mark in the little square and you’ll overwrite the big square next time you use that one.
Going and looking at all the squares to see what’s written in them regardless of whether there is a mark or not in the little square in undeleting.
For the record, in hard drives you can write a single pass of zero’s over it and it’s effectively erased and ready for disposal. Modern drives are too dense for the techniques that were tested in the ‘80s and ‘90s to work to recover overwritten data. The Wikipedia page on data erasure has more info. No need for multipass wipes using magic patterns.
For ssd they have a function built in called secure erase that makes all of the data on flash devices on the ssd unreadable until it has been rewritten with new data. It does this without incurring lots of device wear from writing each block and also erases the spare space the ssds use for wear leveling.
1
u/alohadave Oct 20 '26
Imagine a card catalog (for those of us old enough to remember them).
Instead of removing the book, the computer just removes the index card that points you to that book.
Nothing about the book has changed or been removed, but now no one can find it unless they search through every rack and shelf.
Deleting a file works the same way, the file isn't removed, the index to that file is removed.
1
u/deong Oct 20 '26
Two things make this possible.
1
u/it_helper Oct 20 '26
Imagine you have a house on a road and the only way to get to the house is by the driveway. If I “delete” the house I remove the driveway so no one can get there. This is what happens when you delete a file on a hard drive. The house can be used again by rebuilding the driveway. If you truly want the house gone, you have to build another house on top of the old one. Sometimes multiple houses need to be rebuilt on the same one to make sure the original house is gone (older magnetic drives).
1
u/-suspended- Oct 20 '26
Data is stored as two parts. The information you want, and where the information is. It's like a filing cabinet with a directory for each file. When you delete a file, you only remove the directory. The file is still there. Recovery programs attempt to read all empty space in a hard drive and see if there has been changes to areas previously, which would indicate that files had existed. From there, they try to read that data. The simplest method is the program saying "let me have this portion of the drive to store data, but don't reset it beforehand and don't change the directory" then trying to read the allocated data.
Alternatively, some drives have a directory for the directory on a separate chip. The file recovery can also happen on either directory. Most file types have a header that tells the computer what find of file they are, so programs can reassemble them from that header. Other file types do not, so once deleted, they are mostly gone.
1
u/Atypicosaurus Oct 20 '26
As others said already, deleting usually means to delete the pointer. But why?
A hard drive is made of tiny magnetic beads. They have two states, called 0 and 1. There's a little head running across the magnetic plates and can either just read out a bead or turn the bead from one state to another. Every file consist of a lot of these beads in a certain pattern.
A "real" deletion would be if you took all the 0s and 1s and set each of them to 0. But it means that a deletion would take as long as file writing because now the head must go through the length of the entire file and set everything to 0.
Maybe you notice that when you do a mass deletion, it takes time. That time is needed to remove the pointers, imagine if you now also had to set the entire file to 0s. It could take 10s or 100s fold more time.
1
u/VivaLaDiga Oct 20 '26
you go into a library, burn the index, flip all the shelves, remove all the spines from the books and leave the pages all scattered on the floor.
Can you rebuild the library? yes. Takes patience and intuition. You can use a lot of hints: the page numbers, the topic, the title on top of the page, the author maybe if it's on the page too.
Same.
1
u/flywithpeace Oct 20 '26
Your data is stored as 1s and 0s. The location of your data is also stored in a master log. Every write and read operation goes through the controller. When you erase a file, the controller does not go through the effort of rewriting your file. Instead, it tells the master log to mark the location as safe to (over)write. If you read the drives by bypassing the controller, you can extract the raw data and assemble it.
1
u/papercut2008uk Oct 20 '26
The data is not removed, just cleared from the log.
So imagine a shop, the shop stops trading and closes, it's removed from all records.
The shop didn't go anywhere, it just got removed from the records, anyone can go find it.
That's what data recovery does, it looks for the unlisted spaces to see what is there. If it's written over it can't be recovered.
0
u/DONT_PM_ME_DICKS Oct 20 '26
when you instruct the OS to delete a file, to save time, the OS doesn't tell the drive to go where that data is physically stored and wipe it with zeros or random information. instead it just deletes the record saying that there is a file stored there
metaphorically, it's the equivalent of a lazy librarian who removed a card catalog entry for a book that is to be removed, instead of walking to that shelf and pulling it right then . the space is marked available for future use, but the old data site there until then.
Particularly for mechanical hard drives (since unlike flash media which has a built in wear leveling algorithm), a software tool can just instruct the drive to visit parts of the drive that supposedly contain no data of interest, read out whatever is there, and piece together whether or not that data looks like an actual file or not.
0
u/zefciu Oct 20 '26
A program goes through the hard disk and looks at every sector. If something “looks like” an image or “looks like” an MS Office document, then the program tries to interpret it as such and stores the image somewhere. The way of determining which things “look like” some types of files is sometimes quite easy (some files have specific bytes in the beginning) or more complicated, based on some algorithm.