The QR code on a parking sign is scuffed, and one corner has torn away. You point your phone at it anyway, and the link appears. The code didn't get lucky. It was built expecting damage. Part of every QR code is backup, made from your link, that can rebuild what's missing.

Why does a torn QR code still scan? · 33-second film · Watch with transcript

Try it yourself in QR Repair Lab: drag the tear bigger and watch the decoder rebuild the missing squares, until one block runs out of backup.

What are all those little squares?

A QR code is a grid of dark and light squares. Most of them are bits, 1s and 0s. Groups of eight bits make the code's building blocks, called codewords. Project Nayuki: Creating a QR Code step by step.

Not all the squares carry your link. Take the code in QR Repair Lab, which holds https://explainertools.com at the strongest setting. It's 33 squares on a side, 1,089 in all. Only about 19% of them hold the link. About 47% are backup. Most of the rest are patterns that help the camera find and read the grid.

How can backup rebuild what's missing?

The backup uses Reed–Solomon codes, developed in 1960 by Irving Reed and Gustave Solomon. The same family of codes protects CDs, DVDs and Blu-ray discs. It also encoded the pictures that Voyager sent back from space. Wikipedia: Reed–Solomon error correction.

Here is the idea. Picture your data as points that pin down a smooth curve. The backup is extra points on the same curve. Lose a few, and the survivors still fix the curve, so the lost points can be rebuilt. The real math uses a special arithmetic on bytes, but the idea is the same.

There's a cost. A scanner doesn't know which codewords are damaged. Finding and fixing one bad codeword takes two codewords of backup. Our code is split into 4 blocks. Each has 16 backup codewords, so it can fix up to 8 of its 25.

How much of a QR code can you lose?

QR codes come with four levels of error correction. Level L can restore about 7% of the codewords, M about 15%, Q about 25% and H about 30%. More backup makes the code bigger for the same link. DENSO WAVE: Error correction feature.

Those percentages count codewords, not area. Each codeword is a little cluster of eight squares, so one tear can clip many codewords at once. In our film, the tear covers 20% of the code's area but damages 28 of its 100 codewords. The worst block is right at its limit of 8.

The code spreads the risk. Its blocks are interleaved, so neighboring codewords belong to different blocks. That makes it less likely that one patch of damage overwhelms any single block. It's also why a logo printed over the center can still scan: the logo is damage the backup repairs. Wikipedia: QR code.

Why can't you cover the three big squares?

Masahiro Hara's team at Denso Wave, a Japanese company, invented QR codes in 1994 to track car parts. The team wanted a code a camera could read fast, at any angle. So they added three big squares in the corners, called finder patterns. They tell the camera where the code is and which way it's turned.

Each finder has dark and light bands in the ratio 1:1:3:1:1. They picked it because it was the ratio least used on printed matter, so it stands out. DENSO WAVE: History of QR Code.

The backup only protects codewords. If a finder is gone, the scanner may never find the grid. Then the backup never gets a chance.

What does the model leave out?

QR Repair Lab builds a real code, following the QR code standard, ISO/IEC 18004. It reads the code with a real decoder, the open-source jsQR library. But its camera image is perfect: a clean, flat card, evenly lit, at about 7 pixels per square. Real scans add more trouble:

Phone scanners also differ. Some recover more than jsQR, for example with smarter ways to locate a damaged code. Some recover less. Right at a block's limit, the tool's damage count and the decoder can disagree by a codeword or two. We also changed one jsQR rule for finding the small alignment square, and the tool's notes explain why.

Can a sticky note break a QR code?

You need a printed QR code you trust, like one on a box in your pantry, and a few sticky notes. These steps are a suggestion, so adapt them to the child beside you.

Predict. Cut a sticky note into small squares. Ask your child which spot will break the code fastest: the middle, an edge or one of the big corner squares.

Try. Cover one spot at a time, and scan with a phone camera. Start with a small patch in the middle, then make it bigger. Then cover one corner square.

Explain. A small patch in the middle often still scans, because the backup rebuilds what's missing. Hide a corner square, and many scanners can't find the code at all. Results vary with the phone and the code's level, so yours may differ. That's worth a second look in QR Repair Lab.

Back in QR Repair Lab, tap level L under error correction. The same link now fits in a 25-by-25 grid. Then drag the tear bigger until the code fails. Predict first: how much smaller is that tear than the one level H survives?

QR Repair Lab is an ExplainerTools Original. Its decoder is jsQR, by Cosmo Wolfe and contributors.

Keep exploring

Up next

  1. InteractiveQR Repair LabChange the same thing yourself.Try it yourself
  2. 0:34Short · Sports and motionHow do you throw a perfect spiral?
  3. 0:34Short · SkyWhy does Mars seem to move backward?

Sources & further reading

Make the next question an experiment.

Browse independent creators who make big ideas visible.

Find an explainer