EducationUpdated 6 min read

How QR codes work, from finder patterns to error correction

What's inside a QR code: the patterns a camera looks for, how your data is packed into modules, why a scuffed code still scans and what a scanner does.

Line drawing of a QR code lying flat with its three finder patterns marked, a sampling grid floating above it and a phone reading it

A QR code is a grid of dark and light squares, called modules, that stores your data as bits. Three corner squares tell a camera where the code is and which way up it sits.

Extra error-correction bytes let a phone rebuild the data when part of the code is scuffed or covered.

Why a square instead of stripes

A 1D barcode, like the UPC on a cereal box, stores data in bars along one line. A smudge across that line, or a camera held at the wrong angle, can ruin the scan.

A QR (Quick Response) code stores data in two dimensions, so it holds far more in the same area. It also reads at any rotation, because the three bullseye squares in its corners tell the decoder which way is up.

The grid

Real QR codes for the same URL at versions 1, 2 and 10 (21×21, 25×25 and 57×57 modules), finder patterns highlighted in blue
Real, scannable codes for qrdx.dev at Versions 1, 2 and 10 (21 × 21, 25 × 25 and 57 × 57 modules), with the finder patterns in blue.

The smallest QR code, Version 1, is 21 × 21 modules. Each version adds 4 modules per side, up to Version 40 at 177 × 177.

A bigger version holds more data, and the encoder picks the smallest one that fits your content.

Some modules never carry data. They form fixed patterns that help the scanner find and measure the code.

Finder patterns

The squares in the top-left, top-right and bottom-left corners are finder patterns. Each is 7 × 7 modules: a 3 × 3 dark core inside a light ring inside a dark ring, with a one-module light gap between it and the data.

A scanner looks for these first. From the three of them it works out the code's size, rotation and perspective, which is how your phone reads a sticker on a curved coffee cup.

Timing patterns

Two lines of alternating dark and light modules run between the finders, one across and one down. They work like a ruler printed into the code, so the decoder knows where each row and column of modules sits.

Alignment patterns

From Version 2 up, smaller 5 × 5 squares appear inside the code, and larger versions have more of them. They correct the position when the surface is curved or the photo is distorted, as on bottle labels and soft packaging.

The quiet zone

The standard asks for a blank margin of 4 modules on every side. Without it, nearby text or artwork blends into the code and the scanner can't find its edge.

How big should a QR code be? works out how much space the margin takes in print.

How the data is stored

Your content goes into the code as one stream of bits, in this order:

  1. a mode indicator, which says how to read the next chunk;
  2. a character count, which says how long that chunk is;
  3. the data itself;
  4. a terminator and padding, which fill the rest of the space;
  5. the error-correction codewords.

Data modes

The encoder picks the mode that stores your content in the fewest bits.

ModeWhat it holdsCost
NumericDigits only10 bits per 3 digits
Alphanumeric0-9, A-Z, space and $%*+-./:11 bits per 2 characters
ByteAny bytes, such as a URL or UTF-8 text8 bits per byte
KanjiShift JIS kanji13 bits per character

One code can mix modes, such as a run of digits in numeric mode followed by text in byte mode. Most URLs end up in byte mode, because alphanumeric mode has no lowercase letters.

Error-correction levels

Every QR code is made at one of four error-correction levels. A higher level lets more of the code be lost and still decode, but leaves less room for data: a Version 5 code holds 106 bytes at level L and only 44 at level H.

LevelRecovers aboutGood for
L7%Screens and clean labels
M15%General print
Q25%Print that may get scuffed; QRdx's default
H30%Codes with a logo, and signs that get dirty or worn, such as outdoor signs

Pick a level in the demo to see the trade-off on a real code, then cover part of it. The link stays the same; only the redundancy changes.

Error correction level

Level M can recover ~15% of damaged codewords. Same URL, yet the grid generally gets denser at higher levels: the extra modules carry the redundancy.

Why a torn code still scans

Line drawing of a QR code with a square patch of modules missing, read by a phone that shows a tick
A level H code with about 9% of it missing. It still decodes, because the error-correction bytes rebuild the lost data.

QR codes use Reed-Solomon error correction over GF(256), the field of the 256 possible byte values. The encoder computes extra bytes from your data, and the decoder uses them to rebuild modules that are missing or misread, up to the level's limit.

So a code with a scuffed corner, or a thumb over part of it, still gives back exactly the original data.

A logo in the middle is the same kind of damage. It's safe as long as the redundancy that's left covers the modules it hides.

Error correction can't fix a covered finder pattern, though. If the decoder can't find the code, it never gets as far as the repair.

Mask patterns

Once the data and error-correction bytes are on the grid, the encoder flips some of them with one of eight mask patterns (an XOR over the data area). Masking breaks up large blocks of one color and shapes that look like a finder, both of which confuse scanners.

The standard scores each mask with penalty rules, and the encoder keeps the one that scores lowest. That's why two generators can draw different patterns for the same link, and both codes are correct.

What your phone does when it scans

Five tiles in a row: a tilted QR code in a viewfinder, its three finder patterns marked, the code under a sampling grid, sampled module dots, and the decoded text qrdx.dev
From camera frame to URL: find the finders, flatten the grid, sample each module, then decode.

A scanner app works through roughly these steps:

  1. Capture a camera frame.
  2. Find the three finder patterns.
  3. Flatten the grid, undoing the angle and perspective (a homography).
  4. Decide whether each module is dark or light, with a threshold that adapts to the lighting.
  5. Read the format information, which holds the error-correction level and the mask. From Version 7 up, the version is encoded too.
  6. Undo the mask and repair the codewords.
  7. Split the bits into segments and decode each one.
  8. Hand the result to the phone: a link to open, a Wi-Fi network to join or a contact to save.

Every app takes its own shortcuts through these steps. That's why contrast, the quiet zone and module size still decide whether a code reads in a dim room, even with error correction to fall back on.

What this means for design

Keep the quiet zone. It's part of the standard, and a code printed flush against other artwork often won't scan.

Keep dark modules on a light background. Scanners sort modules by brightness, so light gray on white fails. The current standard allows light-on-dark codes, but some scanner apps still can't read them.

Test any code that carries a logo. The logo spends error correction, so check that the code still scans as well as how it looks.

The QRdx playground runs that check as you design. Its scan score decodes the code at three sizes through a model of a phone camera, and tells you what to change when a size fails.

Further reading

The QR code standard is ISO/IEC 18004. For something free to read, the ZXing project is a widely used open-source decoder, and QRdx's own encoder is open source in the qrdx package.

ShareXLinkedIn
Ritesh Bucha

Founder, QRdx

Ritesh Bucha is a designer and full-stack developer, and the founder of QRdx. Ritesh builds the QRdx web app, the qrdx library and the @qrdx/cli tool in the open on GitHub, and writes here about how QR codes work and how QRdx is made.

Read more

Line drawing of the same QR code printed at three sizes on stands, with a tape measure along the floor and a blue dimension line beside the largest

Education

How big should a QR code be?

Minimum QR code sizes by scanning distance and content, plus the quiet zone, contrast and error-correction rules that…

Ritesh Bucha8 min read
Line drawing of a chat window where an assistant calls the design_qr tool, beside a styled QR code on a stand

Education

How to make a QR code with ChatGPT or Claude

Image models draw QR codes that don't hold your link. Connect QRdx's free MCP server to ChatGPT or Claude for a real…

Ritesh Bucha5 min read
Line drawing of a printed QR code linked by a pipe to a redirect block, which points to a new web page while an old, dashed page stands behind it

Education

Dynamic vs static QR codes, and how to choose

A static QR code holds your content. A dynamic one holds a short link that redirects. How each works, what you give up…

Ritesh Bucha6 min read