Does defragmenting delete files?
No: defragmenting moves the pieces of your files into contiguous runs so a hard drive can read them faster, and it does not delete the files that are there. It matters for data recovery anyway, because a defrag pass rewrites data across the free space on the drive and can overwrite the remnants of files you deleted earlier. On an SSD, Windows' Optimize Drives runs a retrim instead, which is worse for recovery, not better.

No. Defragmenting a drive does not delete the files on it. Defragmentation (defrag) is a maintenance task that moves the pieces of your files around so each one sits in a single continuous run on the disk, which helps a spinning hard drive read it faster. Your files are read and rewritten in place: nothing is erased. The reason defrag still belongs in any conversation about lost data is a side effect: a defrag pass rewrites data across the free space on the drive, so it can stomp on the leftover traces of files you deleted earlier. That is why you never defragment a drive you are trying to recover files from.[1][2]
What defragmentation actually does
As a drive fills up and files are created, resized and deleted, a file can end up split into pieces scattered across the disk. Microsoft defines defragmentation as the process of moving portions of files around on a disk so that a file's clusters sit in contiguous locations. Clusters are the small fixed-size blocks the file system hands out, and the mover works on them directly: the documented process finds empty clusters, works out where a file's clusters currently sit, and relocates each one with a control code whose whole job is moving file data to a new position on the disk. If the gap it needs is not there, it moves other files to make one.[2]
Does it delete anything?
Deleting files is not part of what defragmentation does, and it is not the goal either: Microsoft describes the purpose as consolidating fragmented regions of files to improve performance of sequential reads and writes. After a defrag your documents, photos and programs are all still there, with the same contents they had before, just stored more tidily. The distinction worth keeping straight is location versus existence: defrag changes where your files live on the disk, not whether they exist.[1][2]
The one way defrag hurts recovery
When you delete a file, the file system drops the file's record but the file's bytes usually stay on the disk, in space the file system now treats as free. That unused space is exactly what a defrag pass writes into while it rearranges things, because making a file contiguous means filling in the gaps with relocated data. Microsoft ships a command, cipher /w, whose stated purpose is to remove data from available unused disk space on an entire volume, which shows the mechanism plainly: deleted bytes survive in unused space until something writes across that space. A defragmentation is that something.[2][3]
So the full answer to the headline question is: defrag does not delete the files that are on your drive, but it can finish off files you deleted earlier, because rearranging a drive overwrites the free space where their remnants sit. If there is any chance you will want a deleted file back, defragmenting is one of the fastest ways to shrink your odds.[2]
Never run a defrag on a drive you want to recover deleted files from, and stop using that drive for everything else too: every write to it, including a defrag's relocations, can land on top of the data you are trying to save. Defragmentation is maintenance for a healthy drive, not a step in recovering data. If the drive still boots, write as little to it as possible and scan it read-only from other storage. If it does not boot, do not install anything onto it.[2]
When recovery software makes things worse
Should you defrag an SSD?
For a solid state drive the answer is that you do not, and modern Windows will not do it either. The tool still exists, as Optimize Drives (Optimize-Volume in PowerShell), but when it runs on a volume with no options specified, only a hard disk gets the analyze-plus-defrag treatment. An SSD with TRIM support gets a retrim instead of a defrag, and an SSD without TRIM support gets no operation at all. Windows already knows an SSD does not need defragmenting.[1]
That retrim is worse for recovery than a defrag, not better. A retrim generates TRIM and Unmap hints for all currently unused sectors of the volume, telling the drive that space is no longer needed and can be purged. TRIM is delete notification: Windows reports to the storage device which clusters a file delete freed, and on NTFS that reporting is enabled by default. So while defragmenting a hard drive puts deleted data at risk by accident, optimizing an SSD points the drive at every unused sector at once and invites it to erase what is there. We cover that mechanism in detail in SSD TRIM and deleted files.[1][4]
SSD TRIM: why deleted files are harder to get back
Practical rules
How to treat defrag and Optimize Drives
- Healthy spinning hard drive, nothing missing: defragmenting is safe for your files. It moves them, it does not erase them.
- Deleted files you want back: do not defrag that drive, and do not run any other write-heavy tool on it. Copy nothing onto it. Scan it read-only.
- Solid state drive in normal use: leaving Optimize Drives on its schedule is fine as maintenance, but understand what it is doing. On an SSD it sends a retrim, not a defrag, and a retrim tells the drive to purge unused space.
- Mid-recovery on any drive type: no defrag, no optimize, no new installs on the drive in question until the files you care about are safely copied off it.
If it is useful to go a level deeper: deleting a file is a bookkeeping change, not an erasure, which is precisely why the leftover bytes are there for a defrag to overwrite. That article walks through what the file system changes, what stays behind, and where each drive type stores it.
What happens when you delete a file
Related reading
Not sure which situation you are in? Try guided help
Sources
Facts on this page are cited to the publishers’ own documentation.
- [1] Microsoft Learn — Optimize-Volume (Storage) | Microsoft Learn. captured 2026-09-13.
- [2] Microsoft Learn — Defragmenting Files - Win32 apps. captured 2026-09-13.
- [3] Microsoft Learn — cipher | Microsoft Learn. captured 2026-09-13.
- [4] Microsoft — fsutil behavior (Windows command reference). captured 2026-09-12.