If your computer has a traditional hard drive, defragmenting it every month or two can keep it running smoothly; if it has an SSD, you should not defrag it at all. This guide explains the difference, shows you how to defrag on Windows 11, 10, 8 and 7, and covers what to do on a Mac or Ubuntu, where the answer is usually “nothing”.
What is defrag, and what does it do?
Defragmentation (defrag) is the process of rearranging the files on a hard drive so that each file sits in one continuous block instead of being scattered in pieces.
When you save, edit and delete files over months and years, your computer stores new data in whatever gaps are free. A large file can end up split into dozens of fragments in different places on the disk. A traditional hard disk drive (HDD) reads data with a physical head that moves across spinning platters, so every extra jump to collect a fragment costs time.
A defrag tool fixes this by:
- Moving the pieces of each file next to each other.
- Grouping free space together so new files are less likely to fragment.
- Making the drive’s head travel less, so files open faster and the computer boots and loads programs more quickly.
The benefit is real but modest on a healthy drive. It is most noticeable on an older HDD that has been heavily used and is nearly full.
Is defrag still a thing? Do you still need to defrag hard drives?
Yes, but far less than in the Windows XP era, and mostly because Windows now does it for you. Modern versions of Windows run a scheduled optimisation task in the background, so most people never need to start it by hand.
You still need to pay attention to defrag if:
- You have a mechanical hard drive (HDD), especially a large, older or nearly full one.
- You use an external USB hard drive for storage, and it is slow to open folders.
- Scheduled maintenance has been switched off, or your computer is rarely on when the task is due (a laptop that sleeps overnight is a common case).
You can skip defrag if your computer only has an SSD, or if you run a Mac, where the file system manages fragmentation itself (see the Mac OS section below).
Not sure which kind of drive you have? On Windows, open Defragment and Optimize Drives. The Media type column says either Hard disk drive or Solid state drive.
Does an SSD still need defrag?
No. A solid state drive has no moving parts, so scattered files cost it almost nothing, and a traditional defrag only adds unnecessary writes that use up part of the drive’s limited write life.
What an SSD does benefit from is TRIM (Windows calls the scheduled version “retrim”). TRIM tells the SSD which blocks no longer hold useful data so it can clear them in advance and keep write speeds up. Microsoft’s own tool handles this automatically: when you click Optimize on an SSD in Windows 10 or 11, it sends a retrim rather than a full defrag.
One detail that surprises people: Windows may still run a light file consolidation on an SSD about once a month if System Restore or volume snapshots are enabled. That is by design, and it is separate from the old-style defrag you should avoid running yourself.
| Drive type | What Windows runs | What you should do |
|---|---|---|
| Hard disk drive (HDD) | Analyse, then defrag | Let the weekly schedule run, or optimise manually |
| SSD | Retrim (plus occasional light consolidation) | Leave the default schedule on; do not use third-party defraggers |
| USB flash drive | Usually nothing | Do not defrag |
| External USB hard drive | Defrag, when you run Optimize on it | Optimise manually now and then |
Disk Cleanup or defrag first?
Run Disk Cleanup first, then defrag. Cleaning out temporary files, old update files and the Recycle Bin means there is less data to move and more free space to move it into, so the defrag finishes faster and does a better job.
The best order on an HDD:
- Empty the Recycle Bin and uninstall programs you no longer use.
- Run Disk Cleanup (type “Disk Cleanup” into the search box, pick the drive, tick the file types to remove, and select OK). On Windows 10 and 11 you can also use Settings > System > Storage > Temporary files.
- Back up anything important.
- Run Defragment and Optimize Drives on the hard drive.
On an SSD, still do step 2, but skip the defrag: the optimise step only sends a quick retrim.
How to defrag on Windows 11
Windows 11 uses the Optimize Drives tool, which defrags a hard drive and retrims an SSD automatically.
- Select the search box on the taskbar and type defrag.
- Open Defragment and Optimize Drives from the results.
- Select the drive you want to work on.
- If it is a hard disk drive, select Analyze to see how fragmented it is, then Optimize to run the defrag.
- Wait for the status to reach 0% fragmented, then close the window.
By default, Windows optimises your drives once a week. To change this, select Change settings in the same window, then choose how often it runs and which drives it covers.
Command line option. For a specific drive, open Windows Terminal as administrator and run defrag C: /O. To optimise every drive, run defrag /C /O. The /O switch tells Windows to use the right method for each drive type, which is a defrag for an HDD and a retrim for an SSD. Avoid running a bare defrag C: out of habit on an SSD, because it runs the traditional defrag.
How to defrag on Windows 10
The steps on Windows 10 match Windows 11, because both use the same Optimize Drives tool.
- Select the search box on the taskbar and type defrag.
- Choose Defragment and Optimize Drives.
- Select the drive, then select Analyze if it is a hard drive.
- Select Optimize to start the defrag.
- To change how often it runs, select Change settings, tick Run on a schedule, and pick Daily, Weekly or Monthly.
Keep in mind that Windows 10 reached the end of regular support in October 2025. If you are still running it, keep installing available updates and plan your move to a supported version of Windows, as a computer without security updates is a bigger risk than a fragmented drive.
How to defrag on Windows 8 and 8.1
Windows 8 renamed the old Disk Defragmenter to Optimize Drives.
- Press the Windows key + W to open the Settings search, then type defrag.
- Select Defragment and optimize your drives.
- Choose the drive and select Analyze, then Optimize.
- To change the schedule, select Change settings, make sure Run on a schedule is ticked, and pick a frequency.
Windows 8 runs this task automatically in the background, so a manual run is only needed if the drive feels slow or you have turned scheduling off. Windows 8 and 8.1 no longer receive security updates from Microsoft, so we recommend moving to a supported version of Windows.
How to defrag on Windows 7
Windows 7 calls the tool Disk Defragmenter.
- Click Start and type disk defragmenter into the search box.
- Open Disk Defragmenter from the results.
- Select the drive and click Analyze disk to see its fragmentation percentage.
- Click Defragment disk. You can select more than one drive and run them together.
- Click Configure schedule to change when it runs.
By default, Windows 7 defrags on a schedule, at 1:00 AM every Wednesday. If your PC is off at that time, the task runs the next time the computer is idle. Windows 7 normally switches off automatic defrag for an SSD, but it is worth opening Configure schedule to confirm. Windows 7 stopped receiving security updates in January 2020, so it should not be used for online banking or anything sensitive.
How to defrag a Mac (macOS)
You don’t need to, and macOS has no built-in defrag button. Apple’s file systems, HFS+ and the newer APFS, are designed to avoid fragmentation and tidy up small files in the background. Every modern Mac ships with an SSD, which should never be defragged anyway.
The only Macs where fragmentation could plausibly matter are older models with a mechanical hard drive that is nearly full. Even then, third-party defrag tools for the Mac are mostly discontinued or do not support APFS, and we do not recommend them.
If your Mac feels slow, try these instead:
- Free up space. Aim to keep at least 10% to 15% of the drive empty, because macOS’s automatic housekeeping works best when there is room.
- Open Activity Monitor and look for apps using a lot of CPU or memory.
- Restart the Mac, then install any pending macOS updates.
- On an older Mac with a hard drive, upgrading to an SSD is the single biggest speed boost available.
How to defrag Ubuntu (Linux)
Most Ubuntu users never need to defrag. Ubuntu uses the ext4 file system by default, which spreads files out sensibly when it writes them, so fragmentation stays low unless the drive is almost full.
If you want to check, ext4 has an online tool called e4defrag, which is part of the standard e2fsprogs package. Open a terminal and follow these steps:
- Check the fragmentation score of your home folder:
sudo e4defrag -c /home - Read the result. A low score means the files are already in good shape and you can stop here.
- If the score is high, defragment the folder:
sudo e4defrag /home - Run the check again to confirm the score has dropped.
e4defrag is safe to run while files are in use, but it can slow your computer while it works, and it may not help if the drive has very little free space. It only works on ext4, not on other file systems such as Btrfs or XFS.
If your Ubuntu machine has an SSD, skip e4defrag completely. Ubuntu already runs a weekly TRIM job in the background. To run it by hand, use sudo fstrim -av.
How long does it take to defrag a computer?
A hard drive defrag can take anywhere from about 10 minutes to several hours, depending mainly on the drive’s size, how full it is and how fragmented it has become. An SSD optimisation takes seconds to a few minutes, because Windows only sends a retrim.
| Drive | Typical time (rough guide) |
|---|---|
| SSD (retrim only) | A few seconds to a few minutes |
| Regularly maintained HDD | 10 to 30 minutes |
| 250 GB HDD, moderately fragmented | 1 to 3 hours |
| 500 GB HDD, moderately fragmented | 2 to 5 hours |
| 1 TB or larger HDD, heavily fragmented | 8 hours or more |
| External USB hard drive | 1 to 8 hours or more |
These figures are estimates, not guarantees. A drive that has not been optimised for years, a nearly full drive, a slow 5400 RPM disk and a busy computer all make it take longer.
To get through it faster:
- Run Disk Cleanup first and free up space.
- Close other programs and pause cloud sync and backup jobs.
- On a laptop, plug in the charger and run it overnight.
- Do not panic if it seems stuck. As long as the percentage creeps forward now and then and the drive is active, it is working. If there is no progress for many hours, or you can hear the drive clicking, back up your files and have the drive checked.
When a slow computer isn’t a fragmentation problem
If you defragged an HDD or ran Optimize on an SSD and your computer is still slow, fragmentation was probably never the cause. Common culprits are:
- Too many programs starting with Windows (check Task Manager > Startup apps).
- Low memory (RAM) or a drive that is almost full.
- Malware or unwanted software running in the background.
- A hard drive that is failing. Clicking or grinding noises, freezing and files that will not open are warning signs.
- An ageing computer that would run much faster with an SSD upgrade.
The most useful upgrade for a slow HDD computer is usually to replace the hard drive with an SSD. It cuts boot times from minutes to seconds and removes the need to defrag altogether.
