Ask Leo! by Leo A. Notenboom

What is 'defragging', and why should I do it?

Search First! Then browse: Categories | Full Archive | By Date | Newsletter

Home » Video Tips
Home » Windows » Windows Performance

Summary: Defragging is short for defragmenting which rearranges the layout of files on your hard disk for faster access.

What is 'defragging', and why should I do it?

"Defragging" is short for "defragmenting", and it's a process you run on a hard drive to help make it faster. It's something you need to do periodically as files on the disk becomes fragmented over time - hence the term "defragmenting".

So what does it mean to be fragmented, and why does it get worse over time?

Let's look at that, as well as how to defragment and how to defragment automatically.

To you and me, a file on your disk is a single 'thing'. You open it, you work on it, you save it; it's a single entity. Like, say, a book. To your computer, however, a file is a lot more like a bunch of pages in that book that it has to keep track of individually.

Let's briefly define a couple of concepts before we go further. Under Windows a hard disk is nothing more than a collection of information buckets called "clusters". Each cluster is a fixed size, typically 512 bytes or characters. When you create a file on disk, Windows assigns enough clusters to the file to hold it. So if your file is one byte long, it gets one 512 byte cluster. If your file is 600 bytes, it gets two - one 512 bytes full, and one with 88 bytes of data, and 424 bytes unused.

Clusters aren't required to be next to each other on the disk. In fact, that's part of what the "Random" in "Random Access Storage" means; data can be accessed and stored on the disk in random places. So when Windows creates a file, it keeps track of which clusters make up the file, wherever on the disk they might be, and in which order they should go. Kind of like numbering the pages in a book.

Now, imagine if you had the pages of a book randomly distributed around your house. You know where they are and in what order to read them, but you have to run all over the house as you get each successive page.

That's a fragmented file. The clusters that make up the file are scattered throughout the disk. The result is that when you access the file, Windows has to race all over the hard disk to retrieve the whole thing. That takes time.

If instead the pages of your book were all next to each other, in order, then they'd be much easier to read. No need to run all over. That's a defragmented file: all the clusters allocated to the file are in order and physically next to each other on the hard disk.

Files become fragmented because of the way clusters are re-used and allocated on a hard disk. If you delete a file that takes up two clusters, and then write a file that takes four then the new file might be split - two clusters where the old file was, and two clusters somewhere else entirely. Multiply that scenario by thousands of file operations and deletions on your disk every day, with much larger files, and you can see that fragmentation can add up very quickly. The result is your machine gradually slowing down.

Defragging your hard disk is easy. Right click on My Computer, select Manage, and click on Disk Defragmenter. Click on the hard disk you want to defrag, and click on the Defragment button. Defragging can take time, but you'll be able to see the progress as the graphical display of your hard disks state is periodically updated.

Rather than doing it manually, though, if you leave your computer on there's an easy way to schedule the defrag to happen in the middle of the night.

Fire up notepad, and enter the following:

defrag c: >c:\defrag.log 2>&1

Now save that as "c:\defragit.cmd".

Now, in Control Panel, Performance and maintenance, Scheduled tasks, create a new scheduled item. It should run c:\defragit.cmd, and I'd suggest doing it every night when you're not using your machine. Check the log every once in a while to make sure that the process is happening as you expect.

You can run defragit.cmd at any time yourself, if you like. Just open up a command prompt and type c:\defragit.cmd.

Video

Here's a video I put together that walks through some of the steps above:

Related Links:

Article C2123 - July 16, 2004

Was this article helpful? «Yes» «No»

Helpful? Get new articles weekly by email in my FREE newsletter!

Your Name:
Your Email:


Why Subscribe?

Recent Comments
58 Comments

I have Windows ME. (There is no "manage" box when right clicking on "My Computer".) How do I perform this operation?

Posted by: iamawriter at December 29, 2008 12:29 PM

when using defrag it brings your computer back up to the speed it was when new not faster

Posted by: Terry at April 2, 2009 7:57 AM

Couple of points of clarification.
Defrag CAN free up some space in 2 ways. But you shouldn't count it happening, or expect much space to be freed up.
First, depending on how the fragmentation happened, each fragment could have "freespace" intended by the file system for growth. So when the file is defragged the only freespace left is at the end of the file.

The other way defrag can free up space is if there are many small unsed spots on the drive, the file system may not use them until they are "joined" together into a larger block of freespace.

On the question of locked files, the more "advanced" (than the stripped down defrag tool bundled with Win) defrag tools that can handle locked files. They perform defrag in several discrete steps. One of the later steps is to do a reboot and run a defrag BEFORE the OS and/or "startup" apps are loaded.

As well, when HD free space is less than 20% Windows can get twitchy. Strange, unexpected, things can happen such as defrag programs abending unexpectedly. It's not as common a problem these days as it was when HD size was measured in MB not GB.

I'm afraid you're incorrect. Defrag does not free up space. The examples you quote are not how things work. Moving free space around does not create more free space.
- Leo
17-Jun-2009
Posted by: Rohn at June 16, 2009 8:33 PM

I defragmented my drive and it improved the speed a lot. I used the trial version of Diskeeper09 which a friend suggested. Its really easy to use as its automatic.

Posted by: ruman at June 19, 2009 2:35 AM

I have Vista and the when attempting to save as c:\defragit.cmd, a box pops up stating "you do not have permission to save in this location. Contact the administrator to obtain permission."
What does this mean and how do i obtain permission?

Posted by: Dee at July 5, 2009 2:09 AM

\\john system is not accessible you might not have permission to use this
network resourece.contact the administrator of this server to find out if
you have access permissions.the server service is not started..

this errore coming my network pc... what solution
..reply me...

Posted by: damnic at July 9, 2009 1:09 AM

defragment works but sometimes, it also creates problem especially with videos. wats the problem

Posted by: Mahesh at July 14, 2009 12:10 PM

I would seriously recommend the "Piriform Defraggler" for this, free to download and a really good programme, they also have a Ccleaner which cleans out spyware and generally makes your computer run faster, just google piriform if your interested, really good stuff!

Posted by: cameron at August 31, 2009 2:49 PM

Hi Leo, you're so wonderful. Thank you. After I defrag and when I view the undefragged files, it just says they're in my documents but doesn't tell me which ones. How do I find them?

Posted by: Nancy Gardner at October 29, 2009 7:42 PM

Also, maybe you can answer both of these at the same time. I have another computer that will defrag, but there's a great deal of free space in between the compressed files. Why?

Posted by: Nancy Gardner at October 29, 2009 7:44 PM

Post a comment on "What is 'defragging', and why should I do it?":






(Email Address will not be published.)

Remember Me?

By popular demand...
my tip jar
Cuppa Joe
Buy Leo a Latte!

(you may use HTML tags for style)

RSS feed Subscribe to the RSS Feed specifically for comments on this article.

Before commenting, please...

  • Read the article at the top of this page. If your comment shows you didn't, it'll be deleted and ignored.

  • Comment only on this article. Use the Google search box at the top of the page if you have a question about something else.

  • Don't include personal information in the comment. No email addresses. No phone numbers. No physical addresses.

  • Don't spam. Excessive links to unrelated sites within a comment or across multiple comments will cause all such comments to be removed.

  • Don't ask me to recover lost passwords or hacked accounts. I can't, and those comments will be deleted.

  • I can't respond to every comment. And I can't vouch for the accuracy of others who do.

Please wait. Your comment is being processed ...


Question? Ask Leo!