SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
  • OSI Model
  • IP Address
  • TCP vs UDP
  • HTTP / HTTPS
  • DNS
  • Proxy vs Reverse Proxy
  • Checksums
  • HTTP/1.1 vs HTTP/2 vs HTTP/3
  • Cookies and CORS
  • Subnets, CIDR and NAT
  • Firewalls and VPN
  • Ports and Sockets
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Foundations/Networking

Checksums

A small number that helps you check if data was changed or damaged.

⏱ 10 min readIntermediateHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A checksum is a small number worked out from some data. If the data changes, even a little, the number changes too.

  • The sender works out the checksum and sends it with the data.
  • The receiver works it out again. Same number: the data is probably fine. Different: it is damaged.
  • Checksums catch accidents (noise, bad disks, bit flips). Normal checksums do not stop a clever attacker.

02Concept: What is it?

A checksum is a short fingerprint of data. A function reads all the bytes and gives a small fixed-size number. The same data always gives the same number. Different data almost always gives a different number.

The basic idea
📄Any data1 KB or 10 GB
→↓checksum function
🔢Small numberfor example 4 bytes

The family of checksums

TypeSizeGood forSafe against attackers?
Simple sum / parity1 to 2 bytesVery basic error checksNo
Fletcher, Adler-322 to 4 bytesCheap, quick checksNo
CRC32 (cyclic redundancy check)4 bytesNetwork frames, ZIP, storage, EthernetNo
MD516 bytesSpotting accidents, old file checksNo: broken
SHA-120 bytesOld systemsNo: broken
SHA-25632 bytesFile downloads, certificates, blockchainsYes, as a hash
📝Checksum vs hash
People use the words loosely. A checksum is made to catch random errors. A cryptographic hash (like SHA-256) is also made so nobody can build different data with the same hash on purpose. Every hash can act as a checksum, but not the other way round.

03Real-Life Example

🍵Counting the pages
You post a 100-page book to a friend. On the envelope you write: “100 pages, last page ends with the word ‘end’.” Your friend counts the pages when it arrives. If they count 98, they know something went missing and they ask you to send it again. You did not have to send the whole book twice to find out.
🍵The bank account number
Many ID numbers (bank cards, ISBN book codes) have a last digit that is a check digit. If you type one digit wrong, the check fails at once, before any money moves.
Real life
Checksum
“100 pages” on the envelope
The checksum sent with the data
Counting the pages on arrival
Receiver recalculates the checksum
Numbers match
Data is probably fine
Numbers differ
Data is damaged: ask again
Last digit of a card number
A check digit (a tiny checksum)

04Why Do We Need It?

Data does get damaged. Cables pick up noise. Memory chips flip a bit. Disks go bad. Software has bugs. And a copy of 50 GB cannot be checked by eye.

📡Noisy networks
A bit can flip on the way. A checksum shows it.
💽Bad storage
Disks and SSDs can slowly corrupt data (bit rot).
📥Downloads
Check that the file you got is the file that was published.
🔁Copies and backups
Compare two big copies by comparing two tiny numbers.
🧮Find duplicates
Same checksum often means same file. Skip uploading it again.
🚨Fail loudly
Better to know data is bad than to use it silently.
A checksum lets you check a huge amount of data by comparing one tiny number.

05Where Do We Use It?

🌐TCP, UDP and IP headers
Each has a checksum field to catch damaged packets.
🔌Ethernet frames
Each frame ends with a CRC32.
🗄️Databases and file systems
Pages and blocks carry checksums to find corruption (for example ZFS, Btrfs, many databases).
☁️Cloud storage
Services compare checksums when you upload and when data is read, and during repair.
📦Downloads and packages
Sites publish SHA-256 values so you can verify files.
📨Message queues and logs
Records carry a CRC so broken ones can be skipped or repaired.
Where it sits in a data journey
💻Senderadds checksum
→↓network (may flip bits)
🖥️Receiverchecks it
→↓then saves
💽Diskchecks again on read

06Types / Parts / How It Works

How checking works

Send, receive, compare
📄Data
→↓calculate
🔢Checksum S
↓send both
📄Data'maybe changed
→↓calculate again
🔢Checksum R
→↓R = S ?
✅Sameaccept
❌Differentreject / resend
If the two numbers differ, the data is thrown away or requested again.

Simple methods, from weak to strong

1️⃣Parity bit
Add one bit so the count of 1s is even. Catches a single flipped bit. Misses two.
➕Sum of bytes
Add all bytes. Quick, but swapping two bytes gives the same sum.
🔀Fletcher / Adler
Two running sums, so the order of bytes matters too.
🌀CRC
Treats data as a long binary number and divides it. Great at catching burst errors.
🧬MD5 / SHA-1
Older hashes. Fine for accidents, not for security.
🔐SHA-256 and up
Strong hashes. Used when someone may try to cheat.

Check digit example

📝Parity in one line
Data bits 1011001 have four 1s. With even parity we add a 0. If one bit flips on the way, the count of 1s becomes odd, and the receiver knows something is wrong.
VisualizerDoes the checksum catch the damage?Type a message, damage it, then compare the two checksum types.
2. Checksum type
3. What goes wrong on the network?
Sender: message + checksum 5E
P
A
Y
␣
1
0
0
␣
T
O
␣
R
A
M
5Echecksum
↓ 🌐 network ↓
Receiver: gets this, then recalculates 5F
P
A
Y
␣
2
0
0
␣
T
O
␣
R
A
M
5Esent checksum
Sent checksum
5E
Receiver calculates
5F
Result
Caught!
The checksums are different, so the receiver knows the data is damaged and asks for it again.These are small teaching checksums. Real systems use CRC32 (network frames, storage) or hashes like SHA-256 (file downloads). MD5 and SHA-1 are fine for catching accidents, but not safe against a clever attacker.

07How to Use It / Steps / Implementation

Using a checksum

  1. 1
    Pick the right tool
    Accidents only: CRC32 is fast. Someone may cheat: use SHA-256 (or a signature).
  2. 2
    Calculate when the data is created or sent
    Store or send the checksum with the data.
  3. 3
    Calculate again when the data is read or received
    Use the same method on the same bytes.
  4. 4
    Compare
    Same: continue. Different: reject, retry or repair from another copy.
  5. 5
    Keep the checksum safe
    If an attacker can change both the file and its checksum, the check is useless.

Verify a download (terminal)

Check a file with SHA-256
# Mac / Linux
shasum -a 256 tool.zip
# or
sha256sum tool.zip

# Windows PowerShell
Get-FileHash tool.zip -Algorithm SHA256

# Compare the result with the value on the official site

A tiny checksum in code

Fletcher-16 (idea, JavaScript)
function fletcher16(bytes) {
  let s1 = 0, s2 = 0;
  for (const b of bytes) {
    s1 = (s1 + b) % 255;
    s2 = (s2 + s1) % 255;
  }
  return (s2 << 8) | s1;
}
💡In real systems
Do not write your own for production. Use your language’s library for CRC32 or SHA-256.

08Key Terms to Know

TermMeaning in easy words
ChecksumA small number worked out from data, used to spot changes
Hash functionA function that turns any data into a fixed-size value
Cryptographic hashA hash built so that nobody can create different data with the same value
CRCCyclic redundancy check. A strong, fast checksum for random errors
Parity bitOne extra bit to make the count of 1s even or odd
Check digitA digit added to an ID number to catch typing mistakes
CollisionTwo different inputs that give the same checksum
Bit flipA single 0 changing to 1 (or the other way)
Bit rotSlow silent damage to stored data
IntegrityData has not changed since it was made
Error detectionFinding out that data is wrong
Error correctionFinding out AND fixing it (for example ECC memory, erasure codes)
DigestAnother word for the output of a hash

09Pros, Cons and Trade-offs

Pros
  • Tiny and fast to calculate
  • Catches most accidental damage
  • Compares huge data with one number
  • Easy to add anywhere: packets, files, records
Cons
  • Detects problems, usually cannot fix them
  • Weak checksums can miss some errors (collisions)
  • Not safe against an attacker unless it is a strong hash and the value is protected
  • Needs a plan for what to do on failure
ChoiceWe gainWe lose
Short checksum (16 or 32 bits)Speed and small sizeMore chance of a missed error
Long hash (SHA-256)Very low chance of collisions, securityMore CPU time, bigger value
Check at every stepFind the problem earlyMore work for each step
Check only at the endCheaperYou learn late, and cannot tell where it broke

10Common Problems and Mistakes

Common mistakes

  1. Using MD5 or CRC for security. They only catch accidents. An attacker can make a changed file with the same value.
  2. Keeping the checksum next to the file on the same server. If the server is hacked, both can be changed. Publish the value somewhere separate, or sign it.
  3. Using a checksum as a password hash. Passwords need slow, salted hashes (like bcrypt or Argon2).
  4. Ignoring failures. Detecting bad data and then using it anyway is worse than useless.
  5. Comparing different forms of the same data. Line endings or text encoding can change the bytes, and so the checksum.
  6. Thinking a matching checksum means “100% sure”. It means “very likely”. Short checksums can collide.

Known problems

🎯Collisions
Two different inputs can share a value. Longer values make this very unlikely.
🔓Broken hashes
MD5 and SHA-1 have known collision attacks and should not be used for security.
🧯Detect only
A checksum says “wrong” but not “what is right”. You need a second copy or an error-correcting code.
🫥Silent corruption
Without checksums, bad data can pass through many systems unnoticed.

11Real-World Examples

🌐Internet packets
IPv4, TCP and UDP headers carry a checksum. Ethernet frames carry a CRC32.
🗜️ZIP and PNG files
Both contain CRC32 values to detect damaged files.
🗄️Distributed storage
Systems such as HDFS and cloud object stores keep checksums on blocks and repair bad ones from other copies.
🐧Linux and package managers
Downloads are checked with SHA-256 or similar hashes.
📚Git
Every commit and file is named by a hash of its content.
💳Card numbers
The last digit is a check digit (the Luhn check) to catch typing errors.
Repair using checksums and copies
💽Copy 1checksum OK
💽Copy 2checksum BAD
💽Copy 3checksum OK
→↓copy a good block over the bad one
🔧Repairedall three match
Good Corrupt Repair
One copy is found bad by its checksum, so the system copies a good one over it.

12Related Topics to Read Next

TCP vs UDP→

TCP and UDP both put a checksum in each segment.

OSI Model→

Checksums and CRCs appear at several layers.

HTTP / HTTPS→

TLS adds strong integrity checks to protect against tampering.

Reliability→

Detecting corrupt data is part of a reliable system.

Consistent Hashing→

Another use of hash functions, to place data on servers.

IP Address→

The IPv4 header has its own checksum.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔Checksum: a small fingerprint of data. Changes when the data changes.
  • ✔Flow: sender calculates and sends. Receiver recalculates and compares.
  • ✔Detects errors. Does not fix them. For fixing, use ECC or another copy.
  • ✔CRC32: fast, for accidents (network, ZIP, storage).
  • ✔SHA-256: for security and downloads. MD5 and SHA-1 are broken for security.
  • ✔Order matters: a plain sum misses swapped bytes. Better checksums catch that.
  • ✔Protect the checksum itself, or an attacker will change both.
  • ✔One line: “A checksum is a tiny number you compare to know your data did not change.”
← Previous
Proxy vs Reverse Proxy
Next →
HTTP/1.1 vs HTTP/2 vs HTTP/3