If you've gotten a message on your computer telling you about a bad sector or cluster on your hard drive, you may have experienced a sinking feeling while wondering what data has been lost. Bad sectors and clusters are a fact of life with all mass storage devices, whether magnetic like hard drives or solid state like flash memory. However, operating systems have ways to mark and avoid them when they come up, ensuring your data stays safe.
In a standard hard drive, data is written to a spinning magnetic platter using electromagnetic heads which write the data in thin, concentric bands. These same heads retrieve the data from the appropriate physical location when that data is recalled by the operating system.
Solid state drives use huge numbers of tiny transistors, storing data in the form of stored electrons rather than the magnetically encoded data of a traditional hard drive. As they have no moving parts and use transistors in place of magnetic platters, they are referred to as "solid state."
Sectors and Clusters
On a hard drive, the sector is the smallest unit of physical storage on the disk, usually 512 bytes. Generally an operating system will attempt to write related data in contiguous sectors on a disk, as this is the most efficient way to store and retrieve data. A cluster is comprised of these consecutive sectors, which always number in an exponent of 2. While SSDs don't have sectors in the same sense that HDDs do, data is still stored in physical locations on the drive -- the transistors.
Why Sectors and Clusters Go Bad
On a hard drive, there are two main types of bad sectors -- hard and soft. Hard bad sectors are caused by physical damage to the disk platter itself. This is typically caused when the read/write head touches the surface of the disk, which can occur when the drive is bumped while data is being read or written. A soft bad sector occurs when the error correction code for that sector doesn't match the content of the sector, usually due to a virus or failing to shut the computer down properly. SSDs, on the other hand, have no moving parts to fail, so most SSD failures are of the "soft" variety, but over time it is possible for the individual transistors within them to fail.
Fixing and Preventing Bad Sectors and Clusters
Unfortunately, there isn't much you can do to repair a hard bad sector, as the drive platter cannot be physically repaired. The operating system will flag that sector and avoid writing data to it in the future, however. It is possible to recover soft bad sectors through defragmentation, which regroups data in a more logical pattern on the disk.
Bad sectors in a hard drive can be prevented by not moving the disk abruptly while it is writing data, to prevent the head from making contact with the platter. Shutting down the computer properly to allow data to be written correctly will help prevent soft bad sectors, as will using a quality anti-virus program to prevent malware from damaging your file system.