How do files get corrupted?
A file is corrupted when its stored bytes no longer represent valid data for its format. The causes are varied, and most are about interrupted writes rather than data spontaneously degrading.
Interrupted writes, the most common cause. Writing a file is not instantaneous. Power loss, a crash, or removing a USB drive mid-write leaves the file partially updated — some new data, some old, and often an inconsistent index. This is why safely ejecting removable media matters: the operating system buffers writes for performance, and data you believe is written may still be in memory.
Storage failures. Hard drives develop bad sectors as magnetic surfaces degrade. SSDs have a finite number of write cycles per cell, and although wear levelling distributes this, cells eventually fail. Both technologies use error correction that handles small errors invisibly — corruption becomes apparent when errors exceed what correction can repair.
Filesystem inconsistency. The filesystem's own metadata — which blocks belong to which file — can become inconsistent after an unclean shutdown. Journaling filesystems mitigate this by recording intended changes before making them.
Memory errors. Faulty RAM writes wrong data to disk perfectly, so the file is stored exactly as corrupted. Bit flips from cosmic rays are real but very rare; ECC memory in servers exists to catch them.
Incomplete transfers over an unreliable network, and cloud sync conflicts where two versions merge badly.
Malware, particularly ransomware, which corrupts deliberately.
Application bugs writing malformed output.
What actually protects you:
Backups following the 3-2-1 rule — three copies, two media types, one offsite. This is the only genuine protection.
Versioned backups, since syncing a corrupted file overwrites the good one.
Checksums to detect corruption early, before it propagates into backups.
Uninterruptible power supply for desktops, and safe ejection habits.
Recovery is sometimes possible with format-specific repair tools, but partial at best.