What is defragmenting a hard drive?

There is a recommended procedure on personal computers called “defragmenting.” What follows is a layman’s description of how a hard drive works and why defragmenting is important.

Think of your hard drive as a library. No, not a “Windows 7” library, but a real physical library with books and shelves and a card catalog. When you buy a brand new computer, the library is not empty. There’s a section of the library that’s filled with files (think of them as “books” for the time being) that instruct the computer how to do, well, everything it does. Only the computer and accounts with “administrator” privileges can access this area of the library, so you should set up separate “administrator” and “user” accounts. That way, you can log in as a “user” and not accidentally stray into the restricted area and make a change that disables your computer.

The rest of the shelves are empty. As you use your computer to do whatever you do, you will begin to fill these shelves with “books” (some of them pictures, music, or videos, in addition to documents). The thing is, once you put a book on the shelf, it almost never goes away. Just moving the book on the shelf, even an inch, is relatively difficult once it’s there. If you check a book out of the library and start to read it, you’re really reading a copy. If you look up from your reading back at the shelf, you’ll see the book still there, even though you’re holding it in your hands reading it. Depending on the book and how you open it (with what program), any changes you make may not completely eliminate the original version. They’ll just be added to an appendix or revision history at the end of the book that stays on the shelf, and they’ll appear in context only in the copy you check out and open.

When you “delete” a book, it doesn’t really go away, either. Remember how you find books in a library? You use the card catalog (or the electronic version of it, these days). When you drag a file on your computer to the “Recycle” bin, what’s actually happening is that the card in the card catalog gets moved to the “obsolete” section of the card catalog. If you “restore” the file from the recycle bin, the catalog card is moved back from the “obsolete” section to where it was. And when you empty the recycle bin, all that happens is that the cards in the “obsolete” section of the card catalog are shredded. The book is still there on the shelf, but the space it occupies is declared as available for new books. Only if the librarian (in this case, your computer) happens to put another book into that exact space on the shelf, does the book ever really go away. This is why an expert can “recover” deleted files from a computer. There are special programs that can search the shelves directly without using the card catalog.

In fact, most of the interactions you appear to be having with the file system are actually happening with the “card catalog.” Renaming or moving files or organizing them into folders are all things being done not with the books out on the shelves, but with the “cards” in the “card catalog.”

But what about defragmenting? As the library fills up with new books, some larger and some smaller, shelf space becomes harder to manage. If the librarian gets a new, really big book, space must be found for it. Since this is a very strange and magical library, what normally happens is not re-arranging the books to make space, nor does the librarian always choose to put the book on an empty shelf far away in the back, even though that seems to be the only space large enough. It turns out to be quicker to rip the book along the spine so that the various fragments fit into available spaces, and then to make lots of notes on the card in the card catalog saying where all the fragments are and how to re-assemble them when someone checks out (a copy of) the book. This works just fine until a significant percentage of the books in the library are stored in fragments. Retrieving all the fragments and re-assembling the books as they are checked out starts to consume significant time. At this point, it becomes worthwhile to “defragment” the books by re-arranging the library so that most of the books sit on the shelves whole. In addition to moving books on the shelf, much of the work involves revising the cards in the card catalog to reflect the new arrangement of books on the shelves. So defragmenting a disk is done infrequently and takes a relatively long time.