Algorithm Architecture

How QR Code Error Correction Works: Reed-Solomon Mathematics Explained

Ever wondered how a QR code can still scan flawlessly when torn, stained with coffee, partially smudged, or covered in the middle by a company brand logo? The secret lies in Reed-Solomon polynomial error correction.

Four QR codes of the same address at error correction levels L, M, Q and H, each with 7, 15, 25 or 30 percent of its area blacked out to show how much damage the level can recover

1. What is Reed-Solomon Error Correction?

Invented in 1960 by mathematicians Irving S. Reed and Gustave Solomon, Reed-Solomon (RS) error correction is a non-binary cyclic error-correcting algorithm widely used in space telecommunications (NASA Voyager), CD/DVD optical discs, satellite television, and the ISO/IEC 18004 standard for QR codes.

Instead of merely detecting errors (like a simple parity bit or CRC checksum), Reed-Solomon code generates redundant mathematical parity blocks capable of pinpointing the exact location of damaged byte modules and reconstructing the original payload data without re-requesting the transmission.

2. The 4 QR Code Error Correction Levels

The ISO/IEC 18004 standard specifies four selectable Error Correction Code (ECC) levels. Each level represents the percentage of total codewords that can be obliterated or obscured before the code becomes unreadable:

ECC Level Recovery Capacity Module Density Recommended Use Case
Level L (Low) ~7% of data Least dense (fewest squares) Digital screens, high-density payloads where QR must remain small.
Level M (Medium) ~15% of data Balanced standard Default for general URLs, packaging, flyers, and marketing print.
Level Q (Quartile) ~25% of data Moderately dense Best for Custom Logos, table tents, and environments prone to wear.
Level H (High) ~30% of data Highest density (most squares) Outdoor billboards, industrial tags, heavy physical abuse environments.

3. How Logo Embedding Leverages Error Correction

When you place a logo or icon in the center of a QR code, the scanner's optical sensor interprets the logo as physical surface damage or missing modules.

Because Error Correction Level Q can recover up to 25% of corrupted data and Level H can recover up to 30%, the Reed-Solomon mathematical decoder calculates the missing modules underneath the logo and reconstructs the original URL in milliseconds.

The Golden Rules for Logo QR Codes:

  • Maximum Area: Never let a logo occupy more than 20% to 25% of the total QR code area.
  • Protect the 3 Finder Corners: Never allow your logo to cover or touch the three large square eye finders in the top-left, top-right, and bottom-left corners.
  • Use White Margins: Always draw a solid white protective margin around your logo to prevent surrounding QR modules from blending into the logo graphic.
  • Automatically Switch to Level Q or H: qr-code.love automatically upgrades your error correction level to Level Q or H whenever you upload a custom logo.

4. The Mathematical Pipeline in Galois Field GF(256)

The encoder that runs in your browser does its arithmetic in a finite field with 256 elements, written GF(28) or GF(256). Every byte is an element of the field, and multiplication is defined modulo this primitive polynomial:

P(x) = x8 + x4 + x3 + x2 + 1   (0x11D in hexadecimal)

The data bytes are treated as the coefficients of a polynomial D(x). The engine multiplies it by xE, where E is the number of error correction codewords the level calls for, and divides the result by a fixed generator polynomial G(x) for that level. The remainder of that division is the parity: E bytes that are placed into the symbol after the data.

5. The 8 ISO Masking Patterns & Penalty Scoring

Once error correction codewords are calculated, placing raw binary bytes into a grid could accidentally create large patches of all-black or all-white modules, or false "finder pattern" shapes that confuse optical camera sensors.

To solve this, the ISO/IEC 18004 standard applies 8 candidate mathematical XOR mask patterns across the grid. The engine scores each masked candidate using a strict penalty formula:

  • Penalty 1 (Runs of Adjacent Modules): Consecutive runs of 5 or more same-colored modules add 3 points plus 1 for each module beyond five.
  • Penalty 2 (Blocks of 2x2 Modules): Every solid 2x2 square adds 3 penalty points.
  • Penalty 3 (False Finder Patterns): Any module sequence matching 1:1:3:1:1 adds 40 penalty points.
  • Penalty 4 (Dark/Light Ratio Imbalance): Deviation from a 50/50 balance adds proportional penalty points.

The mask pattern that produces the lowest cumulative penalty score is chosen and encoded into the format information bits surrounding the finder patterns.

6. Real-World Environmental Abuse Resilience

Choosing the right error correction level is crucial for physical materials exposed to weathering or wear:

Environmental Condition Recommended ECC Typical Damage Risk
Outdoor Billboards & Metal Signs Level H (30%) UV fading, rain streaks, rust, and bird droppings.
Restaurant Table Tents & Menus Level Q (25%) Food spills, thumb smudges, and alcohol sanitizers.
Product Packaging & Labels Level M (15%) Minor surface friction and handling scuffs.
Digital Screens & TV Broadcast Level L (7%) Zero physical wear; prioritizes lowest pixel count.

7. Data and error correction codewords by version

Each version has a fixed number of codewords, eight bits each, and the level decides how many carry your data and how many carry recovery data. The first three versions look like this.

VersionTotalL (data + EC)MQH
12619 + 716 + 1013 + 139 + 17
24434 + 1028 + 1622 + 2216 + 28
37055 + 1544 + 2634 + 3626 + 44

The data codewords are not all payload. The first bits hold the mode indicator and the character count, which in byte mode take twelve bits up to version 9 and twenty from version 10. That is why a version 1 symbol at level L holds 17 bytes of your data rather than 19.

At level H the recovery data outweighs the payload from version 1 onward. That is the trade the logo option makes when it raises the level: fewer bytes of room, in exchange for a symbol that still reads with part of it painted over.

Sources & further reading

Generate Error-Corrected QR Codes

Select your preferred Reed-Solomon level (L, M, Q, H) and embed your brand logo with zero server logging.

Open All-in-One Generator