How to defragment or trim your drive on Windows 11


The longer you use your computer, the more likely it is to become slower over time, especially as you pile up more files on your drives. Filling up your hard drive can significantly downgrade performance, and one good way to help address that problem is to optimize or defragment that drive. In this article, we’ll show you how to defragment a drive on your Windows 11 PC.

What is defragmenting?

Defragmenting means that Windows will search for files split across different parts of the physical drive and put the bits in the same area, making it easier for the computer to read them sequentially. This can make a big difference on a hard disk drive (HDD) as the spinning platters take longer to locate the different parts of a file if they’re scattered throughout the drive.

However, you probably won’t see many mentions of defragmenting these days. That’s because most PCs today come with a solid-state drive (SSD) or eMMC storage, which works very differently in how files are accessed. Accessing different parts of the drive doesn’t take any longer now, and defragmenting can actually be detrimental to the lifespan of an SSD since it uses up more write cycles, which are limited on this kind of drive. This used to be a bigger problem with earlier SSDs that had particularly short lifespans, but even today, there’s no benefit to defragmenting an SSD.

Instead, Windows 11 optimizes SSD drives by doing something called trimming. This marks unused parts of the drive as being ready for use, making it faster to write new data to that segment when needed.

How to defragment and optimize your drive

The easiest way to defragment or optimize your drive is to use the built-in disk optimization tool in Windows 11. This tool automatically defragments or optimizes your drive depending on whether you have an SSD or HDD. It’s the best way to do it since it avoids wearing out an SSD with defragmentation.

  1. Open the Start menu and type Defragment. The first result should be Defragment and Optimize Drives. Select it.
    Screenshot of Windows 11 Search results for defragment
  2. Select the drive you want to optimize or defragment.
  3. Click Analyze to check if the drive needs optimizing or defragmenting.
    Screenshot of the Windows 11 disk optimization tool with the Analyze button highlighted
  4. If it does, click Optimize.
    Screenshot of the Windows 11 disk optimization tool with the Optimize button highlighted
  5. The process may take a while. If you’re defragmenting an external drive, make sure it stays plugged in until the process is done.

How to schedule drive optimization

That’s all you need to do to defragment your drive once. However, you can also schedule the optimization to run regularly. The default sets a weekly defragmentation schedule for internal drives on your PC. If you want to change that, follow these steps.

  1. Open the Defragment and Optimize Drives window again.
  2. Click Change Settings under Schedule optimization.
    Screenshot of the Windows 11 disk optimization tool with the Change settings button highlighting
  3. Enable the Run on a schedule (recommended) checkbox if it isn’t already.
    Screenshot of automatic disk optimization settings in Windows 11
  4. You can change the frequency of the optimization to Daily, Weekly, or Monthly.
    Screenshot of the automatic drive optimization settings in Windows 11 with the frequency options expanded
  5. Click Choose to select the drives you want to be part of the scheduled optimization.
  6. You can choose the drives you’d like to optimize and whether you want new drives to be optimized automatically.
    Screenshot of choosing drives to be included as part of the automatic disk optimization in Windows 11
  7. Click OK and then OK again to save your settings.

And that’s about all you need to do to defragment your drive on a schedule. This is definitely the easiest way to go about it, but there are other methods.

Defragment your drive using Command Prompt

If you’d rather use the Command Prompt to run your disk defragmentation, you can do it that way, too. However, note that this method will still defragment your drive if it’s an SSD, which you don’t want.

The steps below should only be followed if you have an HDD.

  1. Search for cmd in the Start menu and select Run as administrator under Command Prompt.
    Screenshot of Windows 11 search results for CMD
  2. Type Defrag [Drive letter], replacing [Drive Letter] with the letter assigned to the drive you want to defragment. For your OS drive, it should be C:, so the command would be Defrag C:
    Screenshot of Command Prompt in Windows 11 running the Defrag command
  3. Wait for the process to finish, which may take a while.

If you’d like to optimize an SSD by trimming it, you have to use a specific command. Open Command Prompt as explained above, and then enter the command Defrag [Drive letter] /L. The /L argument specifies that you want to retrim the drive, which makes more sense for an SSD.

Screenshot of Command Prompt running the Retrim command in Windows 11

There are a lot of additional arguments you can use for the Defrag command for different kinds of optimizations and tasks. Adding the /A argument lets you analyze a drive to see if it needs optimization, while the /B argument lets you optimize the boot performance, for example.

That’s about all you need to know to defragment your drive on Windows 11. This can help improve the performance of your amazing PC, especially if you’ve been using it for a long time. However, Windows 11 already optimizes your drives by default, so you shouldn’t need to follow these steps too often.

If you’d like to learn more about other ways to save space or improve performance on your PC, you can also check out how to clear cache and temporary files on your PC. You can also read about how to clear the DNS cache of your PC, which can help with some internet connection issues.