To defragment a disk drive is to physically rearrange the contents of the files stored on the disk so that they can be accessed more efficiently.
The information stored in a single file may not necessarily be stored in one place. For a variety of reasons the data may be scattered in fragments kept in various locations around the surface of the disk. The file system keeps track of where all the fragments are so that when we use a file it behaves as one single thing.
Traditional hard disks involve actual moving parts, so a file that is scattered around a disk’s surface will be slower to access than one where all the pieces are near each other. Defragmenting simply rearranges the pieces of files such that they are not only near each other, but also in order, so that reading the file can take place as quickly as possible.
Disks without moving parts – such as flash drives and SSDs – typically do not benefit from defragmenting.