A QR code is a grid of dark and light squares, called modules, that stores your data as bits. Three corner squares tell a camera where the code is and which way up it sits.
Extra error-correction bytes let a phone rebuild the data when part of the code is scuffed or covered.
Why a square instead of stripes
A 1D barcode, like the UPC on a cereal box, stores data in bars along one line. A smudge across that line, or a camera held at the wrong angle, can ruin the scan.
A QR (Quick Response) code stores data in two dimensions, so it holds far more in the same area. It also reads at any rotation, because the three bullseye squares in its corners tell the decoder which way is up.
The grid

The smallest QR code, Version 1, is 21 × 21 modules. Each version adds 4 modules per side, up to Version 40 at 177 × 177.
A bigger version holds more data, and the encoder picks the smallest one that fits your content.
Some modules never carry data. They form fixed patterns that help the scanner find and measure the code.
Finder patterns
The squares in the top-left, top-right and bottom-left corners are finder patterns. Each is 7 × 7 modules: a 3 × 3 dark core inside a light ring inside a dark ring, with a one-module light gap between it and the data.
A scanner looks for these first. From the three of them it works out the code's size, rotation and perspective, which is how your phone reads a sticker on a curved coffee cup.
Timing patterns
Two lines of alternating dark and light modules run between the finders, one across and one down. They work like a ruler printed into the code, so the decoder knows where each row and column of modules sits.
Alignment patterns
From Version 2 up, smaller 5 × 5 squares appear inside the code, and larger versions have more of them. They correct the position when the surface is curved or the photo is distorted, as on bottle labels and soft packaging.
The quiet zone
The standard asks for a blank margin of 4 modules on every side. Without it, nearby text or artwork blends into the code and the scanner can't find its edge.
How big should a QR code be? works out how much space the margin takes in print.
How the data is stored
Your content goes into the code as one stream of bits, in this order:
- a mode indicator, which says how to read the next chunk;
- a character count, which says how long that chunk is;
- the data itself;
- a terminator and padding, which fill the rest of the space;
- the error-correction codewords.
Data modes
The encoder picks the mode that stores your content in the fewest bits.
| Mode | What it holds | Cost |
|---|---|---|
| Numeric | Digits only | 10 bits per 3 digits |
| Alphanumeric | 0-9, A-Z, space and $%*+-./: | 11 bits per 2 characters |
| Byte | Any bytes, such as a URL or UTF-8 text | 8 bits per byte |
| Kanji | Shift JIS kanji | 13 bits per character |
One code can mix modes, such as a run of digits in numeric mode followed by text in byte mode. Most URLs end up in byte mode, because alphanumeric mode has no lowercase letters.
Error-correction levels
Every QR code is made at one of four error-correction levels. A higher level lets more of the code be lost and still decode, but leaves less room for data: a Version 5 code holds 106 bytes at level L and only 44 at level H.
| Level | Recovers about | Good for |
|---|---|---|
| L | 7% | Screens and clean labels |
| M | 15% | General print |
| Q | 25% | Print that may get scuffed; QRdx's default |
| H | 30% | Codes with a logo, and signs that get dirty or worn, such as outdoor signs |
Pick a level in the demo to see the trade-off on a real code, then cover part of it. The link stays the same; only the redundancy changes.
Level M can recover ~15% of damaged codewords. Same URL, yet the grid generally gets denser at higher levels: the extra modules carry the redundancy.
Why a torn code still scans
QR codes use Reed-Solomon error correction over GF(256), the field of the 256 possible byte values. The encoder computes extra bytes from your data, and the decoder uses them to rebuild modules that are missing or misread, up to the level's limit.
So a code with a scuffed corner, or a thumb over part of it, still gives back exactly the original data.
A logo in the middle is the same kind of damage. It's safe as long as the redundancy that's left covers the modules it hides.
Error correction can't fix a covered finder pattern, though. If the decoder can't find the code, it never gets as far as the repair.
Mask patterns
Once the data and error-correction bytes are on the grid, the encoder flips some of them with one of eight mask patterns (an XOR over the data area). Masking breaks up large blocks of one color and shapes that look like a finder, both of which confuse scanners.
The standard scores each mask with penalty rules, and the encoder keeps the one that scores lowest. That's why two generators can draw different patterns for the same link, and both codes are correct.
What your phone does when it scans
A scanner app works through roughly these steps:
- Capture a camera frame.
- Find the three finder patterns.
- Flatten the grid, undoing the angle and perspective (a homography).
- Decide whether each module is dark or light, with a threshold that adapts to the lighting.
- Read the format information, which holds the error-correction level and the mask. From Version 7 up, the version is encoded too.
- Undo the mask and repair the codewords.
- Split the bits into segments and decode each one.
- Hand the result to the phone: a link to open, a Wi-Fi network to join or a contact to save.
Every app takes its own shortcuts through these steps. That's why contrast, the quiet zone and module size still decide whether a code reads in a dim room, even with error correction to fall back on.
What this means for design
Keep the quiet zone. It's part of the standard, and a code printed flush against other artwork often won't scan.
Keep dark modules on a light background. Scanners sort modules by brightness, so light gray on white fails. The current standard allows light-on-dark codes, but some scanner apps still can't read them.
Test any code that carries a logo. The logo spends error correction, so check that the code still scans as well as how it looks.
The QRdx playground runs that check as you design. Its scan score decodes the code at three sizes through a model of a phone camera, and tells you what to change when a size fails.
Further reading
The QR code standard is ISO/IEC 18004. For something free to read, the ZXing project is a widely used open-source decoder, and QRdx's own encoder is open source in the qrdx package.