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.

Error correction
Show layers

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.

Questions people ask

How does a QR code store information?
As a grid of dark and light squares called modules. Each dark module is a 1, each light one a 0. Your text is converted to bits, grouped into 8-bit codewords, protected with Reed–Solomon error correction, and laid into the grid in a zigzag from the bottom-right corner.
What are the three big squares for?
They are finder patterns. Their 1:1:3:1:1 ratio of dark and light looks the same from any angle, so a scanner can find the code, work out its size and orientation, and correct for tilt.
Why do QR codes look random?
A mask pattern is XOR-ed over the data so there are no big blank areas or stripes that could confuse a scanner. The encoder tries all eight masks and keeps the one with the lowest penalty score. Turn the mask off above to see how regular raw data can look.
Who invented the QR code?
Masahiro Hara and his team at Denso Wave, a Toyota group company, in 1994, to track car parts. Denso Wave chose not to enforce its patent, which is why QR codes are free to use. The format is standardised as ISO/IEC 18004.
Can a QR code hold a virus?
The code only holds text. The risk is what the text points to: a malicious link. Check the URL your camera shows before opening it.

Related tools