An explanation of how QR codes store, protect, and deliver information — and the engineering decisions that make them so reliable.
A QR (Quick Response) code is a two-dimensional matrix barcode capable of storing digital information in a pattern of black and white squares known as modules. Unlike traditional one-dimensional barcodes, which only encode information horizontally, QR codes encode data both horizontally and vertically. This allows them to store significantly larger amounts of information while remaining relatively compact.
QR codes were developed in 1994 by the Japanese company Denso Wave, a subsidiary of Toyota. They were originally designed for tracking automotive components through manufacturing plants, where conventional barcodes lacked the capacity and scanning speed required. The "Quick Response" name reflects their ability to be decoded rapidly from almost any orientation.
Today QR codes have become one of the world's most common methods of sharing information. They can store website URLs, plain text, contact information, Wi-Fi credentials, payment details, product identifiers, authentication tokens and even small amounts of binary data.
A modern smartphone camera contains software capable of recognising and decoding QR codes almost instantly, making them an extremely accessible technology.
Although a QR code appears to be a random arrangement of black and white squares, every module has a defined purpose.
Each small square represents a binary value:
These binary values are grouped together into codewords, each consisting of eight bits (one byte). A sequence of codewords represents the encoded message along with additional information required for decoding.
The data itself is never simply written directly into the QR code. Instead, it undergoes several processing stages including:
Only after all of these steps are complete is the final QR code produced.
QR codes come in 40 standard versions, with each version increasing the dimensions of the square grid.
Version 1 measures 21 × 21 modules. Every subsequent version increases the width and height by four modules.
| Version | Size |
|---|---|
| 1 | 21 × 21 |
| 2 | 25 × 25 |
| 3 | 29 × 29 |
| 10 | 57 × 57 |
| 20 | 97 × 97 |
| 40 | 177 × 177 |
Larger versions can hold considerably more information, although they also become physically larger when printed.
The version chosen depends on:
Not every module stores user data. Many are permanently reserved for helping scanners correctly identify and decode the symbol.
The three large squares located in three corners of every QR code are called finder patterns. These patterns allow scanning software to:
Their distinctive alternating black and white rings make them easily identifiable even in noisy images.
Alignment patterns are smaller square markers found throughout larger QR codes. Their purpose is to compensate for:
Version 1 QR codes contain no alignment patterns because they are too small to require them.
Running horizontally and vertically between the finder patterns are alternating black and white modules called the timing patterns. These establish the spacing of every row and column.
Without timing patterns the decoder would struggle to determine exactly where one module ends and the next begins.
Every QR code requires a completely blank border surrounding it. This border is known as the Quiet Zone, and its width must be at least four modules.
Without this empty margin, scanners may mistake surrounding graphics or text as part of the code, preventing successful decoding.
QR codes support multiple methods of storing information. Different data types can be encoded more efficiently using different modes.
Stores digits 0–9 only. This is the most storage-efficient mode because multiple digits are packed into relatively few bits. Maximum capacity: 7,089 digits.
Supports uppercase letters, numbers, space, and nine punctuation symbols. Maximum capacity: 4,296 characters.
The most common mode today. Stores UTF-8 text, ASCII, binary files, URLs, and most languages. Maximum capacity: 2,953 bytes.
Optimised specifically for Japanese Shift-JIS encoded characters. Maximum capacity: 1,817 characters.
ECI (Extended Channel Interpretation) allows QR codes to specify alternative character encodings for international text.
One of the most remarkable features of QR codes is their ability to remain readable even after suffering physical damage. This is achieved using Reed–Solomon error correction, an algorithm developed in 1960 by Irving Reed and Gustave Solomon.
Instead of storing only the original data, the QR code also stores mathematically generated redundancy called error correction codewords. If some modules become unreadable due to dirt, scratches, poor printing or physical damage, these redundant codewords allow the missing information to be reconstructed.
Four levels are available.
| Level | Recovery |
|---|---|
| L | 7% |
| M | 15% |
| Q | 25% |
| H | 30% |
Higher levels reserve more of the QR code for redundancy rather than user data. Consequently, higher reliability means lower storage capacity — a trade-off that allows designers to choose between capacity and robustness.
Reed–Solomon does not simply duplicate the original information. Instead it treats the data as coefficients of mathematical polynomials over a finite field known as GF(256). Additional parity codewords are calculated using polynomial division.
When the QR code is scanned, the decoder compares received codewords against the expected polynomial relationships. Using algorithms such as the Berlekamp–Massey algorithm and Chien search, missing or corrupted codewords can often be reconstructed exactly.
This mathematical approach is why a QR code can still be read even when a significant portion has been obscured.
Large blocks of identical colours make QR codes difficult for cameras to interpret. To prevent this, every QR code is tested using eight different masking patterns. Each mask flips selected modules according to a simple mathematical rule, such as:
Each candidate mask receives a penalty score based on:
The mask with the lowest penalty score is selected and recorded in the QR code's format information.
After encoding and error correction have been completed, the codewords are inserted into the QR code. The placement follows a highly specific zig-zag path beginning at the lower-right corner: data is written upwards through two columns, then downwards through the next pair. Reserved areas for finder patterns, timing patterns and format information are skipped.
Because every QR code follows the same placement algorithm, any compliant scanner can decode any QR code regardless of the software used to generate it.
The decoding process is surprisingly sophisticated. A scanner typically performs the following operations:
Most of these operations are completed in a fraction of a second on modern smartphones.
The amount of information a QR code can hold depends upon its version number, error correction level, and encoding mode.
| Data type | Maximum |
|---|---|
| Numeric | 7,089 digits |
| Alphanumeric | 4,296 characters |
| Byte | 2,953 bytes |
| Kanji | 1,817 characters |
In practice, many QR codes contain much less information because higher error correction levels are often chosen to improve reliability.
Several engineering decisions contribute to the reliability of QR codes:
This material is suitable as an introduction to the engineering principles behind QR codes for a college or undergraduate computing / web technology project.