QR code specification and internals
The ISO/IEC 18004 machinery: versions, capacity, error correction, masks, encoding modes. Every number here is implemented and tested in our open-source core.
- How a QR code is generated, step by stepEncoding runs in eight steps: choose the mode, choose the version, build the bit stream, split into codewords, compute Reed–Solomon error correction,…
- QR code error correction levels explainedL, M, Q and H tolerate roughly 7%, 15%, 25% and 30% damage. Higher levels cost capacity, so the same payload needs a bigger version — which means smaller…
- Alignment patterns — the small squares that fix distortion5×5 alignment patterns anchor the decoder's sampling grid. Version 1 has none; the count grows to 46 at version 40, at positions fixed by ISO/IEC 18004.
- Can a QR code be round?The symbol must stay a square grid, but the rendering can look round — circular modules, round eyes, circular frames. What works and what breaks scanning.
- Decode a QR code by handRead the format information, unmask, zig-zag through the data, de-interleave, check Reed–Solomon and parse the modes — decoding on paper, step by step.
- Deterministic QR generationSame input and options must yield the same symbol — mask selection included. Why determinism holds, why generators still differ, and why it is a feature.
- ECI — how QR codes declare a character encodingThe Extended Channel Interpretation header tells decoders how to interpret byte mode — UTF-8 is ECI 26. Most decoders assume UTF-8 anyway; old ones choke.
- Encode HELLO WORLD by hand — a complete worked exampleThe classic exercise: HELLO WORLD as a version 1-Q QR code, step by step, with every real intermediate value from character pairs to Reed–Solomon codewords.
- Error correction blocks and interleaving in QR codesWhy QR data is split into blocks and woven together codeword by codeword: so one physical scratch spreads across every block instead of destroying one.
- Finder patterns — how a scanner locates a QR codeThe three 7×7 corner squares produce a 1:1:3:1:1 dark-light signature on any scan line through their centre, which is what makes QR codes rotation-proof.
- Format information — the 15 bits everything depends onFormat information encodes the EC level and mask in 5 bits, protects them with BCH(15,5), XORs with a fixed mask, and is written twice beside the finders.
- GS1 Digital Link in QR codesOne QR code that opens a web page for shoppers and yields the GTIN for checkout scanners — the Digital Link URI syntax and the 2D sunrise behind it.
- How logos work without breaking a QR codeA logo deletes data modules and error correction rebuilds them. The budget maths, why centre placement matters, and how generators keep codes scannable.
- How much data fits in a QR codeTheoretical ceilings are 7,089 digits, 4,296 alphanumeric characters or 2,953 bytes — but the practical answer is to keep URLs under about 50 characters.
- Kanji mode explained — 13 bits per characterKanji mode packs double-byte Shift-JIS characters into 13 bits — 46% denser than UTF-8 byte mode — but few generators emit it and UTF-8 rules in practice.
- Mask patterns 0 to 7 — the eight formulas and why they existEvery QR code XORs its data region with one of eight fixed patterns to break up problem shapes. The formulas, what they look like, and what masking prevents.
- Mask selection and penalty scores — how the best mask winsEncoders score all eight masked symbols on four penalty rules — runs (N1=3), 2×2 blocks (N2=3), finder-lookalikes (N3=40), balance (N4=10) — lowest wins.
- Maximum safe logo coverage by error correction levelSafe logo area by EC level — roughly 8% at M, 16% at Q, 20% at H, and none at L — with the side-length conversions generators actually use.
- Mirrored QR codesGood decoders tolerate a mirror-imaged QR code, but mirrored print is still a production bug. How mirroring happens and how to spot it from the finder layout.
- Module size vs camera resolutionA decoder needs roughly three or more image pixels per module. The arithmetic from sensor to module, and why tiny codes fail on older cameras.
- QR code anatomy — every region of the symbolA labelled tour of a QR code: finder patterns, separators, timing, alignment, format and version information, the data region and the quiet zone.
- QR code bit stream walkthrough — from text to modulesThe full encoding pipeline: mode indicator, character count, data, terminator, pad bytes 0xEC 0x11, Reed–Solomon, interleaving, zig-zag placement, masking.
- QR code checksum and integrityQR has no payload checksum — Reed–Solomon corrects damage and BCH protects the format fields, but a clean decode proves nothing about authenticity.
- QR code colour inversion and polarityThe spec assumes dark modules on a light background and nothing in the symbol says otherwise. Why inverted codes are a decoder lottery, and the safe rule.
- QR code data encoding modes — numeric, alphanumeric, byte, kanjiNumeric packs 3.33 bits per character, alphanumeric 5.5, byte 8, kanji 13. Mode choice is why HTTPS://USEQR.APP makes a smaller code than the lowercase URL.
- QR code density and scan distanceModule count times module size sets the physical width a QR code needs. The formula, and a table of common versions at common scanning distances.
- QR code file formats comparedPNG, SVG, JPEG, WebP, PDF and EPS for QR codes — lossless vs lossy, scaling behaviour, print hand-off, and why JPEG is never the right choice.
- QR code SVG path structureHow a module matrix becomes SVG — one merged path versus thousands of rects, crisp-edges rendering, integer coordinates, and why seams appear.
- QR code versions 1 to 40 — sizes, capacity and how to chooseVersions run from 21×21 to 177×177 modules, growing 4 per step. The right version is the smallest that fits your payload at your error-correction level.
- Quiet zone requirements — the margin that is part of the specISO/IEC 18004 requires a light border at least 4 modules wide on every side of a QR code (2 for Micro QR). Crowding it is a leading cause of scan failure.
- Reed–Solomon error correction in QR codes, made readableQR codes append Reed–Solomon check codewords computed over GF(256). What "recovers 30% damage" really means: erasures count once, unknown errors twice.
- Rendering a QR code from a matrixFrom boolean matrix to pixels — module size, quiet zone, device pixel ratio on canvas, and choosing PNG or SVG output. With pseudo-code.
- Structured append — splitting data across multiple QR codesThe spec lets one message span up to 16 QR symbols with a parity byte tying them together. Phone scanner support is effectively nil — use alternatives.
- Timing patterns — the ruler inside every QR codeThe alternating dark-light lines in row 6 and column 6 tell a decoder the module pitch and count, so it can place its sampling grid before reading data.
- UTF-8 and Unicode in QR codes — emoji, CJK and the legacy trapQR byte mode carries raw octets, so Unicode works by encoding UTF-8. It scans everywhere modern — but each emoji costs 4 bytes and old readers assume Shift-JIS.
- Vector vs raster QR codesSVG scales infinitely; a raster QR must be 300+ DPI at final printed size — a 3 cm code needs at least 354 pixels. The print-shop arithmetic.
- Version information — how big symbols declare their sizeFrom version 7 up, QR codes carry an 18-bit BCH(18,6)-protected version field, written twice near the finders, so decoders need not trust module counting.
- Why longer URLs make denser QR codesQR capacity steps at fixed boundaries — 14, 26, 42, 62, 84, 106 bytes at level M — and each boundary crossed adds four modules to every side of the code.
- Why QR codes are squareQR is a matrix symbology — data on a fixed square grid, located by three corner finder patterns. Why the geometry works, and the rectangular exceptions.
- Why two generators produce different QR codesVersion selection, EC defaults, mode segmentation and mask choice can all legally differ. How to tell a harmless difference from an actual bug.