CMD Guide
HomeSystem DesignChecksum

What is Checksum

A checksum is a small, fixed-size value computed by running every byte of a message through a deterministic function, so that changing any byte almost always changes the value — which lets whoever receives the data recompute the function and compare, catching corruption before it is trusted.

The problem it solves

When data moves between components — across a network link, off a disk, through RAM — bits flip. A cosmic ray flips a memory cell, a cable induces a burst error, a firmware bug drops a byte. The receiver has no way to know the bytes it holds are the bytes that were sent. A checksum attaches a compact fingerprint alongside the data so the receiver can answer one question cheaply: are these the bytes I was supposed to get? If not, it can raise an error or refetch from another replica instead of silently serving garbage. At scale this is not hypothetical: one petabyte is 8×1015 bits, so even a very low bit-error rate of 10−15/bit works out to roughly 8 flipped bits on every full scan of the data.

The important correction up front: a checksum is any function that folds data into a fixed-size fingerprint for integrity checking. It does not have to be a cryptographic hash. The workhorses of real systems are cheap, non-cryptographic algorithms — CRC32 (Ethernet frames, ZIP, PNG), Adler-32 (zlib), Fletcher, the 16-bit one's-complement Internet checksum (TCP/IP). Cryptographic hashes like SHA-256 are checksums too, but they are a heavyweight subset you reach for only when you must defend against a deliberate attacker, not merely random noise.

A worked example: Adler-32 on the bytes "Hi"

Adler-32 (used inside zlib) is simple enough to run by hand and shows the mechanism clearly. It keeps two running sums, A and B, both reduced modulo 65521. A starts at 1 and adds each byte; B accumulates A after every step. The final checksum is (B << 16) | A. The two-sum trick means the result depends not just on which bytes appear but on their order — a plain sum would give the same answer for "Hi" and "iH".

Input bytes: 'H' = 72, 'i' = 105.

StepByteA = A + byteB = B + A
init10
172 ('H')1 + 72 = 730 + 73 = 73
2105 ('i')73 + 105 = 17873 + 178 = 251

Both sums are well under 65521, so the modulo is a no-op here. Final: A = 178 = 0xB2, B = 251 = 0xFB, giving checksum = (251 << 16) | 178 = 0x00FB00B2.

Now corrupt one bit. Suppose the 'H' (72, binary 01001000) has its low bit flipped in transit, becoming 'I' (73, 01001001):

StepByteAB
173 ('I')1 + 73 = 740 + 74 = 74
2105 ('i')74 + 105 = 17974 + 179 = 253

New checksum: (253 << 16) | 179 = 0x00FD00B3. The receiver recomputes Adler-32 over the bytes it holds, gets 0x00FD00B3, compares it to the transmitted 0x00FB00B2, sees they differ, and rejects the data. A single flipped bit was caught by four additions.

diagram
diagram

Pitfalls

When to use which — and the trade-offs

"Add a checksum" is not one decision; it is choosing where you sit on a cost-versus-guarantee curve. The signals that point to each option:

Rule of thumb: CRC32 when the enemy is noise; SHA-256 when the enemy is a person; HMAC/signature when the enemy controls the wire. Reaching for SHA-256 to guard an internal disk block wastes CPU; reaching for CRC32 to verify a downloaded release binary is a security hole.

Takeaways


Re-authored and deepened for this guide. Sources: RFC 1071 (Computing the Internet Checksum); RFC 1950 (ZLIB / Adler-32 specification); Philip Koopman, Better Embedded System Software and his CRC/checksum research (Carnegie Mellon); Martin Kleppmann, Designing Data-Intensive Applications (on end-to-end integrity and replica repair); the ZFS end-to-end checksum design notes. The original page's claim that a checksum is computed with a cryptographic hash function was corrected — cryptographic hashes are one heavyweight subset of checksums, not the definition.

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

Stuck on What is 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 **What is Checksum** (System Design) and want to truly understand it. Explain What is 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 **What is 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 **What is 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 **What is 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