Why do QR codes still scan when partially damaged, and what does it reveal about error correction? This educational explainer walks through the logic with clear examples anyone can follow.
Chapters 7
Transcript
Here's a QR code — version one, twenty-one squares by twenty-one. Smudge a couple of its cells and it still scans fine. Smudge seven, and it fails completely. So why does damage not stop a QR code?
A QR code is a journey written on a map. The message is the itinerary; the data cells are the landmarks along the way. Parity cells add extra landmarks, ones the journey doesn't strictly need. Damage is a smudge across the route.
The scanner compares the route against those extra landmarks, finds exactly where the smudge falls, and redraws just that leg. Levels L, M, Q and H set how big the damage budget is. Encoding starts with the message itself: ten data cells, D1 through D10, each carrying one piece of what you actually want to send. Then four more cells are appended — the parity cells, P1 to P4.
They add no new destination. Each one is computed from the data, so together they act as its fingerprint. The rule is simple: twice the number of cells you can repair must not exceed the parity symbols. Twice t is at most four, so t equals two.
That means two damaged cells can be repaired even when you don't know which ones they are. And if you already know where the damage sits, those same four parity cells rebuild four. Picture a route with ten itinerary stops and four landmark checks that no other combination of stops could reproduce. The parity cells add no stop; they make the route check itself.
Now the scanner does the real work. It reads the ten data cells and recomputes the four parity values from them, then compares that with the four parity cells stored in the code. Every mismatch is called a syndrome. Four syndromes are enough to solve for up to two wrong cells — where they are, and what they should have been.
Here, cells three and seven disagree, so the scanner flips them back to their correct values. That isn't luck; it's a designed budget. Level L recovers about seven percent of codewords, M about fifteen, Q about twenty-five, H about thirty. And interleaving spreads one long scratch across many codewords, so each one carries only a single error — well inside the budget.
Parity isn't a spare copy — it's enough structure to find and undo the damage. Both red cells flip back to black, and the message is unchanged. Here is one full case, with numbers small enough to check. Ten data cells sit in a row, and four parity cells sit beside them.
Four parity cells means 2t equals 4, so t equals 2 — two errors can be repaired. Now damage smudges cell 3 and cell 7. The decoder recomputes parity and gets four syndromes, two of them nonzero. It tries candidate pairs of positions.
Only 3 and 7 fit the syndrome pattern, and solving for those two wrong values comes out clean. So it repairs them and decodes the message exactly. Now push it: smudge a third cell. The syndromes now fit no two-error pattern at all, so the scanner refuses to guess.
Though if the damage's positions were known in advance, the budget would double — four known erasures for four parity cells. Here's the whole flow: data cells carry the message, and parity cells watch over them. Damage strikes, syndromes locate it, repair fixes it. The rule: four parity cells correct two unknown errors, and levels L, M, Q, H raise that budget to roughly seven, fifteen, twenty-five, thirty percent.
A QR code survives damage because it carries enough structure to find the flaw — not because it kept a spare copy.
Still stuck on part of this?
Ask for a video on exactly the bit you need. Your first 2 are free.
Animated by Proverbit, planned with AI · Pictures: Qr-1.svg — Autopilot, adapted, CC BY-SA 3.0