Defragmenting a hard drive means rearranging the data as saved on the disk so it is in a sequential order. If you imagine a magnetic drive as a sentence, multiple files would read something like "Create file1.txt; Create file2.txt; Add data to file1.txt; Create file3.txt" and so on. Over time as more files are created and updated each file's data is spread out throughout the disk and the drive becomes slower. Degragmention rearranges the files so that the data is sequential: "Create file1.txt; Add data to file1.txt; Create file2.txt; Create file3.txt" and so on. By grouping each file's data into the same area of the disk the performance improves greatly. Solid State Drives (SSD) do not need to be defragmented.
The maintenance of file systems, defragmentation is a process that reduces the amount of fragmentation This is done by physically organizing the data inside of the mass storage device used to store the files into the smallest number of contiguous regions (fragments, extents) It also attempts to create larger regions of free space using compaction to impede prevent fragmentation Some defragmentation utilities try to keep smaller files within a single directory together, because they are usually accessed in a sequence Defragmentation is effective and relevant to the file systems on electromechanical disk drives (hard disk drives, floppy disk drives and optical disk media)