Home / Software y Cloud / How much damage can a QR code take? Up to 30%, thanks to Reed-Solomon

How much damage can a QR code take? Up to 30%, thanks to Reed-Solomon

The QR code in your pocket has spent the night crumpled, taken a scratch from your keys, and a coffee stain has decided to settle right on one corner. Even so, at the supermarket checkout it scans on the first attempt. That is not luck: a QR code carries a copy of itself, written in mathematical code, that lets it rebuild whatever is lost. That mathematics is called a Reed–Solomon code, an error-correction system that tolerates up to 30% of the symbol’s surface being damaged and still decodes. This is the story of that grid: how it is built, and why it is so hard to kill.

A barcode that learns to read in two dimensions

In 1994, engineer Masahiro Hara worked at Denso Wave, a Toyota group subsidiary, and was tired of classic barcodes: one-dimensional, slow, and able to hold barely twenty characters. Legend has it the idea came to him while looking at a Go board, the Japanese game of black and white stones. What if information were organised as a two-dimensional grid instead of a strip of bars?

The result was the QR code, short for Quick Response, standardised as ISO/IEC 18004. A QR code is not an image format: it is a matrix symbol, a lattice of black and white square modules that encode bits. There are 40 versions, from 1 (21×21 modules) to 40 (177×177). Maximum capacity is about 7,089 numeric characters, 4,296 alphanumeric characters or 2,953 bytes —a JPEG image fits— depending on the encoding mode used: numeric, alphanumeric, byte (binary data) or Kanji.

The anatomy of the grid

The first thing you notice are the three large squares in the corners, the finder patterns. They carry no information: they are beacons that tell the camera where the code is, with what orientation and at what scale, even if the photo is taken crooked. Without them, the decoder does not know where to start.

The rest of the grid is split between two kinds of modules: data (the information, turned into bits) and error correction (the mathematical backup copy). There are also supporting pieces: timing patterns (a dotted line between the finders that marks the grid), alignment patterns for large versions, and a quiet zone of four modules around the whole symbol, the mandatory margin that separates the code from the rest of the world.

Reed–Solomon: the mathematics that repeats just in case

Here is where it gets serious. The Reed–Solomon code, invented in 1960 by Irving Reed and Gustave Solomon, turns a block of data into a polynomial: it treats the message bytes as coefficients of a polynomial and evaluates it at additional points. Those extra values are the parity symbols, and the whole calculation happens in a Galois field GF(256), a finite set of 256 elements with its own addition and multiplication rules, where each symbol fits in one byte (8 bits).

The magic property is this: if symbols are lost or corrupted during transmission, the receiver builds equations called syndromes and solves them to figure out which positions failed and what their correct value was. With 2t parity symbols you can correct t errors (both position and value), and twice as many if the damage only erases symbols —the so-called erasures— because then the position is already known.

The correction level is configurable: QR codes offer four levels, L, M, Q and H, which set aside 7%, 15%, 25% or 30% of the symbols as parity. Level H, used on parcel labels and payments, is the one that survives losing almost a third of the image. That is exactly why the scratched code keeps working: the coffee stain does not destroy the information, it only erases part of a redundant copy.

Why damage gets spread out: interleaving

If the data were stored in a single contiguous block, a stain wiping out 10% of the surface could destroy an entire block, and correction would blow up. That is why the standard interleaves the data: it splits it into several blocks, each with its own Reed–Solomon code, and mixes the symbols of all of them across the grid. The result is that localised damage hits many blocks a little instead of one block a lot, and every block has spare parity to fix its share.

Masks and formats: information about the information

Modules are not placed as-is: the standard applies one of eight possible masks, an XOR pattern that flips some modules to avoid large same-colour areas that would confuse the reader with the finder patterns. The reader needs to know which mask was used and which correction level: that information lives in the format information area, 15 bits protected by another correcting code, BCH(15,5), which survives up to 3 errors out of 15. Large versions add a version information block protected by BCH(18,6).

All of this, in milliseconds

When you point the camera, the decoder does, in order: locate the three finder patterns, estimate the module grid (including perspective distortion), read the format information, undo the mask, extract the data and parity symbols, deinterleave them, apply Reed–Solomon correction, and finally interpret the bits according to the encoding mode to get the original bytes. On a modern phone, under 100 milliseconds. The name Quick Response was not empty marketing.

The same mathematics, everywhere

Reed–Solomon does not only live in QR codes: it is the error correction of CDs, DVDs and Blu-rays, of the RAID 6 arrays that protect server disks —the same Galois field family we discussed a few days ago when explaining why a file survives a dead disk—, of digital television, and of communications with the Voyager probes. And none of this had to happen: Denso Wave held the patent but chose not to enforce it, and that is why Hara’s grid is on the menu of every restaurant on the planet.

The weak spot: the code you cannot see

Damage tolerance has its downside. Because a QR code is opaque —a blotch of pixels that only reveals itself as a URL once decoded— nobody knows where it leads until they scan it, a perfect advantage for quishing, QR phishing: fake stickers placed over legitimate codes, malicious codes on leaflets and forms. And the error correction that rescues scratched codes also lets an attacker overlay their own message on an existing QR without destroying it completely. The practical lesson is simple: do not scan the code you cannot see.

Next time a stained, scratched QR lets you pay without a hitch, you know who to thank: a polynomial over a Galois field, invented in 1960, that is still buying your coffee in 2026.