# What Happens When You Defragment a Drive?

One of the age-old solutions to fix a slow computer is to defragment its hard drive. This is easy enough to do: Simply run the defragmenter and wait for it to finish its job. Have you ever wondered, however, what defragmenting means exactly? It may sound like a complex procedure by its name, but it’s actually quite simple. Let’s take a look at how disks store data, and how they become fragmented in the first place.

One way to understand how a disk becomes fragmented is to imagine a man who’s in charge of filing reports within several filing cabinets. Whenever you, a worker at this office, need to file or take out a report, you go through him. While a hard worker, this man’s organisation method is very strange.

If he’s given a report, he’ll go through the drawers starting from A to L looking for an empty spot to put the report. If he finds a spot, he places the report into it. Otherwise, he puts it at the very end. When a report is removed, the gap it leaves behind stays there. The sorter doesn’t make any effort to “shunt up” reports to fill the gap – he just leaves the gap as it is.

For example: if he fills all the drawers from A to F, and then a 100-page report from C is removed, the 100-page gap will stay in C. Then, if the man receives another 100-page report to file, he’ll go through each drawer looking for a gap. He’ll find the 1oo-page gap in C which he fills snugly with the report he just received.

### The Problem

So far so good, right? However, imagine if we had a gap left in a drawer, and the man receives a report larger than the size of the gap. In the above example, picture if the man received a 200-page report rather than a 100-page one. In this case, in an attempt to fill the 100-page gap in C, he’ll split the report in two. He’ll put 100 pages into C, then the other 100 pages at the very end, assuming there are no more gaps. This means the report is now “fragmented” into two halves.

All it takes is for several small reports to be removed over a long period of time, and you find yourself in a real problem. After some time has passed, if you asked him to file a 250-page report, he may find a 50-page-sized gap in Cabinet B, then a 25-page gap in Cabinet C, then another 25-page gap in F, a 100-page gap in G, and a 50-page gap in K. To fill all the gaps, he splits the 250 pages amongst them. This means, when you ask him to get the report out, he has to go through Cabinet B, C, F, G, and K in order to get all the pieces of the report, which takes a lot of time to do. What a hassle!

It doesn’t take a genius to realise the man should take some time at the end of the week to sort the reports into consecutive order. By shuffling pages in and out of the main filing system, he can arrange the cabinets so that each report has their pages all together in the right order. That way, when you ask for a report, he doesn’t have to open several scattered drawers to get it, and it saves time as a result.