# How QR codes work: modules, finder patterns and error correction

> A plain-language tour of what the squares in a QR code actually do: how your camera finds the grid, reads the data, and repairs damage with built-in error correction.

A QR code is just a grid of black and white squares that a camera reads as a long string of ones and zeros. The three big squares in the corners tell your phone where the code is and which way it faces, while the rest of the pattern carries your data plus built-in backup copies that let the code survive scratches, stains and stickers. Here is how each piece works, in plain language.

## From camera image to grid of modules

When you point your camera at a QR code, the app's first job is to turn a photo into something a computer can process. It converts the image to black and white by setting a brightness threshold: everything darker than the line becomes black, everything lighter becomes white. Blurry or shadowy photos make this step harder, which is why a crisp, well-lit code scans more reliably.

The smallest square in the pattern is called a module. To the reader, each module is a single bit of information — a dark module is one binary value, a light module the other. Everything below, from the big corner squares to the data itself, is just modules arranged on a grid.

Around the code sits a blank margin called the quiet zone, four modules wide by convention. It gives the camera a clean edge to detect and separates the code from busy backgrounds. A code printed right up against other graphics is harder to scan for exactly this reason.

## The three finder patterns

In three corners — top-left, top-right and bottom-left — you will find the QR code's most distinctive feature: a large square made of nested rings, with a dark outer ring, a light ring and a solid dark 3×3 centre. These are the finder patterns, and they solve the first problem every scanner faces: where is the code, and which way round is it?

A scanner finds them by sliding a line across the image and looking for a very specific rhythm. A line through the middle of a finder pattern crosses dark, light, dark, light, dark with widths in the ratio 1:1:3:1:1 — one module of dark, one of light, three of dark, then one and one again. That signature is unusual enough to stand out from almost anything else in a photo.

Why three finders and not four? Three corners are enough to pin down a square, and the missing corner carries meaning: it tells the reader which way is "up". Even if you scan a code upside down or sideways, the reader knows exactly how to rotate the grid before decoding it.

## Timing and alignment patterns

Knowing where the corners are is not quite enough. If the code was photographed at an angle or printed on a curved surface, the grid in between may be stretched or skewed. Two more structures keep it honest.

The timing pattern is a dashed line of alternating dark and light modules running between the finder patterns — one along the top, one down the left side. It works like a ruler: by counting the alternations, the reader confirms the exact size of the modules and how the grid should be spaced across the whole code.

The alignment pattern is a smaller nested square, five modules across, that appears from version 2 onward, placed toward the bottom-right. Larger codes carry several of them. Each one acts as an extra landmark, letting the reader measure and correct distortion in its part of the grid — essential when a code wraps around a bottle or sits on a slightly crumpled label.

## Versions 1 to 40

QR codes come in 40 sizes, called versions. Version 1 is a 21×21 grid of modules. Each version up adds four modules per side, so version 2 is 25×25, version 3 is 29×29, and so on up to version 40 at 177×177.

A bigger grid means more room for data. As a rule of thumb, the largest versions can hold around 7,000 digits, while a short URL fits comfortably in a much smaller code. The exact capacity also depends on what you encode — numbers pack tighter than text — and on the error correction level you choose.

This is also why generated codes vary so much in look. Encoding tools pick the smallest version that fits the content, so a brief link produces a sparse, chunky code while a long one produces a dense, fine-grained pattern.

## Data and error-correction codewords

Once the structural patterns have claimed their space, the remaining area holds the payload. The bits are grouped into units of eight modules called codewords — each one is a single byte of information.

There are two kinds. Data codewords carry your actual content: the URL, text or whatever else the code encodes. Error-correction codewords are spares of a clever kind, computed from the data using a branch of mathematics called Reed–Solomon coding — the same family of techniques that protected data on CDs and DVDs. The reader uses them to check the data and repair anything missing.

QR codes offer four error correction levels, named L, M, Q and H. Roughly speaking, they can restore about 7%, 15%, 25% or 30% of the codewords respectively. The trade-off is space: the higher the level, the more of the code is reserved for spares and the less is left for data, so the same content may need a larger version.

This is why a QR code with a logo overlaid in the middle can still scan: the designer chose a high error correction level and let the spare codewords absorb the covered area.

## Masking

Left to chance, the raw data could produce an awkward-looking grid: large blank patches, or clusters of squares that accidentally mimic a finder pattern and confuse the scanner. The fix is masking.

The encoding tool takes one of eight predefined mask patterns — checkerboards, horizontal or vertical stripes and similar repeating designs — and flips every module where the mask has a dark square. The data itself does not change; only its appearance does, and the flip is perfectly reversible.

The tool tries all eight masks, scores each result with penalty rules (long runs of the same colour, finder-pattern lookalikes, overly unbalanced dark and light areas) and keeps the one with the lowest penalty. Which mask was used is recorded in a small strip of format information next to the finders — written twice for safety, so a scuffed corner does not leave the reader guessing.

This is also why the same link encoded by two different tools can produce two visually different codes. Both are correct; they simply chose different masks.

## A small worked example

Take the text "HI". The encoder first writes a few setup bits — what kind of data follows and how long it is — and then the content itself. Each character is stored as eight bits: H becomes 01001000 and I becomes 01001001. Those sixteen bits become sixteen modules on the grid, one bit each.

The bits are laid into the grid in two-column strips that snake up and down from the bottom-right corner, skipping over the finder, timing and format areas. After the data comes a block of error-correction codewords, computed from it and tucked in alongside. Finally, the chosen mask is applied, flipping some of the modules to break up any unlucky patterns.

That is the whole recipe: structure first, then data, then spares, then a mask. Every QR code you have ever scanned is this same procedure repeated at a larger scale.

## The key takeaway

A QR code is a self-describing picture. The finder patterns say "here I am, and this way up"; the timing and alignment patterns straighten the grid; the version sets the size; the codewords carry your data with built-in spares; and masking keeps the whole pattern readable. Next time you scan one — or generate your own at QRCodeMax.Vip — zoom in and you will spot every one of these parts working together.
