How do bad sectors happen?

Bad sectors are areas on a hard disk drive (HDD) that can no longer reliably store data due to permanent damage or manufacturing defects. There are several reasons bad sectors can develop on a drive.

Physical Damage

One of the most common causes of bad sectors is physical damage to the HDD platters. The platters are thin circular discs inside the drive that are coated with a magnetic material for data storage. If the platters become scratched, dented, or warped, it can prevent data from being read from or written to certain areas, resulting in bad sectors.

Some ways physical damage can occur include:

  • Dropping or jarring the hard drive
  • A head crash where the read/write head makes contact with the platter surface
  • Overheating which can warp or melt the platters
  • Manufacturing defects such as bubbles or inconsistencies in the platter material

Even very minor physical damage that is invisible to the naked eye can interfere with the precise operation of the read/write heads and cause bad sectors.

Magnetic Issues

Problems with the magnetic properties of the platter surface can also lead to bad sectors.

During the HDD manufacturing process, the platters are coated with a ferromagnetic material that allows the data to be recorded by magnetizing tiny areas on the platter surface. Issues that can occur include:

  • Weak magneticStrength in parts of the platter so data is not written or read properly
  • Loss of magnetic charge over time causing data loss
  • External magnetic fields reaching the platters and corrupting data

These types of issues result in areas that cannot maintain a reliable magnetic charge to store data, resulting in bad sectors.

Failed Flash Memory Cells

In solid state drives (SSDs), bad sectors occur when NAND flash memory cells wear out and can no longer reliably store data. This typically happens after tens of thousands of write/erase cycles.

Reasons flash cells become damaged and unusable include:

  • Wear from excessive drive writes/erasures
  • Read disturbs where nearby cells get corrupted
  • Write disturbs during programming
  • Electrical issues like overvoltage or current spikes
  • Manufacturing defects in the flash chips

The SSD controller will detect when a flash cell cannot hold data reliably anymore and mark it as a bad sector.

How are bad sectors detected and managed?

The hard disk and SSD controllers have several methods to detect and manage bad sectors.

Error detection

When writing to or reading from a sector, error checking codes are used to verify the data is valid. If the drive detects excessive read or write errors in a sector, it will flag it as pending reallocation. After further read/write tests, if the errors persist, the sector is marked as bad and reallocated.

Read scans

Drives will periodically scan all sectors, reading data to check for any unresponsive or weak sectors. This helps identify bad areas before they are needed for actual user data storage.

S.M.A.R.T. monitoring

Self-Monitoring, Analysis and Reporting Technology (S.M.A.R.T.) uses sensors to monitor drive health metrics like reallocated sectors, temperature, mechanical shock, etc. The drive firmware analyzes these metrics to predict failures and mark bad sectors.

Reallocation

When a sector goes bad, the drive will reallocate the data to a spare good sector. This is done transparently so the OS still accesses the original logical block address. The original bad sector is marked as unusable to prevent further writes.

Bad sector mapping

The drive maintains a map of bad sectors. When the OS requests data from a bad sector, the drive will transparently remap the request to the spare sector.

Sparing

Drives reserve extra sectors during manufacturing specifically for reallocating bad sectors later. For example, an 80GB drive may have an extra 1% or 800MB set aside for spares.

How many bad sectors are acceptable?

Most drives can tolerate a small number of bad sectors with no noticeable performance impact. However, if the bad sector count grows, it indicates the drive is deteriorating and more failures are likely. As a guideline:

  • HDDs – Up to 10-50 bad sectors is usually considered acceptable on larger high capacity HDDs. Beyond this indicates issues.
  • SSDs – Even 1 bad sector is a sign of degradation on an SSD. More than this means problems ahead.

Ideally, you want as few reallocated sectors as possible on a healthy drive. Drives with 0 bad sectors are ideal.

Can bad sectors be fixed?

There is no way to repair and restore bad sectors that have developed. The damage is permanent and they will continue to store data unreliably. However, the drive can still continue operating by managing the bad sectors. Typical solutions include:

  • Letting the drive remap bad sectors automatically to spare areas
  • Manually locking out bad sectors so they are no longer used
  • Low level formatting to factory reset the drive and retest all sectors
  • Zero filling or secure erasing the drive to remap sectors

These methods allow the drive to continue working by avoiding the bad areas. But the bad sectors themselves cannot be repaired.

How to avoid bad sectors

To help minimize bad sectors developing over time:

  • Handle drives gently and limit shock/vibration
  • Maintain proper airflow to prevent overheating
  • Use surge protectors to avoid power spikes
  • Don’t heavily fragment the drive which forces excessive seeking
  • Scan drives periodically for reallocated sectors
  • Replace aging drives before failures occur

Following drive maintenance best practices will help maximize lifespan and data reliability.

Recovering data from drives with bad sectors

If your drive is showing reallocated sectors, it’s at risk of further issues. The first priority is backing up any important data before problems get worse. Options include:

  • Copy files directly to another drive if sectors haven’t failed yet
  • Use data recovery software to retrieve data from degraded areas
  • Send to a professional recovery service if DIY methods don’t work

The sooner you can backup, the more data you will likely be able to save before the drive completely fails.

Conclusion

Bad sectors naturally develop over time on HDDs and SSDs due to physical damage, magnetic issues, or flash memory cell degradation. The drive firmware manages these issues by reallocating data and mapping out bad areas. A small number of reallocated sectors is normal, but growing bad sectors indicate a failing drive. While bad sectors themselves can’t be repaired, drives use workarounds like sparing and remapping to continue operating in a degraded state. Following best practices for drive handling, maintenance, and backups will help maximize data life span.