How does a QR code work?
Up to 84 characters at level M in this demo (real QR codes go up to version 40 and about 2,900 characters).
Mask. Big blobs of one colour, or shapes that look like finder patterns, confuse cameras. So the data area is XOR-ed with one of 8 patterns. The encoder tries all eight, scores each with penalty rules, and keeps the lowest: here mask 2. This finished code is real: point your phone camera at it.
Overview
Short answer
A QR code stores data as a grid of dark and light squares, one bit each. Three corner squares let a camera find and straighten it, and extra error-correction data lets your phone rebuild up to 30% of a damaged or covered code.
Play with the figure, then press Next (or the → key) to go step by step.
A barcode that works in two directions
An ordinary barcode stores information in one direction only, in the widths of its bars, so it holds just a few dozen characters. A QR code ("Quick Response") is a grid of small squares called modules. Each one is a single bit: dark for 1, light for 0. Reading in both directions lets even a small code hold a web link, and the largest version holds about 2,900 characters.
QR codes were invented in 1994 by Masahiro Hara at Denso Wave, a Toyota supplier, to track car parts through factories. The codes had to be read fast, from any angle, even when dirty. Every feature of the design comes from those three demands.
The parts of a QR code
Step through the builder above to see each part appear. In order:
- Finder patterns. The three big squares in the corners let a camera find the code and work out which way up it is. The missing fourth corner gives the orientation.
- Timing patterns. Dotted lines between the finders tell the reader the grid spacing.
- Alignment patterns. Smaller targets that correct for a code that is curved or seen at an angle.
- Format information. A tiny label, stored twice, saying how the rest of the code is set up.
- Data and error correction. Everything else: your message, followed by extra repair codewords.
Codes come in 40 sizes, called versions. Version 1 is 21×21 modules, and each version adds four modules per side, up to 177×177 for version 40. The encoder simply picks the smallest version that fits your message.
How your phone reads it
Your camera app looks for the 1:1:3:1:1 stripe pattern of the finders in every video frame. Once it sees three, it knows the corners. It then undoes the perspective, using the alignment pattern, and samples the colour at the centre of every module. It reads the format bits, removes the mask, follows the same zigzag path the encoder used to collect the bits back into bytes, and runs error correction. All of that takes a fraction of a second.
Why a damaged code still works
The extra codewords are calculated with Reed–Solomon error correction, the same maths that lets a scratched CD play and lets space probes send pictures home. With enough repair codewords, the reader can work out the original data even when some codewords are wrong. The trade-off is space: more repair codewords means a bigger code for the same message.
There are four levels, chosen when the code is made:
- L (low): recovers about 7% of the codewords. Good for clean screens.
- M (medium): about 15%. The most common default.
- Q (quartile): about 25%.
- H (high): about 30%. Used for codes printed outdoors or with a logo in the middle.
Try it. Add a logo or scratch the code, then switch levels:
Codewords are split into blocks and spread out across the code. A single scratch then damages a few codewords in every block instead of wiping out one block completely, which is a much easier repair.
Why the mask matters
Raw data can produce large blank areas or accidental shapes that look like a finder pattern, and both confuse cameras. So the encoder flips modules using one of eight fixed patterns, tries all eight, and keeps the one that gives the most even, least confusing result. The format information tells the reader which mask to undo. Move the mask slider on the last step of the builder to see how different they look.
Are QR codes safe?
A QR code is just text, usually a link. It cannot run anything by itself. The risk is where the link goes: scammers stick fake codes on parking meters and posters, a trick called "quishing". Before you tap, check the address your camera shows, and be wary of any code that asks you to log in or pay.
Common myths
- "QR codes track you." The code itself is just printed data and can't see anything. The website it opens can track visits, like any link.
- "QR codes expire." A plain QR code works forever. "Dynamic" codes from some services point to a redirect link, and that service can switch it off.
- "You need a special app." The built-in camera on modern iPhones and Android phones reads them.
Questions people ask
How much data can a QR code hold?
The largest version (40) at the lowest error-correction level holds up to 7,089 digits, 4,296 letters and numbers, or 2,953 bytes of any data. Most codes in daily life hold a short web link and are version 2 to 5.
Can a QR code have a logo in the middle?
Yes. The logo simply covers some modules, and error correction rebuilds them. Use level H, keep the logo small, and never cover the three finder patterns.
Can QR codes be coloured or inverted?
Colours work as long as there is strong contrast between dark and light modules. Many readers also handle light-on-dark codes, but dark-on-light is the safest.
Why does a QR code need a white border?
The light margin, called the quiet zone, separates the code from its surroundings so the reader can find the finder patterns. The standard asks for four modules of margin.
What is the difference between a QR code and a barcode?
A barcode stores data in one direction, in the widths of its bars, and holds a few dozen characters. A QR code stores data in two directions and can hold thousands, with built-in error correction.
Test yourself
Pick an answer for each question. Every answer comes with an explanation.
0/4 answered01What are the three big squares in the corners for?
02Why can a QR code still scan with a logo covering its middle?
03What does the mask do?
04What makes a QR code dangerous?
Sources & more
Sources
- QR code (Wikipedia)(opens in a new tab)
- Creating a QR Code step by step (Project Nayuki)(opens in a new tab)
- Reed–Solomon error correction (Wikipedia)(opens in a new tab)
- History of QR Code (Denso Wave)(opens in a new tab)
Last updated 2026-11-26
Keep exploring
- Internet & WirelessExplore it
How does Bluetooth work?
- Internet & WirelessExplore it
How does WiFi work?
- Internet & WirelessExplore it
How does GPS work?
- Internet & WirelessExplore it
How do mobile networks (4G and 5G) work?
- Internet & WirelessExplore it
How do fibre-optic cables work?
- Internet & WirelessExplore it
How does HTTPS keep websites secure?