Computer Science · Interactive demo
Why does a torn QR code still scan?
Tear, stain and scratch a real QR code and watch a real decoder still read it. Error correction you can break with your own hands.
Created by ExplainerTools.
About this explainer
- Made by
- ExplainerTools
- Format
- Interactive demo
- Subject
- Computer Science
- Where it runs
- Plays here
- Full tool
- Open the tool page
- Published
- Added to collection
- QR codes
- error correction
- Reed-Solomon
- codes
How the model works
A QR code can lose a whole chunk and still work. Which of its squares are your link, and which are there in case something goes wrong?
- Damage sizenone → 40% of the code
Presets Torn cornerCoffee stainLogo in the center · HScratched finder
A real QR encoder and the jsQR decoder on a clean, flat camera image. Real cameras add blur, glare and perspective.
Model notes and sources
A real encoder. The code is generated on this page, following ISO/IEC 18004 in byte mode: a 4-bit mode indicator, an 8-bit length, the UTF-8 bytes of the link, a terminator and the pad bytes 0xEC and 0x11 fill the data codewords (8-bit bytes). These are split into blocks, and each block gets Reed–Solomon error-correction codewords computed over GF(256) (field polynomial x⁸ + x⁴ + x³ + x² + 1, generator (x − α⁰)(x − α¹)…). The blocks are interleaved and placed in two-square-wide columns that zigzag up and down from the bottom-right corner, data first and then error correction, which is why the backup fills the left two-thirds. One of eight masks is chosen with the standard’s four penalty rules, and the format information is BCH-coded. Because the tool builds the code itself, it knows every square’s job.
This code. https://explainertools.com is 26 bytes. At level H it needs version 4, 33 × 33 squares: 100 codewords, 36 data and 64 error correction, in 4 blocks of 25 (9 data + 16 error correction). A Reed–Solomon block with 2t check codewords can fix up to t wrong codewords when the decoder doesn’t know where the damage is, so each block here fixes 8 of its 25. Of the 1,089 squares, 19% carry the link, 47% are error correction, 26% are function patterns (the three finder patterns and their separators, the timing patterns, the alignment pattern and the format information), and 8% are the mode and length header, padding and 7 spare bits. Levels L, M, Q and H restore about 7%, 15%, 25% and 30% of the codewords. A lower level fits the same link into a smaller code: version 2 at L and M, version 3 at Q.
A real decoder. Damage is drawn onto the printed card: a torn corner (the knob sets the share of the code’s area torn away; the margin goes with it), an opaque dried-coffee stain, a printed logo, or scratches that scrape the ink off. The phone shows the exact camera image that is decoded: the card at 288 px, about 7 px per square, on a dark table. It goes to jsQR 1.4.0 (Apache-2.0), and jsQR’s answer sets ✓ or ✗. We changed one jsQR heuristic: it now accepts an alignment pattern only within 2 squares of where the three finder patterns predict it, and otherwise uses that prediction, as it already did when it found none. Unchanged, it locks onto a random data pattern whenever a tear removes the real alignment pattern, and fails even with only a few codewords damaged. “Codewords damaged” counts the codewords with at least one square that jsQR’s own binarizer now reads as the wrong color. Right at a block’s limit, the count and the decoder can disagree by a codeword or two, because the decoder samples a few edge squares slightly differently.
Not modeled. Blur, glare, perspective, curved or crumpled paper, low light and printing defects. Phone scanners differ: some recover more (for example with smarter location or erasure decoding) and some less. In the film, the tear covers 20% of the code’s area and damages 28 of its 100 codewords; the worst block is at its limit of 8.
Sources: Denso Wave, QR code error correction feature; QR code (Wikipedia); Reed–Solomon error correction (Wikipedia); Project Nayuki, Creating a QR Code step by step; ISO/IEC 18004:2015, QR Code bar code symbology specification; jsQR by Cosmo Wolfe and contributors.
An ExplainerTools Original.
Watch it move
- Why does a torn QR code still scan?33-second Short
- Why does a torn QR code still scan? Error correction, explained70-second narrated film
Go deeper
Explore interactive ideas in space, science, math, and more. Try a demo, read an interactive article, watch a short video, and follow what makes you curious.
New Originals
Change one thing and see why.
The three newest models, each with a short film. Watch the question, then play with the answer.
Follow your curiosity
A collection of small doors into big ideas.
Format
Swipe or scroll for more formats →
Subject
Swipe or scroll for more subjects →
Topic
Swipe or scroll for more topics →
Sort by
Rankings count activity here on ExplainerTools. Newest means added to this collection.
Loading collection…
Make something click.
Made an explainer, or found one you love? Give it a place in the collection.


