← Back to QR Generator
Technical Guide March 15, 2026

How QR Codes Work — Encoding, Structure & Error Correction

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.

The Anatomy of a QR Code

Every QR code is built from a fixed set of structural components.

Finder patterns

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.

Timing patterns

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.

Alignment patterns

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.

Four Encoding Modes

QR codes don't treat all data the same. The spec defines four encoding modes, each optimized for a different character set:

ModeCharactersBits per CharMax Capacity (V40-L)
Numeric0-93.337,089 digits
Alphanumeric0-9, A-Z, space, $%*+-./: 5.54,296 chars
ByteAny (ISO 8859-1 / UTF-8)82,953 bytes
KanjiShift JIS double-byte131,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.

Practical tip: If you control the URL, consider using an all-uppercase domain with a case-insensitive redirect. 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.

Reed-Solomon Error Correction

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 LevelRecoveryOverheadBest For
L (Low)~7%~20% more modulesDigital screens, clean environments
M (Medium)~15%~38% more modulesGeneral printing (default)
Q (Quartile)~25%~55% more modulesOutdoor signage, industrial labels
H (High)~30%~65% more modulesLogo overlays, harsh environments
The tradeoff is real: Level H needs about 65% more modules than level L for the same data. That means a bigger, denser code — harder to scan at small sizes. Don't default to level H "just in case." Use M for most applications and bump up only when you know the code will take damage.

Versions 1 Through 40

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.

VersionModulesNumeric (EC-M)Alphanumeric (EC-M)Byte (EC-M)
121x21342014
225x25633826
537x3720212284
1057x57652395271
2097x972,0611,249858
40177x1775,3133,2202,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.

Data Masking

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 Full Encoding Pipeline

  1. Mode analysis — determine the most efficient encoding mode for the input
  2. Data encoding — convert characters to bit streams
  3. Version selection — find the smallest version that fits the data plus error correction
  4. Error correction — compute Reed-Solomon codewords and interleave with data
  5. Module placement — lay out structural elements, then fill data modules in a zigzag pattern
  6. Masking — apply all eight masks, score each, select the best
  7. Format encoding — write error correction level, mask number, and version info

The whole process is deterministic. Given the same input and error correction level, you get the same module grid every time.

QR Codes vs Traditional Barcodes

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.

Tips for Developers

See it in action — generate QR codes and experiment with different data lengths and error correction levels.

Try the QR Generator

Related Articles

Built by Andy · Build a microsite + QR · Free VIN Decoder · WebMCP Directory · helloandy.net