Initial Problem:
In the context of administering computer systems, defragmentation is a process that reduces the amount of fragmentation in file systems. It does this by physically organizing the contents of the disk to store the pieces of each file close together and contiguously. It also attempts to create larger regions of free space using compaction to impede the return of fragmentation. Some defragmenters also try to keep smaller files within a single directory together, as they are often accessed in sequence.
When running programs that contains hundreds of files, fragmenting can degrade the performance of your computer. As the clusters of files on your hard drive become fragmented, they grow further apart and it takes longer for your computer to find and assemble all the pieces necessary to run the programs. This is where defragmenting comes in. It rearranges the files on your hard drive so they are back in order, which cuts down on access latency (the time it takes to access your files). It is as if the library has hired a new librarian who goes through and arranges the books so that the volumes are intact and contiguous. This would greatly reduce the time it takes to find whole volumes or individual books in those volumes.
Solution:
Figure 1. Opening Disk Defragmenter in Run
Please go to Start -> Run, type dfrg.msc and press OK

The disk defragmenter window will open with a list of all the drives on your computer. Select the drive that you want defragged by clicking on it. Before defragmenting, click the “Analyze” button to see if it is necessary.
Figure 2. Disk Defragmenter Console
The Windows Disk Defragmenter program will open and all drives are listed in the top window pane. Since the program is going to be arranging files on your hard drive, it is important that no files are being accessed during the process, or the program won't be able to move them. Close all open programs.

Figure 3. Defragmentation itself

While the program is running, it is recommend that you not use your computer. The time is takes to run the defragmenting process is dependent on the size of your hard drive and amount of fragmentation. While the program is running you will see a graphical representation of the blocks of files on your hard drive being moved and the fragmented segments joined together. Usually the less gaps of free space between the contiguous segments the better, but as long as the fragmented files are put together into contiguous segments, it will help your computer's performance.
Figure 4. Defragmentation result
Once the process is complete, the graphic should display most of the contiguous files on the left and the majority of the free space on the right. Close the Disk Defragmenter window and resume using your computer.

Even after running the defragmenter, some files will remain fragmented. Any files that are in use are left alone by the defragmenter so things like pagefile.sys will not be defragmented.
When Disk Defragmenter hangs or continually restarts
A problem that I have encountered on several computers seems to arise because of something in the Internet cache. Corruption of a cached page or Web sites that have very long names can cause the defragmentation process to hang. Therefore, I always clean out the Internet cache before running defrag. In fact, it is a good idea to clean up all temporary files first.
Interference from programs running in the background seems to be much less of a problem in Windows XP than it was in Windows 98/Me. Nonetheless some programs like GoBack, Norton SystemWorks, or ZoneAlarm may sometimes interrupt the defrag process so you may need to turn them off. (Note: for safety, closing down your firewall and other defensive software should be done only when disconnected from the Internet.) Another way to avoid this type of problem is to go to Safe Mode to run Disk Defragmenter.