Technology in terms you understand. Sign up for my weekly newsletter, "Confident Computing", for more solutions you can use to make your life easier. Click here.

Defragging in Windows 7 (and later)

Disk defragging, or more correctly “defragmenting,” is the source of many questions, more than a few misconceptions, and many articles here on Ask Leo!

The good news is that for reasons we’ll explore, defragging in Windows 7 is actually something you rarely need think about any more.

While we’re exploring, we’ll also look at a brief refresher on what fragmentation is, why defragmenting is needed, and how to do it yourself, if you want to. I’ll also address some of the most common myths of defragmenting.

Become a Patron of Ask Leo! and go ad-free!

Fragmentation

To summarize from a previous article What is ‘defragging’ and why should I do it?:

Imagine that you have a book, but that the pages are randomly scattered throughout your house. You have a list of where each page is, so when you want to read your book you go find page 1, then you look on the list for page 2 and go to that, then look up page 3, and so on. In order to read your book in order, you’re racing around the house like crazy because the pages are all over.

That’s a fragmented file – lots of “fragments” scattered all over the disk.

It takes time to do all that running around to read the book from beginning to end.

Degfragmenting is nothing more than the hard disk equivalent of collecting up all the pages and putting them next to each other, in order, for every book on your book shelf.

Things are much easier (i.e. quicker) to read when they’re gathered together in order.

Why you needn’t worry about defragging

Let’s fire up the disk defragmenting tool.

In Windows Explorer, right-click on the drive you want to defragment and click Properties:

Right Clicking a Drive for Properties

In the resulting dialog box, click the Tools tab, and then the Defragment now… button:

Defragment now button

(In Windows 8 the term “Optimize” is also being used instead of or in addition to, “Defragment”.) This will bring up the disk defragmenting tool:

Windows Defragmenting Tool

The first thing that you might notice is this:

Defragmenting Scheduled

By default, Windows will defrag all of the hard drives connected to your machine once a week. In fact, if you look in the “Microsoft” branch of the Windows Task Scheduler (in Start, All Programs, Administrative Tools), you’ll see that there’s a scheduled task for exactly that purpose:

Defrag in Task Scheduler

99% of the time, that’s plenty. Even if your machine is off at the scheduled time, Windows will run it as soon as possible thereafter – and only when the machine is idle so as not to interfere with whatever you might be doing.

Defragging manually

Let’s say that for some reason, you want to defrag a drive manually. Perhaps it’s become particularly fragmented and you don’t want to wait. Perhaps it’s a drive, such as a removable drive, that the scheduled defragmentation has missed for some reason.

In the disk defragmenter, simply click the disk that you want to defrag and click Defragment disk:

Defragment Disk

Analyze disk simply updates the “% fragmented” number that appears with each disk. Defragmenting actually begins by updating that number as well.

The time defragmentation takes depends on the size of the disk, the speed of the disk, and how badly fragmented it is. After a potentially long time and many passes,…

Defrag Progress

the disk is defragmented.

Defragging from the command line

As it turns out, the task that is scheduled to defrag your computer weekly does nothing more than run the command-line version of the defragmenting tool.

You can run that too, if you like.

You’ll need to run the Windows Command Prompt “as administrator” to get the privileges required to run the defragging tool. Click Start, All Programs, Accessories, and then right-click Command Prompt and click Run as administrator.

In the command prompt, type “defrag c:” (without the quotes) to defragment the C: drive:

Defrag in Windows Command Prompt

The command line defrag tool has several additional options, just type “defrag /?” to list them.

Another alternative: Defraggler

Piriform’s Defraggler is an alternative disk defragmenting tool that some people prefer for one or both of two reasons:

  • It’s more visually informative
  • It’s more aggressive than Windows built-in defragmenting tool

Defraggler displays a continuously updated map of the drive’s defragmentation status as it does its work, very similar to the old Windows XP defragmenting tool:

Defraggler, in progress

Those that are so inclined often feel that this gives them a much better sense of what’s happening, as well as more detailed results when the tool is finished.

When it comes to results, however, we need to talk a little about why no defragmentation programs can defragment completely.

Defragging is never perfect

After running a defragmenter on your hard drive, you will find that the drive remains fragmented. In fact, sometimes even running a different defragmentation tool may report a drive as defragmented even though the Windows tool reports it as not fragmented at all.

There are several reasons.

  1. Some files, like the system paging file and hibernation files, cannot be defragmented while Windows is running. The Windows tool apparently excludes them from the calculation.
  2. Defragmenting is a surprisingly complex process, and different tools use different algorithms to move file contents around on the disk. Some algorithms are more aggressive than others, at the cost of taking longer.
  3. Files are in use and being fragmented by other programs – including Windows itself – while the defragmentation process happens.
  4. Getting a perfectly defragmented disk – when defragged in place1 – may often take significantly more time than it’s actually worth. The thinking is that you’d never notice the performance improvement of defragging that last 3%, which might take significant additional time to achieve. Many defragging programs take this into account and simply defrag to the point of “good enough.”

The point is that “good enough” typically is exactly that – good enough. You really wouldn’t notice the performance increase if you spent the extra time defragmenting completely. (Although it can make sense to defrag the paging file – once – should it be significantly fragmented.)

If you really, really want to get near-perfect defragmentation, you can keep running the defgragging tool over and over. Each run should give you progressively better results, at least for the files that it’s able to defrag.

Debunking defragging myths

Like many things about Windows specifically and computers in general, the whole concept of defragmenting is somewhat mysterious and magical. As a result, there are many misconceptions.

“Defragging frees up disk space” – No, it does not. All defragging does is move files and file parts around on the hard disk. It doesn’t delete, remove, or repair anything. It is only a performance optimization.

“Defragging wears out the hard disk” – Magnetic hard drive: no. USB/Flash drive: yes. SSD: probably yes.

  • Traditional mechanical magnetic hard disks with spinning platters and moving arms work hard while defragging happens, but they’re built specifically to handle that and work hard at other times as well.
  • Defragging your USB thumb drive or other inexpensive flash memory based device will significantly shorten its life, due to the fact that flash memory wears out the more you write to it.
  • There may be anecdotal evidence that defragmenting an SSD – also a flash-based technology, albeit of much higher quality – may speed it up. I still strongly recommend not doing it. Ultimately, SSDs are still subject to the wear issues similar to other flash memory and the speed of an SSD shouldn’t depend on “where” the data is stored within it. I wouldn’t risk it.

“Fragmentation/defragmenting will cause my programs to crash” – No. All programs, including Windows itself, are blissfully unaware of fragmentation. Other than files reading or writing more quickly, program behavior is unaffected.

Footnotes & references

1: If you use a second disk you can achieve 100% defragmentation by copying all files to that other disk, formatting the original erasing it completely, and then copying the files back. Many backup programs restore functions will actually achieve similar results.

20 comments on “Defragging in Windows 7 (and later)”

  1. Since more and more systems are built using solid state drives (especially laptops), is Windows intelligent enough to exclude them from its scheduled defrag process? Or is this one of those items that we need to go in and disable?

    • Reid,
      One would hope that the manufacturer of the computer knows enough to turn it off. But to be safe, you are probably right, best to check and make sure it is disabled.

    • Excellent timing, as I just tested this. I swapped out a hard drive in a machine, replacing it with an SSD. The command used by the scheduled task – “defrag -c” – appears to skip SSDs. Where it used to defrag C: the hard disk, it no longer tries to defrag C: the SSD.

  2. Thank you, Leo, for the best definitions of fragmentation I have ever heard since the PDP-11 was king.. 🙂 I’m a middle school teacher, and this analogy will be perfect for the young and inexperienced to understand.

  3. Hello Leo,
    I remember in the past you stating it is not necessary to defrag the drive unless you notice the computer slowing down. Am I remembering your recommendation correctly?
    I have turned off automatic defragging. I am not a heavy computer user so there is not a lot of file writes and deletes. Every couple months I do a manual defrag of the C: drive. The analysis of the drive says defragmenting is not needed. I do it anyway, with very little difference in the displayed file display.

  4. Hi Leo. Great article. On the question of when why and how often to defrag, here is my experience in repairing customer computers. After cleaning out malware, viruses, unwanted programs, etc., if the computer is still slow I check the fragmentation with Defraggler. In most cases it will be 25-50%. I am sure part of this is related to cleaning I have just done, but the before and after difference is amazing. In these machines the full defrag with Defraggler can take 6-8 hours, but performance is significantly improved. Your thoughts on how often to otherwise defrag are right on it depends.
    Also, for my own machine that I work with all the time, previously running on Windows 7 but now upgraded to Windows 8, I find that lower levels of fragmentation can hinder performance, and running Defraggler produces a notable difference. My theory is that although the fragment level is low, the files that are fragmented are the ones that you use all the time, thus slowing performance. To use your analogy about books. It doesn’t matter if you have 100 books on the shelf. If the one you use all the time is scattered all over the house, you will lose a lot of time looking for the pages. What are your thoughts on this idea?
    Thanks for your great articles.

  5. i ran defrag of my C;| drive. after twice, it still has 17% fragmentation. What can I do? is it due to disk bad sector? if so how can i fix it?

  6. My system is set to defrag at 1PM on Wednesday. It does defrag the PQSERVICE and the SYSTEM RESERVED, but hasn’t done the ACER (C:) since JULY! So, I am currently one hour and 5 passes into defraging. 🙁

  7. My SYSTEM drive is 37% fragmented, and I suspect this may be why my laptop is running so poorly (or at least one reason). The Windows 7 defrag tool appears to run on this drive – it flashes very quickly and then remains at 37%. Assuming I can boot from a repair disc, how would I run a manual defrag on this drive? It has no assigned drive letter. Issue with repair disc – the laptop booted from it once, but on subsequent tries it bypasses it. BIOS boot order has been changed, verified, re-verified.

    Does the SYSTEM drive need to be defragmented? Could the fragmentation be the cause of extremely slow reactions to mouse clicks and keystrokes? How do I do it? And what’s up with the repair disc – why would it only work once?

    • Fragmentation is RARELY the cause of that kind of system slowdown. I would look elsewhere for speed problems, starting here: https://askleo.com/why_is_my_machine_slowing_down/

      As to why the disc wont’ boot again: I’d triple check the BIOS settings, or perhaps create a new repair disc.

      Finally, if you want to continue to persue the defrag option, get defraggler from piriform – it’s free, and it can show you exactly what files are fragmented.

  8. Re: the space thing:

    The indeces for all the fragments take up space, so a proper defragmentation is going to recover you some. The trick is that, these days, that’s usually a very small amount compared to the drive capacity. Nevertheless, insignificance is not nothing; It is not a myth.

    Some file system drivers will allocate by sectors, even when the file system can handle more fine control, which means that there can be significant waste to be recovered, as well. That’s mostly a problem of the past, unless you’re using FAT.

  9. Leo I sure would appreciate this answer about my defrag problem as I thoroughly search all the articles and as far as I can tell there is absolutely nothing that even remotely relates to my problem and believe me I tried! I am running windows 7 home version. I am able to defragment manually as I am well aware of how to do this. My problem is that when I try to set it for a schedule automatically it never works even after I went to task manager and set it up to run on automatic because before this time it indeed said manual so I thought this was the problem but apparently not. Further when I try to stop or start or pause I get this response: Windows could not pause the disk fragmenter service on local Computer
    The service did not return an error. This could be an internal Windows error or an internal service error.
    If the problem persists, contact your system administrator..(Which I presume is me!)

    Can you help me.

    • Since you have this problem it could be one of three things, 1) a bad hard drive 2) WINDOWS 7 VERSION YOU HAVE, MIGHT BE UNOFFICIAL or 3) could be malware related? Other than that you could have bad RAM modules. I would suggest adwcleaner and run as admin, it can be downloaded from toolslib. Then try deleting unnecssary programs/media/even pics and music, also games. Then try defrag again. If problem persists then try a memtest for your particular laptop or PC, good luck!!!

    • Hi again reading your article and as you cannot pause through task manager and defrag doesnt work automatically , could be hard drive, faulty RAM modules, or infected with malware but this is unlikely, my guess would be between the hard drive and RAM modules, how much space is in hard drive ? If its pretty full you might need to delete some stuff, remove programs that you dont use and then using cmd prompt admin type chkdsk wait til it finishes and then type sfc/scannow and if there are any problems it will be displayed? Hope this helps being very long winded, sorry!!!

  10. I did want to note that when attempting to pause or stop or start from the task manager I am not able to initiate the procedure although the other tasks lets me do it for some reason. When I double click on the defrag task, as you know, it takes me to another box where I can initiate the start and stop but not the pause function. Any thoughts about this? But my main concern would be the aforementioned question.

  11. Leo,
    I decided to do a back to back defraggler run.
    To see what would happen.
    To my surprise. It acts like I did not defrag my computer.
    What gives?

Leave a reply:

Before commenting please:

  • Read the article.
  • Comment on the article.
  • No personal information.
  • No spam.

Comments violating those rules will be removed. Comments that don't add value will be removed, including off-topic or content-free comments, or comments that look even a little bit like spam. All comments containing links and certain keywords will be moderated before publication.

I want comments to be valuable for everyone, including those who come later and take the time to read.