How QR Codes Work: Technical Principles and Error Correction Explained

QR Code โ€” views

What Is a QR Code

QR Code (Quick Response Code) was invented by DENSO WAVE, a Japanese company, in 1994 for tracking automotive parts. Unlike traditional one-dimensional barcodes that store only a dozen characters, QR codes can hold up to 7,089 numeric digits or 4,296 alphanumeric characters โ€” an information density tens of times greater.

Today, QR codes are used in mobile payments, URL redirection, identity verification, logistics tracking, and countless other scenarios, serving as a critical bridge between the physical and digital worlds.

Basic Structure of a QR Code

qr-error-correction-structure

A standard QR code consists of several core regions:

1. Finder Patterns

Three large square patterns made of nested blocks occupy three corners of the QR code. Scanners use these to quickly determine the QR code's position, size, and tilt angle. This is why QR codes can be read from any orientation โ€” once the scanner detects three finder patterns, it can establish the coordinate system.

2. Alignment Patterns

Starting from Version 2, smaller alignment patterns (a small nested square) appear within the code. They help correct distortion caused by curved surfaces or perspective transforms. Higher versions include more alignment patterns.

3. Timing Patterns

Alternating black-and-white module rows and columns connecting the finder patterns help the scanner determine the exact coordinate of each module.

4. Format Information

Stores the error correction level and mask pattern used by the current QR code, located in fixed positions around the finder patterns.

5. Data and Error Correction Area

The main body of the QR code, storing the encoded data and Reed-Solomon error correction codewords.

Data Encoding Process

Converting input data into a binary bitstream involves the following steps:

Step 1: Select Encoding Mode

QR codes support four encoding modes:

  • Numeric Mode: Digits 0-9 only, most efficient โ€” every 3 digits take 10 bits
  • Alphanumeric Mode: 0-9, A-Z, and selected symbols โ€” every 2 characters take 11 bits
  • Byte Mode: Arbitrary byte data (such as UTF-8 encoded text) โ€” each character takes 8 bits
  • Kanji Mode: Shift JIS encoded Japanese/Chinese characters โ€” each character takes 13 bits

Step 2: Encode Data

Encode the raw data into a binary bitstream based on the selected mode, prepending a mode indicator and character count.

Step 3: Error Correction Encoding

Generate error correction codewords from the data codewords using the Reed-Solomon algorithm, then interleave both and fill them into the QR code matrix.

Step 4: Masking

To avoid large uniform areas of black or white (which impede scanning), the QR code applies one of 8 mask patterns to the data area, selecting the one with the optimal penalty score.

Error Correction in Detail

qr-error-correction-ecc-levels

One of the QR code's greatest strengths is its error correction capability โ€” it can still be read correctly even when parts are obscured, worn, or contaminated. This relies on the Reed-Solomon error correction algorithm.

Four Error Correction Levels

LevelCorrection CapabilityData RecoveryBest For
L (Low)Low~7% recoverableHigh data volume, clean environments
M (Medium)Medium~15% recoverableGeneral use (recommended default)
Q (Quartile)High~25% recoverablePotential partial obstruction
H (High)Highest~30% recoverableHarsh environments, logo embedding

Error Correction Trade-offs

Higher error correction levels allocate more codewords to error correction, leaving less space for actual data. This means:

  • For the same data, higher correction levels require larger QR codes (higher versions)
  • For the same version, higher correction levels store less data

For example, Version 1 (21ร—21 modules) can store 41 digits at Level L, but only 17 digits at Level H.

Why QR Codes Can Embed Logos

This is a classic application of the error correction mechanism. Placing a logo in the center of a QR code effectively "destroys" the data modules in that area. As long as the obscured area doesn't exceed the recovery limit of the current error correction level, the scanner can still reconstruct the complete data from the error correction codewords. This is why QR codes with embedded logos typically use Level H error correction.

QR Code Versions

QR codes range from Version 1 (21ร—21 modules) to Version 40 (177ร—177 modules), totaling 40 versions. Each version increase adds 4 modules per side. Higher versions store more data, but the physical size must also increase to maintain scanning reliability.

In practice, most QR codes use Versions 1 through 10 (21ร—21 to 57ร—57), which is sufficient for common data like URLs, text, and contact cards.

Conclusion

The QR code's technical design balances information density, reading speed, and fault tolerance. Three-point finder patterns enable rapid multi-angle recognition, Reed-Solomon error correction ensures data recovery even with partial damage, and flexible encoding modes and version options let QR codes adapt to anything from a few characters to thousands. Understanding these underlying principles helps you make better parameter choices when generating QR codes.