Hard Disk Drives store their data in sectors as shown in the diagram below. A real Hard Disk Drive would have thousands of such sectors.
Initially data saves in a sequential order as you may well expect.
Once you start deleting files, folders and programs sectors become empty at different sectors. This means the needle which reads the data on the Hard Disk Drive has further to move in order to read the data.
Defragmenting the Hard Disk Drive moves data back into sequential sectors, therefore making the time the needle takes to read data shorter and your PC run faster.
Initial Stage - Formated Hard Disk
Files Are written to sectors serially
Fragmentation due to deletion of files
After Defragmentation
Defragmentation Tool in Windows