Checksums vs Hashes: CRC, MD5 and SHA
Overview
Not all fingerprints are equal. A CRC is tiny and fast and catches accidental damage. A cryptographic hash such as SHA-256 is bigger and slower but resists deliberate tampering. Picking the right one means knowing what threat you are guarding against.
Detailed Notes
What is a hash function
A hash function maps data of any size to a fixed-size output called a hash or digest, and the same input always gives the same output. A cryptographic hash adds security properties:
- Avalanche effect: a tiny change in the input changes the output completely.
- Collision resistance: you cannot practically find two inputs with the same hash (or an input for a given hash).
The problem it solves
Two teams need integrity checks.
- Team A builds a storage engine verifying millions of 4 KB blocks per second. They need something extremely cheap, so they use CRC32C, which modern CPUs accelerate in hardware.
- Team B publishes software installers and must prove a mirror site did not swap in a modified file. A CRC is worthless here because an attacker can change the file and recompute a matching CRC. They publish a SHA-256 hash through a trusted channel.
Same idea, different threat: accident versus attacker.
How it works
CRC (Cyclic Redundancy Check) treats the data as a huge binary number and divides it by a fixed polynomial; the remainder is the checksum (usually 32 bits). It catches common physical errors such as burst errors (several adjacent bits damaged) and is very cheap, but it is predictable, so an attacker can craft changed data with the same CRC.
MD5, SHA-1, SHA-256: MD5 (128 bits) and SHA-1 (160 bits) have practical collision attacks, so they are not safe for security (MD5 survives as a quick non-security check). SHA-256 (256 bits, SHA-2 family) is widely considered secure today.
| Feature | CRC32C | MD5 | SHA-256 |
|---|---|---|---|
| Size | 4 bytes | 16 bytes | 32 bytes |
| Speed | Fastest | Fast | Slower, still fast |
| Resists deliberate tampering | No | No | Yes, if the hash itself is trusted |
Integrity vs authenticity. Integrity asks "did the data change by accident?" Authenticity asks "did it come from who I think, and has nobody changed it on purpose?" A plain hash stored next to the data proves nothing about authenticity, since an attacker changes both. Authenticity needs a secret key (an HMAC) or a digital signature (both covered in the Security chapter later).
How to choose: CRC32C for random corruption on hot paths (storage, network); SHA-256 for verifying file content across systems, published through a separate trusted channel; a signature or HMAC to resist tampering. Never invent your own checksum.
A simple example
A CRC is a quick glance at a cheque's numbers to catch typing mistakes. SHA-256 is a hologram security seal: slower, very hard to forge.
System design example
A package mirror lists a SHA-256 hash and a maintainer signature for each release. If a mirror is compromised and a file replaced, users who compare against the official hash see a mismatch and refuse to install. Inside the mirror's storage cluster, every 1 MB block carries a CRC32C that catches disk rot on each read. Two layers, two jobs: CRC for accidents, SHA-256 and signatures for attackers.
Summary
- CRC is fast and built for accidents, not attackers.
- MD5 and SHA-1 are unsafe for security; SHA-256 is the safe default.
- Integrity (accidents) differs from authenticity (attackers).
Architecture Diagram
CRC for accidental corruption on hot paths; SHA-256 and signatures where tampering matters.
- 1Data enters the system and a fingerprint is computed.
- 2Hot paths use a CRC; trust boundaries use SHA-256, HMAC or signatures.
- 3The receiver recomputes and compares.
Common Interview Questions
Finished this lesson?
0 of 91 lessons done · 0% of the course

