MyFreeQR
Back to Blog
TechnologyMarch 25, 202612 min

The Science Behind QR Codes: How the Technology Actually Works

A deep dive into the inner mechanics of QR codes: Reed-Solomon error correction, encoding modes, and data masking.

TM

Thomas Martin

Founder of MyFreeQRCode

The invention that revolutionized automatic identification

In 1994, at Toyota's factories in Japan, an engineer named Masahiro Hara from Denso Wave was solving a concrete problem: traditional barcodes could only store 20 characters and had to be scanned at a precise angle. The automotive industry needed to store hundreds of characters (part numbers, manufacturing dates, lot numbers) on tiny labels. The result — the Quick Response Code — could store 7,089 numeric characters in a square of just a few centimeters, scannable in 30 milliseconds from any angle.

Today, over 5.3 billion QR code scans are performed annually worldwide according to Juniper Research (2024). Yet very few users understand the sophisticated technology behind these black-and-white squares. This article offers a technical deep dive into the inner mechanisms that make QR codes work.

ISO/IEC 18004: The global standard

QR codes are governed by the international standard ISO/IEC 18004:2015, which precisely defines every aspect of their structure. Unlike linear barcodes (EAN-13, Code 128), QR codes are two-dimensional matrix codes: they encode information on both axes (horizontal and vertical), allowing them to store exponentially more data in the same area.

The standard defines 40 QR code versions, from version 1 (21×21 modules) to version 40 (177×177 modules). Each higher version adds 4 modules per side. A module is the smallest black or white square in the QR code — the fundamental unit of information.

Anatomy of a QR code: structural components

Finder Patterns

The three large squares in the upper-left, upper-right, and lower-left corners are the Finder Patterns. Their unique black-white-black-white-black width ratio of 1:1:3:1:1 allows the scanner to instantly locate the QR code and determine its orientation, regardless of rotation. This is the characteristic that enables scanning from any angle — a major advantage over traditional barcodes.

Timing Patterns

Two lines alternating black and white connect the Finder Patterns: one horizontal, one vertical. These Timing Patterns allow the decoder to determine the matrix density and correctly synchronize module reading, even if the QR code is slightly distorted (for example, printed on a curved surface).

Alignment Patterns

Starting from version 2, additional small squares appear in the QR code. These Alignment Patterns help correct perspective distortion. The higher the version, the more markers: version 7 has 6, version 40 has 46.

The four encoding modes

ISO 18004 defines four encoding modes, each optimized for a specific data type:

  • Numeric mode: encodes digits 0-9 at 3.33 bits per character. A version 40 QR code can store up to 7,089 digits.
  • Alphanumeric mode: encodes digits, uppercase letters A-Z, and 9 special characters ($, %, *, +, -, ., /, :, space) at 5.5 bits per character. Maximum capacity: 4,296 characters.
  • Byte mode: encodes any ISO 8859-1 character on 8 bits. This is the mode used for URLs and text with special characters. Capacity: 2,953 bytes.
  • Kanji mode: encodes Japanese Kanji characters (JIS X 0208) on 13 bits per character. Capacity: 1,817 characters.

The generator automatically selects the most efficient mode. For a URL like "https://example.com," byte mode is used because the URL contains lowercase letters (not supported in alphanumeric mode). This is why an ALL-CAPS URL generates a simpler QR code — a little-known but useful trick for small print formats.

Reed-Solomon error correction: the real magic

This is the most remarkable component of the QR code. The Reed-Solomon error correction algorithm (invented by Irving S. Reed and Gustave Solomon in 1960 at MIT Lincoln Laboratory) can reconstruct data even if part of the QR code is damaged, dirty, or obstructed.

Four correction levels are defined:

  1. Level L (Low): recovers up to 7% of lost data
  2. Level M (Medium): recovers up to 15% of lost data
  3. Level Q (Quartile): recovers up to 25% of lost data
  4. Level H (High): recovers up to 30% of lost data

In practice, a QR code with Level H correction will continue to work even if nearly one-third of its surface is damaged. This property is what allows logos to be added to the center of QR codes: the logo "destroys" part of the data, but error correction compensates. Be careful though: a logo that is too large can make the QR code unreadable if the destruction exceeds the correction capacity of the chosen level.

Data masking: an overlooked optimization mechanism

After encoding data and adding error correction codes, the QR code undergoes a masking process. Eight predefined masks (numbered 0 to 7) are tested. Each mask is a mathematical formula that inverts certain modules based on their position (for example, mask 0 inverts all modules where (row + column) is even).

The goal of masking is to avoid patterns that interfere with decoding: large uniform black or white areas, patterns resembling Finder Patterns, or excessive imbalance between black and white modules. A penalty system evaluates each mask against 4 criteria, and the mask with the lowest penalty score is selected.

From scan to decode: what your smartphone does

When you point your camera at a QR code, here is what happens in milliseconds:

  1. Detection: the algorithm searches for the three Finder Patterns with their characteristic 1:1:3:1:1 ratio.
  2. Orientation: the relative position of the three Finder Patterns determines the code's orientation.
  3. Perspective correction: Alignment Patterns and Timing Patterns correct distortions.
  4. Sampling: each module is identified as black (1) or white (0).
  5. Unmasking: the mask number is read from the Format Information bits and the inverse mask is applied.
  6. Error correction: the Reed-Solomon algorithm verifies and corrects the data.
  7. Decoding: bits are converted to text according to the specified encoding mode.

This entire process typically takes less than 50 milliseconds on a modern smartphone — faster than the blink of an eye.

Why this technology remains unmatched

Thirty years after its invention, the QR code remains the world's most versatile automatic identification technology. Its unique combination of high storage capacity (up to 7,089 characters), robustness (error correction up to 30%), reading speed (under 50ms), and free usage (Denso Wave waived its patent rights) makes it a standard that is virtually impossible to replace.

Competing technologies exist — Data Matrix (ISO/IEC 16022), Aztec Code (ISO/IEC 24778), PDF417 — but none combines as many advantages. The next time you scan a QR code, you'll know that behind that simple square lies 30 years of research in information theory, abstract algebra, and image processing — all executed in the blink of an eye.

Generate a QR Code

Generate custom QR codes for your links, texts, contacts, and much more. Free, fast, and no sign-up required.

Generate a QR Code
technologyQR codeReed-SolomonISO 18004