How to Defragment and Optimize Drives

Download now

Windows includes both a graphical tool (dfrgui) and a command-line tool (defrag) for optimizing HDDs and issuing TRIM to SSDs.

Updated August 9, 2026 · PC Utility Hub Editorial Team

Using the graphical tool (dfrgui)

  1. 1Press Start, type "defrag", and open "Defragment and Optimize Drives".
  2. 2Select the drive you want to check.
  3. 3Click "Analyze" to see the current fragmentation percentage (HDDs only).
  4. 4Click "Optimize" to run defragmentation on an HDD or TRIM on an SSD.
  5. 5Optionally click "Change settings" to adjust or disable the automatic schedule.

Using the defrag command line

The defrag.exe command gives more control and can be scripted or scheduled.

defrag C: /A
defrag C: /O
defrag C: /L
defrag C: /V
SwitchMeaning
/AAnalyze only, report fragmentation
/OOptimize based on drive type (defrag HDD or TRIM SSD)
/LRetrim on an SSD (issue TRIM to reclaim unused blocks)
/VVerbose output
/UShow progress during operation

SSD TRIM and retrim explained

TRIM tells an SSD controller which storage blocks no longer hold valid data so the drive can erase and reuse them efficiently ahead of new writes, which helps maintain write speed over time. Windows issues TRIM continuously as files are deleted, and the scheduled "optimize" task performs a periodic retrim pass (`defrag /L`) as a backstop, rather than a full rewrite of data.

Checking or changing the automatic schedule

  1. 1Open Defragment and Optimize Drives.
  2. 2Click "Change settings".
  3. 3Confirm "Run on a schedule" is checked (weekly is the default).
  4. 4Choose which drives are included by clicking "Choose".

Leave the default schedule enabled unless you have a specific reason to manage it manually; Windows already treats HDDs and SSDs differently.

When to skip optimization

  • Don't manually defragment SSDs or NVMe drives beyond the scheduled TRIM pass.
  • Skip defragmenting drives with SMART errors — check disk health first.
  • Avoid running defrag on a nearly full drive; free some space first for best results.

Frequently asked questions

How do I know if my drive is an SSD or HDD in this tool?
The Media type column in Defragment and Optimize Drives lists each drive as "Solid state drive" or "Hard disk drive".
What does defrag /L do?
It issues a retrim to an SSD, telling the controller which blocks are free, without performing traditional defragmentation.
Can I disable scheduled optimization?
Yes, uncheck "Run on a schedule" in Change settings, though leaving it enabled is recommended for both HDDs and SSDs.