● A free public tool  ·  Built by Poptani Labs  ·  No sign-up  ·  Your data never leaves your browser
Built in the Lab · 5-minute read

How a QR code survives scratches, smudges and a bad camera angle

You point your phone at a restaurant table, a parcel, or a poster, and in under a second a website opens. Nothing about that feels remarkable anymore, which is a shame, because the little square you just scanned is doing several clever things at once: finding itself in the image, correcting its own tilt, repairing damaged parts of itself, and decoding a message — all from a pattern of black and white squares that was invented to track car parts. This is a research-based explainer, not a hands-on teardown: the design is public, standardised, and well documented, so we can walk through exactly how it works.

It started with car parts, not menus

The QR code — short for Quick Response code — was invented in 1994 at Denso Wave, a Japanese automotive-parts company, by a team led by engineer Masahiro Hara. The factory problem was simple: one-dimensional barcodes hold only about 20 characters, so workers had to scan several barcodes per box, all day, and a scratched or oil-stained label could stop the line. Hara's team wanted a code that held far more data, could be read from any angle, and would survive the grime of a factory floor. The design they produced was standardised internationally in 2000 as ISO/IEC 18004 — and the code went on to spread everywhere instead of staying a factory tool.

Anatomy of a square

Every QR code is a grid of modules — the black and white squares, each one a single bit, dark for 1 and light for 0. The three large squares in three of the corners are finder patterns, and they are the reason your phone locks on so fast. Hara's team searched printed material for a black-to-white ratio that almost never occurs by accident and settled on 1:1:3:1:1; that ratio, read in any direction, tells the scanner "this is a QR code, this is its orientation, and this is its scale". A smaller alignment pattern near the fourth corner helps with distortion when the code is printed on a curve or photographed at an angle, and a row of alternating modules between the finders acts as a timing pattern so the scanner can count the grid.

The data itself is packed in a zigzag that snakes up and down the grid starting from the bottom-right corner, after the encoder applies one of eight mask patterns to break up large blocks of same-coloured squares that would confuse a camera. Codes come in 40 sizes, called versions: version 1 is a 21 by 21 grid, and each version adds four modules per side up to version 40 at 177 by 177. At the lowest error-correction level, a version 40 code can store up to 7,089 digits, 4,296 alphanumeric characters, or 2,953 bytes of data. Most codes you scan are far smaller, which is why they look sparse and clean.

The space-age trick: error correction

The real magic is Reed–Solomon error correction, a technique developed in 1960 by Irving Reed and Gustave Solomon at MIT's Lincoln Laboratory for reconstructing messages damaged in satellite communications — NASA used it on the Voyager probes, whose signals crossed billions of kilometres. The idea is simple to state and hard to do: the encoder generates extra backup bytes from the original message using polynomial mathematics, and weaves them into the grid alongside the data. When the scanner reads the code, it checks the maths; if squares are missing or misread, it uses the backup bytes to reconstruct them.

The QR standard defines four levels. Level L recovers about 7% of corrupted codewords, M about 15%, Q about 25%, and H about 30%. That is why a code with a logo stamped in the middle still scans: the designer chose a high error-correction level and sacrificed the centre squares, knowing the maths would rebuild them. It is also why a torn poster or a rain-spotted label often still works, and why a code photographed at a drunken angle usually does not need a second try. More error correction means less room for data in the same grid, so designers trade capacity against toughness — a menu code can afford level H, a dense industrial label may not.

Fun anecdote: the code's look came from a board game. Hara's team was inspired by the black and white stones on a Go board, and the search for the finder pattern's ratio involved scanning newspapers, magazines, and other printed matter for a sequence that almost never appeared by chance. A factory tracking tool, designed by studying Go stones and newsprint, now opens menus, tickets, payments, and boarding passes — a career change few inventions manage.

Under the Hood

A QR code works because it was designed for the worst case, not the best: a dirty label, read at an angle, in a hurry, by a cheap camera. Finder patterns locate it, timing patterns measure it, masks keep it readable, and Reed–Solomon maths repairs it. The next time a code scans despite a coffee stain or a logo in the middle, that is not luck. It is 1960s space-communications mathematics, doing a factory job, in your pocket.

Related on Poptani Labs: How a website actually works: from typed address to page on your screen, How a steel box rewired the world, PDF tools. More in this category: Built in the Lab.

Sources: Wikipedia, QR code; TechSpot, QR codes explained; GoTo.now, QR codes: history, structure and how they work

← All posts