The Encoding Pipeline

Creating a QR code is a multi-step pipeline that transforms human-readable data into a precise grid of black and white modules.

1

Data Analysis

The encoder examines the input and selects the most efficient encoding mode (numeric, alphanumeric, byte, or Kanji).

2

Data Encoding

The input is converted to a binary bitstream according to the selected mode, prefixed with mode indicators and character counts.

3

Error Correction

Reed-Solomon error correction codewords are calculated and appended to the data bitstream.

4

Structure Arrangement

The combined bitstream is arranged into data codewords and organized into blocks for interleaving.

5

Module Placement

Codewords are placed into the matrix following a specific two-module-wide column pattern, avoiding reserved areas.

6

Masking

Eight masking patterns are evaluated, and the one producing the most scannable result is applied.

7

Format & Version Info

Format and version information is written into reserved areas to complete the QR code.

Encoding Modes

QR codes support four encoding modes, each optimized for different types of data. The encoder automatically selects the most efficient mode, or can mix modes within a single code.

ModeCharacter SetBits per CharEfficiency
Numeric0–93.33Most efficient for numbers
Alphanumeric0–9, A–Z, space, $%*+-./: 5.5Uppercase only
ByteISO 8859-1 / UTF-88URLs, mixed case text
KanjiShift JIS characters13Japanese text

URL tip for smaller QR codes

URLs are case-sensitive in QR encoding. HTTPS://EXAMPLE.COM (all caps) uses alphanumeric mode at 5.5 bits per character, while https://example.com uses byte mode at 8 bits per character. Uppercase URLs produce smaller, more scannable QR codes.

Structural Patterns

Before any data is placed, several structural patterns are written into the matrix at fixed positions. These patterns are what make QR codes recognizable and enable scanners to detect, orient, and decode them.

Finder Patterns

The three large squares in three corners (top-left, top-right, bottom-left) are finder patterns. Each is a 7×7 module square with a distinctive ratio of dark-light-dark (1:1:3:1:1) in any direction.

This unique ratio allows scanners to detect a QR code and determine its orientation regardless of rotation.

Alignment Patterns

For QR codes Version 2 and above, smaller 5×5 alignment patterns are placed at regular intervals. These help the decoder compensate for perspective distortion — such as when a QR code is photographed at an angle.

Timing Patterns

Alternating black-and-white modules running horizontally and vertically between the finder patterns form timing patterns. These establish the grid coordinate system, helping the decoder determine the exact row and column of each module.

Key Insight

The bottom-right corner of a QR code is intentionally left without a finder pattern. This asymmetry is by design — it tells the scanner which way is "up" so the data can be read in the correct order.

Error Correction: Reed-Solomon

QR codes use Reed-Solomon error correction, the same algorithm used in CDs, DVDs, and deep-space communication (NASA's Voyager probes). This allows QR codes to remain readable even when partially damaged, obscured, or covered by a logo.

LevelRecovery RateData OverheadBest For
L (Low)~7%LowestClean digital screens
M (Medium)~15%ModerateGeneral purpose (default)
Q (Quartile)~25%HighPrinted materials
H (High)~30%HighestCodes with logo overlays

For a deep dive into each level and how to choose the right one, see QR Code Error Correction Explained.

Masking

After data and error correction modules are placed, the QR code applies one of eight masking patterns. Masking inverts specific modules to prevent problematic patterns — like large uniform areas or patterns that mimic finder patterns — that could confuse scanners.

The encoder evaluates all eight patterns against a penalty scoring system and selects the mask that produces the lowest penalty score — meaning the most scannable result. The chosen mask ID is stored in the format information area.

How Scanning Works

When your smartphone camera points at a QR code, the decoding process happens in milliseconds:

  1. Detection — The camera identifies the three finder patterns and determines the code's position, size, and rotation.
  2. Sampling — The decoder uses timing and alignment patterns to map each pixel to its corresponding module in the grid.
  3. Unmasking — The format information is read to determine which mask was applied, and that mask is reversed.
  4. Decoding — Data codewords are extracted from the module grid in the correct reading order.
  5. Error correction — Reed-Solomon decoding detects and corrects any errors in the data.
  6. Interpretation — The decoded bitstream is parsed according to the mode indicators to reconstruct the original text, URL, or other data.

Version and size

QR codes come in 40 versions. Version 1 is 21×21 modules; each subsequent version adds 4 modules per side. Version 40 is 177×177 modules (31,329 total). Most practical QR codes are Version 1–10.

See it in action

Generate a QR code and watch the encoding pipeline produce a scannable result instantly.