How do QR codes work?
A QR code is a small, carefully organised grid. Some squares help the scanner find and straighten the code; the rest carry your data twice over. Type below and switch the layers on and off to see which is which.
Version 0 · 0 × 0 modules · 0% of the grid carries your data and its error correction
Reading the layers
Finder patterns (orange) sit in three corners. Scan a line through any of them and you get dark–light–dark–light–dark in a 1:1:3:1:1 ratio, whatever the angle. That's how a camera finds the code in a cluttered photo and works out which way is up. The missing fourth corner tells it the orientation.
Timing patterns (blue) are two dotted lines joining the finders. They let the scanner count columns and rows even when the print is stretched or the page is curved.
Alignment patterns (green) appear from version 2 upwards. They're small bullseyes that help correct for perspective and warped surfaces. Type a longer text and watch more of them appear.
Format information (pink) is 15 bits stored twice, next to the finders. It records the error correction level and which of the eight masks was used, protected by its own BCH code. Version information (purple) shows up from version 7.
Data and error correction (black) is everything else. Your text is converted into bits (numeric, alphanumeric or byte mode, whichever is most compact) and split into codewords. Reed–Solomon error-correction codewords are added, and the result snakes up and down the grid in two-module-wide columns, starting at the bottom right.
Why the mask matters
Raw data can form long stripes or blank patches that look like finder patterns or confuse the scanner's light metering. So the encoder XORs one of eight fixed patterns over the data area, scores each result against four penalty rules, and keeps the best. Tick "Remove the mask" above to see the unmasked data. The scanner reads which mask was used from the format bits and undoes it.
Why longer text means a bigger code
There are 40 versions, from 21 × 21 modules (version 1) to 177 × 177 (version 40), each four modules wider than the last. The encoder picks the smallest version that fits your data at the chosen error correction level. That's why short URLs give airy, easy-to-scan codes and long ones give dense ones. It's the reason the size calculator asks what you're encoding. To see what the extra error-correction data can really survive, try the damage test.
Poking at a live model like this is often the fastest way to make a technical idea click. If you like learning this way, ahaboo has narrated, interactive explainers on how everyday things really work, one "aha" at a time.