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

1 See

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?

2 Change
  • Damage sizenone → 40% of the code

Presets Torn cornerCoffee stainLogo in the center · HScratched finder

Model · clean, flat camera image

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.

See how the world works.

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.

Find your next rabbit hole

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.

All Originals

Follow your curiosity

A collection of small doors into big ideas.

Format

Subject

Topic

Sort by

Rankings count activity here on ExplainerTools. Newest means added to this collection.

Loading collection…

Opening the collection…

Make something click.

Made an explainer, or found one you love? Give it a place in the collection.

Your next question

What do you wish someone would explain?

Send one question. If it becomes an ExplainerTools Original, you can hear when it is ready.

One weekly email with new explainers. We send a confirmation link first, and you can unsubscribe at any time.

We save your question, your email if you add one, and whether you asked to subscribe. Privacy

Share something worth understanding.

An interactive demo, an interactive article, or an educational video. Every suggestion is reviewed before it joins the collection.

Submit the creator’s original link. We credit creators and link to their work.

A collection for the curious.

ExplainerTools collects interactive explainers, visual essays, and educational videos that help an idea make sense. Browse by subject, follow a topic, or find a creator whose way of explaining speaks to you.

The work belongs to its creators.

Every entry credits its original creator. Supported experiences play here, with a link to the creator’s original work available in the player. Inclusion does not imply a partnership or endorsement.

How rankings work

Views, likes, and bookmarks count activity on ExplainerTools. They don’t include views or likes from a creator’s website or social accounts. Newest means most recently added to this collection. Ties are ordered by date added, then our curated catalog order.

Your collection

New likes and bookmarks require a free account and sync across devices when sign-in is available. Previously saved items from this browser may remain visible here.

Browse the catalog data or read about privacy.