QR codes are everywhere — restaurant tables, boarding passes, payment terminals, factory floors. But what's actually happening inside that square grid of black and white dots? This guide breaks down the encoding process, the physical structure, and the math that makes QR codes surprisingly hard to break.
Every QR code is built from a fixed set of structural components.
The three large squares in the top-left, top-right, and bottom-left corners are finder patterns. Each one is a 7x7 module block with a specific ratio — 1:1:3:1:1 — designed to be recognizable no matter how the scanner encounters it. Rotate the code 90 degrees, flip it, scan it at an angle — the finder patterns still register.
Why three instead of four? Three points define a plane. The scanner calculates the fourth corner mathematically, and the gap in the bottom-right is used for alignment and format information.
Two single-module-wide lines run between the finder patterns — one horizontal, one vertical. They alternate strictly: dark, light, dark, light. The scanner uses these to determine the exact module grid spacing, which matters when the code is printed at odd sizes or on curved surfaces.
Codes from version 2 onward include alignment patterns — small 5x5 targets scattered across the data area. Version 2 has one. Version 40 has 46. They correct for perspective distortion, like when someone scans a code printed on a coffee cup or a wrinkled poster.
QR codes don't treat all data the same. The spec defines four encoding modes, each optimized for a different character set:
| Mode | Characters | Bits per Char | Max Capacity (V40-L) |
|---|---|---|---|
| Numeric | 0-9 | 3.33 | 7,089 digits |
| Alphanumeric | 0-9, A-Z, space, $%*+-./: | 5.5 | 4,296 chars |
| Byte | Any (ISO 8859-1 / UTF-8) | 8 | 2,953 bytes |
| Kanji | Shift JIS double-byte | 13 | 1,817 chars |
Numeric mode groups digits into triplets and converts each to a 10-bit value. Three characters in just 10 bits instead of the 24 bits byte mode would need.
Alphanumeric mode covers uppercase letters, digits, and nine special characters. Note the absence of lowercase letters. A URL like HTTPS://EXAMPLE.COM (all uppercase) encodes in alphanumeric mode, but https://example.com falls through to byte mode — using 45% more space.
HTTPS://EXAMPLE.COM/GO produces a visibly smaller QR code than its lowercase equivalent.
Byte mode is the fallback. Any byte value goes through at 8 bits per character. Most URLs and arbitrary text end up here.
Kanji mode is specific to Shift JIS encoded Japanese characters. Outside Japan, you'll rarely encounter it.
A single QR code can mix modes. The data stream includes mode indicators (4-bit headers) that tell the scanner when one mode ends and another begins.
This is the engineering that makes QR codes work in the real world. Printed codes get scratched, rained on, partially covered, and faded by sunlight. Reed-Solomon error correction lets the scanner reconstruct missing data from the surviving modules.
The math works over GF(256) — a Galois field with 256 elements. The encoder treats the data as coefficients of a polynomial, divides it by a generator polynomial, and appends the remainder as error correction codewords.
| EC Level | Recovery | Overhead | Best For |
|---|---|---|---|
| L (Low) | ~7% | ~20% more modules | Digital screens, clean environments |
| M (Medium) | ~15% | ~38% more modules | General printing (default) |
| Q (Quartile) | ~25% | ~55% more modules | Outdoor signage, industrial labels |
| H (High) | ~30% | ~65% more modules | Logo overlays, harsh environments |
The QR code spec defines 40 versions. Version 1 is a 21x21 module grid. Each subsequent version adds 4 modules per side, up to version 40 at 177x177 — that's 31,329 modules.
| Version | Modules | Numeric (EC-M) | Alphanumeric (EC-M) | Byte (EC-M) |
|---|---|---|---|---|
| 1 | 21x21 | 34 | 20 | 14 |
| 2 | 25x25 | 63 | 38 | 26 |
| 5 | 37x37 | 202 | 122 | 84 |
| 10 | 57x57 | 652 | 395 | 271 |
| 20 | 97x97 | 2,061 | 1,249 | 858 |
| 40 | 177x177 | 5,313 | 3,220 | 2,210 |
Most real-world QR codes fall between version 2 and version 7. A typical URL under 50 characters with level M error correction fits in version 3 (29x29 modules). Keep your data short and your version number stays low — that's the single most effective thing you can do for scannability.
Raw encoded data can produce patterns that confuse scanners — large blocks of identical modules, patterns that mimic finder patterns, or uneven dark/light distributions. The spec defines eight mask patterns. The encoder applies all eight, scores each using four penalty rules, and selects the mask with the lowest penalty score.
This is entirely automatic. But it's the reason two QR codes encoding identical data can look different: different generators might break ties differently.
The whole process is deterministic. Given the same input and error correction level, you get the same module grid every time.
One-dimensional barcodes (UPC, Code 128) encode data in a single row of varying-width bars. They max out at roughly 20-25 characters. QR codes store data in two dimensions — a version 5 QR code occupies a 37x37 module square and holds 84 bytes. To hold the same data in Code 128, you'd need a barcode over 15cm wide. The QR code fits in under 2cm.
There's also the orientation advantage. Barcodes must be scanned perpendicular to their alignment. QR codes scan from any angle, any rotation.
See it in action — generate QR codes and experiment with different data lengths and error correction levels.
Try the QR Generator