CMD Guide
HomeSystem DesignSystem Design Building Blocks

Checksum

A checksum detects corruption by running the bytes through a deterministic function that produces a small fixed-size fingerprint, storing or transmitting that fingerprint next to the data, and recomputing it on the other side: if the two fingerprints disagree, at least one bit changed in transit or at rest, and the receiver rejects the copy instead of silently returning garbage.

The problem it solves

Bits rot. A DRAM cell flips under a cosmic ray, a disk sector degrades, a NIC or switch mangles a frame, a buggy driver writes the wrong block. None of these announce themselves — the read succeeds and hands back plausible-looking bytes. A checksum turns silent corruption into a loud, catchable error: you compare a cheap fingerprint you trust against one you recompute, and a mismatch means "do not use this data."

Cryptographic vs. non-cryptographic — the distinction that matters

The single most common misconception is that checksums are computed with cryptographic hashes like MD5 or SHA-256. In real distributed systems they usually are not. Integrity checks against accidental corruption overwhelmingly use fast, non-cryptographic functions:

Cryptographic hashes are the exception, used only when you need a property a CRC cannot give: collision/preimage resistance against a malicious actor, or a stable content identity (Git object IDs, dedup keys, container image digests). A CRC is trivial for an attacker to recompute after editing your data; SHA-256 is not. So the rule is: CRC/xxHash for accidents, cryptographic hash (or HMAC/signature) for adversaries and identity.

Where a checksum sits: on-wire vs. at-rest

The same idea guards two different boundaries, and mature systems check at both because each catches failures the other misses:

Worked example 1 — CRC by polynomial long division

CRC treats the message as coefficients of a binary polynomial and takes the remainder after mod-2 (XOR) division by a fixed generator. Take data 1101011 and generator G = 1011 (degree 3, so the checksum is 3 bits). First append 3 zeros, then repeatedly XOR G wherever the leading bit is 1:

StepLeading bit at posActionWorking register
startappend 3 zeros1101011000
01XOR 10110110011000
11XOR 10110011111000
21XOR 10110001001000
31XOR 10110000010000
40shift, bring down0000010000
51XOR 10110000000110
60shift, bring down0000000110

The last 3 bits are the remainder: 110. Transmit data + remainder = 1101011110. The receiver divides the whole thing by 1011; because we appended the remainder, the division now comes out to remainder 000 → clean. Any single-bit flip, and most burst errors, force a non-zero remainder. That is the entire mechanism: a clean channel leaves remainder 0.

Worked example 2 — one bit flips, the checksum avalanches

Real integrity checks work on bytes. Take the ASCII string HELLO and flip a single bit in the first byte: H is 0x48 = 0100 1000; flip the low bit → 0x49 = I, giving IELLO. Recompute CRC-32 (the standard zlib/IEEE polynomial):

BytesChangeCRC-32 (hex)
HELLOoriginal0xC1446436
IELLO1 bit0xFC244D86

One flipped bit changes the entire 32-bit fingerprint — a good checksum avalanches, so the receiver's recomputed value (0xFC244D86) will not match the stored 0xC1446436 and the read is rejected. Contrast a naive checksum that just XORs or sums bytes: two compensating bit flips (e.g. add 1 to one byte, subtract 1 from another) cancel out and slip through undetected. That is why CRC's polynomial division, not a plain byte-sum, is the workhorse.

diagram
diagram

Pitfalls

When to use which — and when NOT to

The decision is almost entirely "what am I defending against, and how fast must it be?"

Alternatives to a checksum entirely: if you need to recover corrupted data, not just detect it, prefer an error-correcting code (ECC memory, Reed-Solomon/erasure coding) — it costs extra parity storage and encode/decode CPU but repairs damage in place. If you need to prove who produced the data, prefer a digital signature over any checksum. A plain checksum is the right tool only when detect-and-refetch is an acceptable response.

Takeaways


Sources: Grokking the System Design Interview (checksum building block); J. Stone & C. Partridge, "When the CRC and TCP Checksum Disagree" (SIGCOMM 2000); Apache Hadoop HDFS and Apache Kafka documentation (CRC-32C data integrity); ZFS end-to-end checksum design (Bonwick & Moore). CRC and CRC-32 values independently verified with Python's zlib. Re-authored and deepened for this guide.

🤖 Don't fully get this? Learn it with Claude

Stuck on Checksum? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Checksum** (System Design) and want to truly understand it. Explain Checksum from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Checksum** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Checksum** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Checksum** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes