← Iris

QR Code
Error correction
Zoom 8
Version: 1
Size: 21×21
Bytes: 0
Mode: Byte

How QR codes encode data

A QR code is a two-dimensional barcode invented by Denso Wave in 1994 for tracking automotive parts. It encodes data as a grid of dark and light modules (squares). The encoding process involves choosing a data mode (numeric, alphanumeric, byte, or kanji), converting the input into a binary bitstream, splitting it into codewords, computing Reed-Solomon error correction codewords, and finally placing all of these bits into the matrix according to a specific interleaving pattern. The result is a symbol that any camera can decode — even when partially obscured or damaged.

Reed-Solomon error correction

The magic that makes QR codes resilient is Reed-Solomon error correction, the same mathematics used in CDs, DVDs, deep-space communication, and RAID storage. After encoding the data bytes, the generator computes additional parity bytes by treating the data as coefficients of a polynomial and dividing by a generator polynomial over a Galois field (GF(256)). These extra bytes allow the decoder to reconstruct the original data even if some modules are unreadable. At the highest error correction level (H), up to 30% of the code can be destroyed and the data will still survive. This is why QR codes can have logos placed in their center — the error correction recovers the obscured modules.

Anatomy of a QR code

Toggle anatomy mode above to see the regions color-coded. The three large squares in the corners are finder patterns — they let the scanner determine the code's orientation and boundaries. The alternating dark-light strips connecting the finders are timing patterns that establish the module grid spacing. Larger versions include alignment patterns (smaller squares) to correct for perspective distortion. Format information strips adjacent to the finders encode the error correction level and mask pattern. The remaining modules carry the actual data and error correction codewords, interleaved in a specific pattern that zigzags right-to-left across the matrix. A masking pattern is applied to the data area to ensure no large uniform regions exist, which would confuse scanners.