CERAMICO Instagram

Technology · How it works

The code that carries spares: why a damaged QR code can still scan

Every QR code is printed with extra bytes worked out from its own message. Here is how those spares rebuild what a smudge wipes out, and why the three corners matter so much.

The Code That Carries Spares: cover frame from the CERAMICO filmWatch the film · 1:05

A QR code with a coffee ring across its middle looks like a lost cause. Point a phone at it anyway. It may well scan.

That is not luck. It is a design decision made decades ago and printed into every code since. DENSO WAVE, which announced the QR Code in 1994 (it was then a division of DENSO CORPORATION), puts it plainly: “Even if a QR Code is partly smeared or damaged, it has the capacity to correct itself and restore the original data.”

The important word there is “partly.” In our film, a clay hand chips a small chunk out of the middle of a glazed QR mosaic, and a clay phone still reads it. The size of that chunk, and where it falls, are the whole story. To understand both, you have to follow the code from the moment a phone first spots it to the moment it rebuilds what is missing.

By the numbers

QR Code released by DENSO WAVE
1994
Error correction levels
4 L, M, Q and H
Level L restores
about 7% of codewords
Level M (most often chosen) restores
about 15% of codewords
Level H (strongest) restores
about 30% of codewords
One codeword
8 bits
Corner pattern ratio
1:1:3:1:1 black and white widths

Recovery rates are DENSO WAVE’s approximate figures, expressed as a share of all codewords, spares included. DENSO WAVE notes that restoration may not be complete, depending on the damage.

First, find the code

Before a phone can repair anything, it has to know there is a code in view, and which way up it is. That job belongs to the three big squares in the corners. DENSO WAVE calls them position detection patterns, and says they let a reader pick up the symbol from any direction, through a full 360 degrees.

Their design came from an unusually patient piece of fieldwork. According to DENSO WAVE’s history of the code, its development team, just two people, ran an exhaustive survey of the ratio of white to black areas in pictures and symbols printed on fliers, magazines, cardboard boxes and the like. They were hunting for a pattern that almost nothing else used. In DENSO WAVE’s words, “they came up with the least used ratio of black and white areas on printed matter.”

That ratio is 1:1:3:1:1. Draw a line straight through the middle of one of the corner squares and you cross a band of black, a band of white, a thick block of black three times as wide, then white and black again, in exactly those proportions. A camera sweeping across a busy poster is looking for that rhythm, the rarest one the team could find on the page.

The film · 1:05

The Code That Carries Spares

A clay QR mosaic on a café wall loses a chunk from its middle and still scans, because it was made with its own repair kit.

Watch more on Instagram Follow CERAMICO

Read the transcript

Chip a small chunk off a QR code, and it can still scan. Its creator, DENSO WAVE, says the strongest level can rebuild up to 30% of the bytes. The trick: it carries its own repair kit. First, your phone has to find it, using the three big corner squares. Their inventors picked those stripes after surveying flyers, magazines and boxes for the rarest ratio. Inside, your message is stored as bytes, drawn as black and white squares. When it's made, extra bytes are worked out from the message, using Reed-Solomon math. It's the same family of math used on music CDs, and by Voyager 2 at Uranus. In DENSO WAVE's own example, half of all the bytes are spares. So when a smudge or a tear wipes out some of the bytes, your phone does the math, and rebuilds the missing pieces with help from the spares. So go on, chip a small chunk off. Just leave the three corners alone.

Animated model, illustrative and not to scale.

Spares, worked out in advance

Inside those corners, your message is stored as bytes. DENSO WAVE calls each one a codeword, and one codeword of QR Code is 8 bits. Each is drawn as a little cluster of black and white squares, and because a QR code is two-dimensional, information runs both across and up and down.

The clever part happens when the code is made, not when it is read. Before a single square is printed, the generator works out extra bytes from the message itself. DENSO WAVE: “The QR Code error correction feature is implemented by adding a Reed-Solomon Code to the original data.”

Reed-Solomon is a family of error-correcting codes with a long working life. DENSO WAVE notes that it is used for music CDs. It also went to the outer solar system: a 1986 NASA account of Voyager 2 at Uranus reports that “Reed-Solomon onboard encoding was used” instead of Golay coding, and a JPL engineering summary says the spacecraft carried an experimental Reed-Solomon encoder expressly for the greater distances of the Uranus and Neptune phase. Voyager 2 flew past Uranus on 24 January 1986. CDs, Voyager and QR codes each tune the math differently, which is why “family” is the honest word.

How many spares does a code carry? DENSO WAVE gives a worked example. Take 100 codewords of message and decide you want to be able to fix 50 of them. Reed-Solomon needs twice as many extra codewords as the number to be corrected, so you add 100. The finished code holds 200 codewords, and half of them are spares.

Here is the twist hiding in that example: half spares does not mean half can be lost. Only 50 of the 200 codewords can be corrected, which DENSO WAVE puts at 25 percent of the total. That is error correction Level Q.

How much damage is too much

Level Q is one of four. DENSO WAVE’s table gives approximate recovery rates of 7 percent for Level L, 15 percent for Level M, 25 percent for Level Q and 30 percent for Level H. More spares buy more protection, but they take up room that could otherwise hold message. DENSO WAVE says that “Typically, Level M (15%) is most frequently selected.”

So when DENSO WAVE says that “A maximum 30% of codewords” can be restored, that maximum belongs to the strongest level only. A typical code in the wild can recover about half that, and a Level L code much less. Even at the top level, DENSO WAVE adds a caveat: restoration may not be fully performed, depending on the amount of dirt or damage.

Those percentages are a share of all the codewords, spares included, and DENSO WAVE explains why. A smudge does not politely avoid the spares and land only on the message. Any byte can be the one that is lost. So when a phone reads a damaged code, it does not simply swap in a backup copy. It does the math across every byte that survived, message and spares together, working out which bytes are wrong and what they should have been. The spares are not duplicates. They are clues, computed from the message, that make the missing pieces solvable.

That is also why DENSO WAVE is wary of a popular trick: dropping a logo or illustration over the middle of a code. Its FAQ warns that doing so can leave so little margin that “even a tiny missing or smeared part renders the reading operation impossible,” and asks people to consult the company first.

The spares are not duplicates. They are clues, computed from the message, that make the missing pieces solvable.

Leave the corners alone

Our film ends with a piece of advice: chip a small chunk off, but leave the three corners alone. We should be clear that this is our inference, not a DENSO WAVE rule. It follows from how the parts divide their labor. Error correction restores codewords in the data area. The corner squares are how a reader finds the symbol in the first place. Damage the data and the spares can step in. Damage the finder and the phone may never realize there is anything to repair.

It is not an absolute, either. A US patent from Fujian Landi, with a 2015 priority date, describes a decoding method for a QR code with one damaged position detection pattern, so some readers can cope with a single bruised corner. And the corners are not the only fixed parts that matter. The strips of format information beside them, and the timing and alignment patterns, help a reader make sense of the grid too. That is why “small” matters as much as “chunk.”

None of this is hidden. DENSO WAVE kept its patent rights to the code but declared that it would not exercise them, and the symbol is an international standard, ISO/IEC 18004. The repair kit has been sitting in plain sight on menus, posters and parcels for three decades. You just have to know to look for the spares.

Sources

Every line in the film was checked against these sources by an independent fact-checker before publication. Company claims are attributed to the company that made them.

  1. DENSO WAVE: What is a QR Code?
  2. DENSO WAVE: Error correction feature
  3. DENSO WAVE: Error correction level table (image)
  4. DENSO WAVE: Dirt and damage resistant
  5. DENSO WAVE: Readable from any direction in 360°
  6. DENSO WAVE: History of QR Code
  7. DENSO WAVE: QR Code standardization
  8. DENSO WAVE: FAQ
  9. NASA NTRS: Catching the whispers from Uranus (Bartok, JPL, 1986)
  10. JPL DESCANSO: Voyager telecommunications
  11. Google Patents: US 10,438,038, decoding a QR code with one damaged position detection pattern

Updates and corrections

  • First published.

See an error? Tell us. We correct promptly and say what changed. Our corrections policy.

Disclosure

This is an independent explainer. CERAMICO is not affiliated with, sponsored by, or speaking for any company, brand, agency or person named in this story, and nothing here is official.

Claims are attributed. Where a figure or description comes from a company or an expert, we say so. QR Code is registered trademark of DENSO WAVE INCORPORATED. CERAMICO is not affiliated with, or endorsed by, DENSO WAVE. The animation is an illustrative model, not to scale.

Animations are illustrative. Our films use clay-style 3D models. They are not to scale and are simplified to show how something works.

Trademarks and product names belong to their owners and are used only to identify what we are describing.