How QR Codes Work: Why Even a Torn QR Code Still Scans
Why does a torn, tea-stained UPI QR code still scan in a second? Learn how QR codes work, from finder patterns to Reed-Solomon error correction, explained simply.
Education•Published•
Look at the QR sticker on your local chaiwala's counter. The corner is peeling and a tea stain runs across the middle, yet your phone opens the payment screen in under a second. With UPI handling 25.47 billion transactions in October 2026, many starting with exactly this kind of scan, let's see how QR codes work inside, down to the maths that repairs them.
What Is a QR Code, Really?
A QR code is a two-dimensional barcode that stores data in a square grid of black and white cells called modules, where each module is one bit: dark means 1, light means 0. Masahiro Hara created it at Denso Wave in Japan in 1994, because a normal barcode holds only about 20 characters, while the largest QR code stores up to 7,089 digits.
A shop's UPI QR usually holds just a short "upi://pay" text link with the shop's UPI ID and name, nothing more.
How QR Codes Work: The Parts of the Grid
Every QR code follows the standard ISO/IEC 18004. Sizes run from Version 1, a 21 × 21 grid, to Version 40, a 177 × 177 grid, built from the same parts.
Finder Patterns: The Three Big Squares
A line through the centre of any corner square crosses black, white, black, white and black bands in a 1:1:3:1:1 ratio. Denso Wave chose it because it almost never appears by accident in print. The ratio holds from any angle, so even a tilted code is found, and the empty fourth corner shows which way is up.
Timing and Alignment Patterns
Two dotted lines between the finder patterns, the timing patterns, work like ruler markings that tell the scanner each module's width. Bigger versions add small alignment squares that correct bending on curved surfaces.
Format Information and the Quiet Zone
Beside the finder patterns sits a 15-bit strip of format information recording the error correction level and the mask pattern. It is printed twice and protected by its own small error-correcting code. A blank border at least four modules wide, the quiet zone, marks where the code ends.
Data Area, Codewords and Masking
The rest is the data area. Bits are grouped into 8-bit codewords and placed in a zigzag path that starts at the bottom-right corner and climbs two columns at a time. The encoder then tests eight standard masks, which flip modules in fixed patterns, and keeps the one avoiding big blank patches and fake finder shapes.
What Happens in the Half-Second Your Phone Scans
When you point your camera, the app runs through a fixed sequence:
It finds the three 1:1:3:1:1 patterns and works out the code's position, size and angle.
It corrects the perspective, so a slanted code becomes a flat square.
Using the timing patterns, it samples every module as dark or light.
It reads the format information, learns the level and mask, and removes the mask.
It collects codewords along the zigzag path and sorts them back into blocks.
It runs Reed-Solomon decoding to repair damage, and only then reads the text.
Why Does a Damaged QR Code Still Scan?
Error correction is a method of adding extra, calculated data to a message so the original can be rebuilt even if part of it is lost. The smallest code, Version 1 at Level M, holds 26 codewords, but only 16 carry your data. The other 10 are backup codewords computed from those 16.
Reed-Solomon Codes in School Maths
QR codes use Reed-Solomon codes, invented in 1960 by Irving Reed and Gustave Solomon at MIT's Lincoln Laboratory.
Suppose your data is two numbers, 3 and 5. Treat them as points on a line: at x = 0 the value is 3, and at x = 1 it is 5. That line is y = 2x + 3. Now calculate two extra points on it: 7 at x = 2 and 9 at x = 3. You store all four values: 3, 5, 7 and 9.
If a tea stain wipes out any two, the remaining two still fix the same straight line, and the line gives back the lost values. Real QR codes do this with polynomials of much higher degree, using special arithmetic where every result stays between 0 and 255, so it always fits in one byte.
Errors vs Erasures: Why Location Matters
Damage comes in two kinds. An erasure is a value the scanner knows is missing, such as a torn patch. An error is a value that looks fine but is wrong, such as a module misread under glare.
Errors cost more. If 7 silently became 8, the scanner would see 3, 5, 8 and 9, notice that only three lie on one line, and fix the odd one out. But it needed both extra points to find and fix that one hidden error. Hence the key rule: each unknown error costs two backup codewords, while each known erasure costs one.
Interleaving: Spreading the Risk
Larger codes split data into blocks and spread their bytes across the grid like shuffled cards, so a torn corner takes a little from every block instead of wiping out one.
QR Code Error Correction Levels Explained
The creator picks one of four backup levels:
Level
Codewords that can be restored
Typical use
L (Low)
About 7%
Clean surfaces, lots of data
M (Medium)
About 15%
The most common everyday choice
More backup leaves less room for data. At Version 1, the same 26 codewords hold 19 data codewords at Level L but only 9 at Level H.
Why Logos Fit Inside QR Codes
A bank logo in the centre covers real modules, which the scanner treats as damage and rebuilds, though the logo spends part of the repair budget.
The logo in the centre covers real modules, and error correction quietly fills the gap.
When Even Error Correction Fails
A scan fails when damage exceeds the level's budget, when a torn finder pattern stops the code from being located, or when both format strips are unreadable.
Too much damage: once the loss goes beyond what error correction can rebuild, the scan fails.
One safety point: error correction rebuilds whatever is printed, even a fraudster's sticker pasted on top, so always check the payee name before paying.
Frequently Asked Questions
How much damage can a QR code handle?
About 7% of its codewords at Level L and up to about 30% at Level H, provided the three finder patterns and at least one copy of the format information can still be read.
Why do QR codes have three squares and not four?
Three finder patterns are enough to fix the code's position, size and angle, and the empty fourth corner tells the scanner which way the code is rotated.
What is the difference between an error and an erasure?
An erasure is data the scanner knows is missing, like a torn patch, and costs one backup codeword to fix. An error is data that is wrong without looking wrong, and costs two.
Why does Reed-Solomon work with bytes?
QR codes do their Reed-Solomon maths in a special number system with exactly 256 values, so every calculation stays between 0 and 255 and fits in one 8-bit codeword.
Can a QR code work without internet?
Yes. Decoding happens fully on your phone. You need internet only for what comes next, such as opening a website or completing a UPI payment.
Final Thoughts
The same Reed-Solomon maths keeps scratched CDs playing and carried pictures home from NASA's Voyager probes. My advice to students: redo the four-point example with your own numbers, because once you know how QR codes work, error correction in your syllabus stops feeling abstract. Share this with a classmate preparing for that exam, and explore more explainers in our Education section.