Inside the QR code
The checkerboard squares you scan every day have a 200-year backstory, a clever mathematical heart, and a security problem hiding in plain sight. Five short modules; no maths beyond arithmetic.
From Morse to the barcode
Every QR code is the descendant of a telegraph wire. The story starts with a letter that arrived too late.
A letter that arrived too late
By 1836, working with Joseph Henry and Alfred Vail, Morse had a telegraph that needed only a single circuit; the price of that simplicity was a cleverer code. Short and long pulses; dots and dashes.
The first data compression
E = · T = –
Morse code turned language into a stream of two symbols. Hold that thought; it never goes away.
Morse code, drawn in the sand
The UPC barcode that grew from that moment stores just 12 digits, read by scanning a laser across the stripes; thin and thick, dot and dash, zero and one.
Build a real barcode
The 12th digit is not yours to choose. It is computed from the other eleven: triple the digits in the odd positions, add the rest, and the check digit tops the total up to a multiple of ten. Damage any single digit and the sum snitches.
Twelve digits was never going to be enough
What a barcode says
"I am product number 93573200016 4." That is the entire message. A pointer into somebody's database, nothing more.
What people wanted to say
Where was this made? When? Which batch? Which paddock did this beef come from? Twelve digits cannot carry a story.
The pressure builds
Through the 1980s and 90s, industry after industry hit the same wall: the code was full. Something had to grow.
And in the 1980s, a crisis in British paddocks made the question urgent.
The two-dimensional leap
It took a disease outbreak, a frustrated factory engineer and a board game to push the barcode into two dimensions.
Mad cows and missing data
Inventors tried stacking barcodes on top of each other, like Code 49 and its descendant PDF417, still found on airline boarding passes. Better, but still a bookshelf of one-dimensional codes. The real answer was a true two-dimensional grid.
A factory problem and a game of Go
As told by Masahiro Hara in interview (Veritasium, October 2024).
How much can the grid hold?
Forty sizes, each adding four modules per side. Version 40 holds close to three kilobytes; one programmer famously squeezed a playable game of Snake into a single code. Your phone works out the version by counting the modules.
Capacities: DENSO Wave, qrcode.com (byte mode, level M approximate).
Slow burn, then everywhere
Anatomy of a QR code
Every module in the grid has a job. The code on the next screen is real; it encodes this website's address, and your phone will read it straight off the screen.
Tap each part to light it up
Turning letters into squares
The first few squares of every QR code declare the data type (numbers only, letters and numbers, bytes, or kanji) and the message length; then the message itself follows, byte after byte.
Watch the data pour in
Data enters at the bottom right corner and zigzags upward in two-column ribbons, snaking around the fixed patterns, all the way to the top left.
359 data modules will fill in true placement order.
Now scan it
Half of what you just watched fill in is not the message at all. The rest of the grid is something stranger; that is module 04.
Unkillable codes
Tear a corner off a QR code and it still scans. That is not luck; it is some of the most elegant mathematics in daily use.
The trick: keep valid messages far apart
Suppose the only two valid messages are 000 and 111, opposite corners of a cube. Flip any single bit in transit and you land on a corner that is not a valid message; the error announces itself, and the nearest valid corner is almost certainly what was meant.
Reed-Solomon: redundancy with a brain
before sending, add a few extra numbers computed so the whole message satisfies equations the receiver knows; if the equations fail on arrival, the pattern of failure reveals where the damage is and what the missing values were.
Reed-Solomon codes (1960) recover scratched CDs and DVDs, and still pull Voyager's fading whisper out of deep space, half a century after launch. QR codes carry the same mathematics in every corner shop.
In a QR code, roughly half the grid can be these recovery numbers. How much exactly is your choice.
Four levels of stubbornness
This is why designers can stamp a logo over the middle of a code and it still scans: the logo is just damage the mathematics routes around.
Restoration rates: DENSO Wave, qrcode.com, "Error correction feature".
Try to kill it
Click or drag on the code to paint damage, then test it with your own phone camera. This code uses level M; in theory it should survive until roughly 15% of it is gone.
Damage to the three big position squares hurts far more than damage to the data region; the recovery maths cannot protect the parts that tell the camera where the code is.
Eight disguises, one message
Raw data can bunch into blank patches that confuse scanners, so the standard defines eight masking patterns that flip pixels in fixed ways. A generator scores all eight for awkward patches and publishes the least awkward one; the winner's number rides along in the format strip.
This is why two generators can hand you different-looking codes for the same link.
The dark side of the squares
Everything that makes QR codes brilliant for machines makes them opaque to people. Scammers noticed.
The core problem: you cannot read it
Security folk call QR phishing "quishing". The attack is usually not technical at all; it is a sticker.
Three ways the trick is played
The sticker
A scam code printed on adhesive paper, stuck squarely over the real one; on a parking meter, a menu, a charging station. The equipment looks official because it is; only the sticker is new.
The letterbox drop
Fake fines, missed-delivery cards and "update your details" letters carrying a QR code. Paper feels trustworthy, and the code hides the destination.
The borrowed brand
A scam page dressed as a bank, toll operator or government agency, reached through a code in an email or poster. The page can look pixel-perfect; the address gives it away.
Your one defence sits in the address preview your phone shows before it opens anything. Let's train on it.
Check before you tap
Your camera shows a preview of where each code leads. Trust it or not? All addresses below are invented for this exercise.
Habits that beat the sticker
Preview, then read backwards
Always look at the address your camera shows before opening, and read the domain from the end. The true owner is just before the first single slash.
Feel the surface
On parking meters, menus and public posters, a code on a sticker over another code is a red flag you can literally feel. Unexpected codes in letters and emails deserve the same suspicion as unexpected links.
Never pay through a scanned code
For fines, tolls, banking and anything with your card details, close the browser and go in the front door: the official app, or an address you type yourself.
Why this matters
Built on: Veritasium, "I built a QR code with my bare hands to see how it works" (October 2024), including Masahiro Hara interview material; DENSO Wave, qrcode.com ("Error correction feature"; "Information capacity and versions of QR Code"); ISO/IEC 18004 (QR code standard). The QR codes on these pages were generated for this walkthrough and encode ntworldink.com.