At first glance, a QR code is just a mess of black squares on a white background. But inside that seemingly random pattern is a precisely engineered system capable of storing thousands of characters, surviving 30% physical damage, and being decoded in milliseconds from any angle. Here is how every piece works.

The Anatomy of a QR Code

A QR code is divided into functional zones. Each zone has a specific job. Understanding them is the key to understanding how the whole system works together.

1. Finder Patterns

The three large squares in the top-left, top-right, and bottom-left corners are called finder patterns. They are always identical: a 7x7 black square, with a 5x5 white square inside it, with a 3x3 black square inside that. A scanner searches for these three patterns first. Their consistent size and position tell the scanner the code's boundaries, its orientation (which way is up), and how large each individual module (the small squares making up the rest of the code) is.

The bottom-right corner has no finder pattern — instead, it has an alignment pattern (in larger QR versions), which helps correct for distortion when the code is photographed at an angle.

2. Timing Patterns

Running horizontally and vertically between the finder patterns are alternating black-and-white strips called timing patterns. They help the scanner establish the coordinate grid of the entire QR matrix, so it can precisely locate every module even if the image is slightly blurred or distorted.

3. Format Information

Immediately adjacent to the finder patterns is the format information strip. This tiny region encodes two critical pieces of metadata: the error correction level being used, and the mask pattern applied to the data (more on both below). The format information is stored twice in the QR code for redundancy.

4. Data and Error Correction Region

The rest of the QR code — everything outside the functional patterns — stores the actual encoded data plus error correction codewords. This is where your URL, text, or vCard lives.

How Data Is Encoded

QR codes support four encoding modes, each optimized for different types of data:

ModeCharactersMax capacity (version 40)
Numeric0-9 only7,089 characters
Alphanumeric0-9, A-Z, space, $%*+-./:4,296 characters
Binary (byte)Any 8-bit data (including UTF-8)2,953 bytes
KanjiJapanese double-byte characters1,817 characters

The encoder selects the most compact mode for your data automatically. A URL containing only alphanumeric characters will be encoded more efficiently than one with lowercase letters (which require binary/byte mode). This is why shorter URLs produce smaller, less dense QR codes.

Versions and Sizes

QR codes come in 40 versions. Version 1 is a 21x21 module grid; each subsequent version adds 4 modules to each side, making Version 40 a 177x177 grid. More modules means more data capacity — but also a more visually complex code that requires higher print quality to scan reliably.

Most QR codes you see in everyday life are Version 3 through Version 10. A standard URL QR code is typically Version 3-5 (29x29 to 37x37 modules).

Error Correction: The Genius of Reed-Solomon

This is arguably the most impressive feature of QR codes. Reed-Solomon error correction (the same algorithm used in CDs, DVDs, and deep-space communications) allows a QR code to be decoded even when part of it is missing, dirty, or damaged.

QR codes offer four error correction levels:

LevelRecovery CapabilityBest For
L (Low)~7% damageClean, indoor environments
M (Medium)~15% damageGeneral use
Q (Quartile)~25% damageIndustrial / outdoor use
H (High)~30% damageLogo overlay, harsh conditions

Higher error correction means more redundant data is stored, which requires more modules, which produces a larger, denser code. This is the trade-off: a QR code with a logo overlaid on it requires H-level error correction because the logo obscures some of the data. The redundant error correction codewords fill in the missing information.

Reed-Solomon doesn't just detect errors — it actively corrects them. The algorithm can figure out exactly which codewords are wrong and reconstruct the original data without any retransmission.

Masking: Why QR Codes Look "Random"

After the data is encoded, the QR code specification applies one of eight mask patterns to the data region. Each mask pattern XORs the data modules with a different mathematical formula. The encoder tests all eight masks and chooses the one that produces the most balanced distribution of black and white modules.

Why? Because QR code scanners rely on the alternating black-and-white timing patterns to establish the grid. If large sections of the data region happened to be all-black or all-white, the scanner could lose its grid reference. Masking ensures visual variety, making every QR code look somewhat random even when encoding predictable data.

The mask pattern used is stored in the format information strip so the decoder knows which mask to reverse when reading the code.

How Your Phone Decodes It

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

  1. Image capture: The camera grabs a frame
  2. Binarization: The image is converted to pure black and white using adaptive thresholding
  3. Finder pattern detection: The algorithm searches for the 1:1:3:1:1 ratio that characterizes finder patterns
  4. Perspective correction: The code's orientation and any lens distortion are corrected mathematically
  5. Format information reading: Error correction level and mask pattern are decoded
  6. Data extraction: All data modules are read and the mask is reversed
  7. Error correction: Reed-Solomon corrects any damaged or misread codewords
  8. Decoding: The binary data is converted back to text/URL/etc
  9. Action: Your OS presents the decoded content

Why Any Angle Works

Traditional barcodes require precise horizontal alignment. QR codes don't, because the three finder patterns define a geometric transformation that can be inverted regardless of rotation, tilt, or perspective. Even if you're scanning at a 45-degree angle, the three-corner finder structure gives the decoder enough geometric information to reconstruct the flat, aligned grid.

The Quiet Zone

One detail that trips up many DIY QR code placements: the quiet zone. QR codes require a border of at least 4 modules (white space) around the entire code. This gives the scanner's edge-detection algorithm room to find the finder patterns. Print a QR code right to the edge of a label or flush against a border, and it may fail to scan — not because the code is broken, but because the scanner can't find where the QR code ends and the rest of the world begins.

Capacity in Practice

How much can a QR code actually hold? Here are some real-world examples at Medium (M) error correction:

Try It Yourself

Now that you know how QR codes work, generate one and see the encoding in action. URL, WiFi, vCard, payment — all free.

Generate a QR Code →