How QR codes work: modules, versions and error correction
A QR code is a square grid of dark and light cells that a camera can read from any angle. Its structure explains why some codes scan instantly and others fail, and how big you need to print one.
The parts of a QR code
Each small square in the grid is called a module. Most modules hold data, but several fixed patterns help the scanner find and straighten the code:
- Finder patterns. The three large squares in the corners, each 7 by 7 modules. Their position tells the scanner which way up the code is.
- Timing patterns. A row and a column of alternating dark and light modules between the finders. They let the scanner count the grid size.
- Alignment patterns. Smaller squares that appear from version 2 upward and help correct for a curved or tilted surface.
- Format information. Modules next to the finders that record the error correction level and the mask pattern.
- Quiet zone. The empty light border around the code. It is part of the standard, not decoration.
Versions and grid size
QR codes come in 40 sizes, called versions. Each version adds four modules to each side.
| Version | Calculation | Grid |
|---|---|---|
| 1 | 17 + 4 × 1 | 21 × 21 |
| 2 | 17 + 4 × 2 | 25 × 25 |
| 10 | 17 + 4 × 10 | 57 × 57 |
| 40 | 17 + 4 × 40 | 177 × 177 |
A generator picks the smallest version that fits your data at the error correction level you choose. A short address fits in a small version; a long address with tracking parameters forces a bigger, denser grid that is harder to scan from a distance. Shorter text gives a better code.
Error correction levels
QR codes use Reed–Solomon error correction, the same family of maths used on CDs. Extra codewords let a scanner rebuild data from a damaged or dirty code. You choose one of four levels:
| Level | Approximate share of codewords that can be restored | Good for |
|---|---|---|
| L (low) | about 7% | Clean screens and print, maximum data |
| M (medium) | about 15% | A sensible default for most print |
| Q (quartile) | about 25% | Outdoor signs and labels that may get scuffed |
| H (high) | about 30% | Codes with a logo placed over the centre |
Higher levels use more of the grid for recovery data, so the same text needs a bigger version. That is the trade-off: robustness against size.
Encoding modes and masking
The data is stored in one of several modes. Numeric mode packs digits most tightly, alphanumeric mode handles upper-case letters, digits and a few symbols, and byte mode stores any text. For example, a version 1 code at level L holds up to 41 digits in numeric mode but only 17 characters in byte mode. Before the code is finished, the generator tries eight mask patterns that flip modules in a regular way, and keeps the one that avoids large blocks and confusing look-alike patterns.
How big to make it
The standard quiet zone for a QR code is 4 modules on each side.
Example. A version 1 code on screen with each module drawn at 10 pixels: (21 + 8) × 10 = 290 pixels square, including the border.
Print example. A version 4 code is 17 + 16 = 33 modules. With the quiet zone it is 41 modules. At 0.5 mm per module it prints 41 × 0.5 = 20.5 mm wide.
Make codes bigger when people scan from further away, and always test the printed result with more than one phone.
Checklist before you print
- Scan it with at least two different phones and camera apps.
- Keep strong contrast: dark modules on a light background. Inverted or pale codes fail on some readers.
- Leave the full quiet zone clear of text and borders.
- Use a vector format such as SVG for print so edges stay sharp.
- Check that the destination works and will keep working for as long as the print exists.
- Print a short human-readable address under the code for people who cannot scan.
Questions
Why is there no generator on this page?
A correct QR encoder needs Reed–Solomon maths, version tables and mask scoring. A half-correct one produces codes that fail silently, so this page explains the format instead. Many phone camera apps and office tools can create codes offline.
Do QR codes expire?
The pattern itself never expires. A code that points to a redirect service stops working if that service closes or the redirect is removed, so a code that contains your own address directly is the more durable choice.
Is it safe to scan any QR code?
Treat it like a link from a stranger. Check the address your phone previews before you open it, and be wary of stickers placed over codes in public spaces.