Ask Leo!

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

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:

More articles about: Video Tips
More articles about: Windows Performance

Article Useful? Link to it from your own website; just copy/paste this HTML:

Article 383 | Posted July 16, 2004

Recent Comments

Leo, I set my computer to defrag the other night, and it got hung up on a video file at 26%. So, I deleted the video, and it got stuck again at 13% on a different video file. A third attempt and it got stuck at 6% after 8 hours of running on yet a different video file. What do you think I should do, besides not storing too many movies on my hard drive? Thanks.

Posted by: Jordan at October 16, 2007 02:39 PM

Hi Leo,
I find this article quite informative, I never knew that there is such an option available and I am the computer guy at my house. Anyway, I wanted to ask about the task scheduler, so let's say I did everything like you said; would the computer simply turn itself on and perform the defrag?

Posted by: Kevin Chan at January 19, 2008 07:49 PM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

No, you must leave your computer turned on for scheduled
tasks to run.

Leo


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)

iD8DBQFHlpmgCMEe9B/8oqERAheYAJ9wqFG8P+fBjt7Afvkgug+ew0rnzgCeJvbi
ftSIh/gGlmGHky2YnZ0X2pM=
=Xkxo
-----END PGP SIGNATURE-----

Posted by: Leo A. Notenboom at January 22, 2008 05:34 PM

Wow, this is really informative. I don't think I would have gotten a simpler explanation anywhere else. Now I think I will go and do some defragging. Thanks.

Posted by: Ness at February 28, 2008 12:14 PM

My wife ran defragment and now many of the programs are not working properly. My I-tunes keeps searching for the file to open and never opens. Please help.

Thanks

John

Posted by: John Barron at March 8, 2008 11:38 AM

Do your comments about defragging also apply to the program "registry optimizer"?

Thanks
Troy

Posted by: troy at April 18, 2008 07:22 PM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

No. This article applies to registry cleaners and
optimizers:
http://ask-leo.com/whats_the_best_registry_cleaner.html

Leo


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)

iD8DBQFICjE7CMEe9B/8oqERAgf9AJ9dtsykcIPRbdWZvhphU23Y23WD/ACcCjrg
fNhxQ43HMZcXF4+BCmy9tnc=
=lmni
-----END PGP SIGNATURE-----

Posted by: Leo A. Notenboom at April 19, 2008 10:52 AM

what an analagy about book being a harddrive

Posted by: Anonomys at May 21, 2008 07:39 AM

Thanks alot Leo. I seen my optimizer say that it was reccomended for a defragmentation and i wanted to know what i was doing first. Thankyou!

Posted by: Brad at July 13, 2008 06:24 PM

hi.. do we need to power on our pc if we schedule to defrag at night or early in the morning even if we're away from our pc's? thanks..

Nothing will happen unless the PC is turned on.

-Leo

Posted by: anonymous at July 23, 2008 04:24 AM

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)

New!

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

Before commenting, please...

Please wait. Your comment is being processed ...


Ask Your Question:


ask-leo.com
Web

Archives

By Category
By Date

Advertisers

Advertise on Ask Leo!

««   »»

Question? - Ask Leo!
Who is Leo?
Link to Leo!

Terms, Conditions & Privacy