How To Use The Defrag Command In Windows (2026)
The defrag command analyzes and optimizes a drive from the command line, with more options than the Optimize Drives window offers.
The basic forms are defrag C: /a to analyze a drive and defrag C: /u /v to run it with progress and detail.
This guide follows Microsoft’s defrag reference, which lists Windows 11 and Windows 10 as supported.
Table of Contents
- Defrag quick answers
- What the defrag command does
- Open Command Prompt as administrator
- The defrag syntax
- Defrag switches at a glance
- Analyze a drive first
- Defragment a drive
- Microsoft examples
- Free space needed
- Volumes defrag cannot work on
- Save the report to a file
- What happens on SSDs
- The scheduled task
- Why the Last run time can look old
- Command or Optimize Drives window
- Defrag and Disk Defragmenter conflict
- Common defrag mistakes
- Check and optimize a drive step by step
- Official sources
- More Windows guides
Defrag quick answers
| I want to | Type this |
|---|---|
| Analyze drive C without changing anything | defrag C: /a |
| Defragment drive C and watch progress | defrag C: /u /v |
| Optimize each drive for its media type | defrag C: /o |
| Retrim a drive | defrag C: /l |
| Run on drives C and D in parallel | defrag C: D: /m |
| Run on every volume | defrag /c /h /v |
| Show help | defrag /? |
Run these in an administrator window, because Microsoft requires membership in the local Administrators group.
What the defrag command does
Microsoft says defrag locates and consolidates fragmented files on local volumes to improve performance.
Running it by hand is the same job the scheduled maintenance task does, and the graphical route is covered in how to defragment and optimize drives in Windows 11.
Open Command Prompt as administrator
- Press the Windows key and type cmd.
- Right-click Command Prompt and choose Run as administrator.
- Type your defrag command and press Enter.
Microsoft lists administrator membership as the minimum requirement, and suggests Run As as a security best practice.
The defrag syntax
Microsoft gives the first form as defrag <volumes> | /c | /e <volumes> [/h] [/m [n] | [/u] [v]].
Adding /a makes the same form an analysis, and adding /x makes it a free space consolidation.
The fourth form, defrag <volume> [<parameters>], is the one most people type for a single drive.
Defrag switches at a glance
| Switch | What it does |
|---|---|
<volume> | The drive letter or mount point path to work on. |
/a | Analyzes the volumes. |
/b | Performs boot optimization to improve boot performance. |
/c | Works on all volumes. |
/d | Performs traditional defrag, which is the default. |
/e | Works on all volumes except the ones you list. |
/h | Runs at normal priority, where the default is low. |
/l | Performs retrim. |
/m [n] | Runs on each volume in parallel in the background. |
/o | Performs the proper optimization for each media type. |
/t | Tracks an operation already running on the volume. |
/u | Prints progress on screen. |
/v | Prints verbose output with fragmentation statistics. |
/x | Consolidates free space. |
Microsoft also lists /g, /i and /k for storage tiers and slab consolidation, which matter mainly on server storage.
Analyze a drive first
- Open an elevated Command Prompt.
- Run
defrag C: /awith your own drive letter. - Read the analysis report that appears when the cursor stops blinking.
Microsoft says defrag shows a blinking cursor while it works and then prints the analysis report, the defragmentation report or both.
Defragment a drive
Microsoft’s first example is defrag c: /u /v, which defragments drive C with progress and verbose output.
If you give neither /a nor /v, Microsoft says defrag shows a summary of both reports.
To interrupt the process, press CTRL+C at the command line.
Microsoft examples
| Task | Command |
|---|---|
| Defragment drive C with progress and detail | defrag c: /u /v |
| Defragment C and D in parallel in the background | defrag c: d: /m |
| Analyze a mount point and show progress | defrag c: mountpoint /a /u |
| Defragment all volumes at normal priority | defrag /c /h /v |
Free space needed
Microsoft says a volume needs at least 15% free space for defrag to completely and adequately defragment it.
Defrag uses that space as a sorting area for file fragments.
With less free space it only partially defragments, so delete unneeded files or move them first, as in how to free up disk space on Windows 11.
Volumes defrag cannot work on
- Volumes locked by the file system.
- Volumes the file system marked as dirty, which need chkdsk first.
- Network drives and CD-ROMs.
- Volumes that are not NTFS, ReFS, FAT or FAT32.
Microsoft says you can check whether a volume is dirty with the fsutil dirty command, and checking and repairing drive errors covers chkdsk.
Save the report to a file
Add a redirect to send the report to a text file, as in Microsoft’s defrag volume /v > FileName.txt.
What happens on SSDs
Microsoft says that when the scheduled task runs, traditional defragmentation and retrim on an SSD happen once per month.
If you manually run traditional defragmentation on an SSD between scheduled runs, the next scheduled run does analysis and retrim and skips the defragmentation.
That is why the /o switch, which picks the proper optimization for each media type, is the simplest choice when you are unsure what kind of drive you have.
The scheduled task
Microsoft says defrag runs as a scheduled maintenance task that typically runs every week, and an administrator can change how often in the Optimize Drives app.
The task may skip volumes when the computer is on battery, would need to be woken, or is resumed from idle.
Why the Last run time can look old
Microsoft explains that if analysis is skipped on a scheduled run, the Optimize Drives app does not show an updated Last run time.
As a result, the Last run time can be up to a month old even though the task is running.
Changing how often the task runs does not change the once-per-month cadence for SSDs.
Command or Optimize Drives window
| Need | Better choice |
|---|---|
| Quick look at one drive | Optimize Drives window |
| Analyze or optimize in a script or remote session | defrag C: /a |
| Boot optimization | defrag C: /b |
| Retrim only | defrag C: /l |
| A saved report | defrag C: /v > report.txt |
Defrag and Disk Defragmenter conflict
Microsoft says running defrag and Disk Defragmenter at the same time is mutually exclusive.
If the graphical tool is working on a volume, the defrag command fails.
Common defrag mistakes
- Running it without an elevated window.
- Trying to defragment a network drive.
- Running it on a nearly full drive and expecting a complete result.
- Running it while Optimize Drives is already working on the same volume.
Check and optimize a drive step by step
- Open an elevated Command Prompt.
- Run
defrag C: /ato analyze the drive. - Run
defrag C: /oto optimize it with progress shown. - Read the report when the command finishes.
If the PC is still slow afterward, how to speed up a slow Windows 11 PC covers the next steps.
Official sources
The syntax, switches, requirements and examples come from Microsoft’s defrag reference.
More Windows guides
- How To Uninstall ESET From Windows Step By Step (2026)
- How To Uninstall Kaspersky Completely From Windows (2026)
- Local Security Authority Protection Is Off In Windows 11 (2026)
- How To Use Ping And Tracert In Windows 11 (2026)
- How To Change UAC Settings In Windows 11 (2026)
- How To Rip A CD To Your PC In Windows 11 (2026)
See all: Windows 11 Guides