A QR code looks like noise. It is actually one of the most orderly things you will point a camera at. Every square in it has a job, and once you know the jobs the whole thing makes sense.
The parts
- Version 3, 29×29 modules, error correction M, mask 0. Tap a label to isolate it.
Finder patterns. The three large squares, one in each corner except bottom-right. A scanner looks for their distinctive 1:1:3:1:1 ratio of dark and light in any direction. Find three of them and you know where the code is, how big it is and which way it is turned.
Timing patterns. A row and a column of alternating dark and light modules joining the finders. They let the scanner count how many modules wide the code is, which tells it the version.
Alignment patterns. Small squares scattered across larger codes. If the code is printed on a curved cup or photographed at an angle, these let the scanner correct the distortion. Version 1 (the smallest) has none.
Format information. Two copies of fifteen bits beside the finders, saying which error-correction level and which mask was used. Without these nothing else can be read, so they get their own protection.
Data and error correction. Everything else. Your text, plus extra codewords that let the scanner repair damage.
What happens when you scan
- The camera takes a picture and turns it into black and white.
- The scanner hunts for the three finder patterns.
- It uses them, and the timing patterns, to lay a grid over the image and read each module as 0 or 1.
- It reads the format bits, learns the mask, and removes it.
- It reads the data modules in a zigzag from the bottom-right corner upwards.
- Reed–Solomon error correction fixes any modules it read wrongly.
- The bits become text. Your phone sees that it starts with
https://and offers to open it.
In practice
Steps 2 and 3 are why the white border matters. The finder search needs to see the edge of each big square against clean white. Crowd the code with text and step 2 fails before anything else gets a chance.
Why a damaged code still reads
- Level L 7%
- Level M 15%
- Level Q 25%
- Level H 30%
Some of the data modules are not data at all. They are computed from the data using Reed–Solomon coding, the same maths that lets a scratched CD play. At level M, about 15% of the codewords can be wrong and the message still comes out intact. That budget is what a logo in the middle spends.
Common mistake
Thinking the error correction protects the corners. It protects the data. Damage a finder pattern and the scanner never finds the code, however high the level.
Three examples
▸Masking, and why codes look random
After encoding, one of eight fixed patterns is XORed over the data area. The encoder scores each result for large blank areas, long runs, and anything resembling a finder pattern, then keeps the best. That is why two codes for nearly the same text can look completely different, and why a code never has a big white hole in it. The deep dive shows all eight masks.
Try it yourself
Type your own text and watch the version, alignment patterns and mask change. Tap a legend item to see only that part.