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.
Data Analysis
The encoder examines the input and selects the most efficient encoding mode (numeric, alphanumeric, byte, or Kanji).
Data Encoding
The input is converted to a binary bitstream according to the selected mode, prefixed with mode indicators and character counts.
Error Correction
Reed-Solomon error correction codewords are calculated and appended to the data bitstream.
Structure Arrangement
The combined bitstream is arranged into data codewords and organized into blocks for interleaving.
Module Placement
Codewords are placed into the matrix following a specific two-module-wide column pattern, avoiding reserved areas.
Masking
Eight masking patterns are evaluated, and the one producing the most scannable result is applied.
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.
| Mode | Character Set | Bits per Char | Efficiency |
|---|---|---|---|
| Numeric | 0–9 | 3.33 | Most efficient for numbers |
| Alphanumeric | 0–9, A–Z, space, $%*+-./: | 5.5 | Uppercase only |
| Byte | ISO 8859-1 / UTF-8 | 8 | URLs, mixed case text |
| Kanji | Shift JIS characters | 13 | Japanese text |
URL tip for smaller QR codes
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
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.
| Level | Recovery Rate | Data Overhead | Best For |
|---|---|---|---|
| L (Low) | ~7% | Lowest | Clean digital screens |
| M (Medium) | ~15% | Moderate | General purpose (default) |
| Q (Quartile) | ~25% | High | Printed materials |
| H (High) | ~30% | Highest | Codes 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:
- Detection — The camera identifies the three finder patterns and determines the code's position, size, and rotation.
- Sampling — The decoder uses timing and alignment patterns to map each pixel to its corresponding module in the grid.
- Unmasking — The format information is read to determine which mask was applied, and that mask is reversed.
- Decoding — Data codewords are extracted from the module grid in the correct reading order.
- Error correction — Reed-Solomon decoding detects and corrects any errors in the data.
- Interpretation — The decoded bitstream is parsed according to the mode indicators to reconstruct the original text, URL, or other data.
Version and size
See it in action
Generate a QR code and watch the encoding pipeline produce a scannable result instantly.