How a QR code works and how your phone reads it
Last updated: 09/15/2026
You point the camera, see a little square for half a second, and your phone already shows you the link. It feels like magic, but it's geometry, math, and some well-thought-out redundancy. Here's what a QR code looks like on the inside and how it gets decoded.
The anatomy of a QR code
A QR code is a square grid of black and white cells called modules. Within that grid there are zones with a fixed role, always in the same relative position:
- Position patterns: the three large squares in the corners.
- Timing pattern: the dashed line crossing the center.
- Data area: the rest of the modules, holding the encoded information.
- Quiet zone: the white margin around the entire code.
- Position patterns (the three large squares in three of the four corners): they let the reader instantly find the code in the image and calculate its size and rotation, no matter how tilted the photo is.
- Timing patterns: two dashed lines connecting the position patterns, telling the reader the exact size of each module so it can count the grid precisely.
- Alignment pattern (in larger codes): a smaller square that helps correct distortion when the photo wasn't taken perfectly flat.
- Format information: a narrow strip near the position patterns telling the reader which error correction level and which mask were used.
- Data area: the rest of the grid, where the actual information lives, encoded in binary, plus the error-correction blocks.
- Quiet zone: the white margin around the entire code. It's not decorative — without that margin, the reader can confuse the QR code's edge with the background of the image and fail to recognize it.
From your data to the grid
When you generate a QR code, the text, URL, or WiFi data is first converted to binary and grouped according to its content type (numeric, alphanumeric, free text). On top of that comes the error-correction information, calculated with an algorithm called Reed–Solomon (the same kind of math used to keep a scratched CD playing fine). All those bits get arranged in the grid following a zigzag pattern, and finally one of eight possible “masks” is applied: a pattern that mixes up the modules to avoid overly uniform white or black areas, which are harder for a camera to read.
How the camera decodes it
When you point your phone at it, the process happens in just a few video frames:
- The software scans the image for the three characteristic position patterns (a 1:1:3:1:1 stripe ratio), which are quite rare in “normal” photos, so they're detected fast.
- Using those three points, it calculates the code's orientation, size, and perspective, correcting for distortion if the photo wasn't taken head-on.
- It uses the timing patterns to trace the exact grid and “samples” each module, reading it as 0 (white) or 1 (black).
- It removes the mask applied when the code was generated (that info lives in the format zone) to recover the original data.
- It applies Reed–Solomon error correction: if some modules weren't read correctly (due to dirt, a logo, a tear), it mathematically rebuilds them from the stored redundancy.
- It converts the resulting bits back into text and acts based on the data type: opens the browser for a URL, offers to connect for WiFi, shows the text for plain text.
Why it sometimes won't scan
It's almost always one of these reasons: too little contrast between the chosen colors, a cropped or too-thin white margin, a code too small for the scanning distance, or a logo too large for the configured error-correction level.
Now that you know how it works, try making one!
Go to generator