How a QR Code Actually Encodes Data (Decode One by Hand)

A QR code looks like random noise. It is not — every region has a defined job, the apparent randomness is deliberately manufactured, and with a few rules you can read the version and error correction level of any code by eye. This page explains what each part does and why the design is as good as it is.

The structure in one paragraph

Three corner squares tell the scanner where the code is and which way up. A line of alternating modules gives it a grid to measure against. A ring around the corners stores the error correction level and mask. Everything else is data and Reed-Solomon parity, laid out in a zigzag from the bottom-right — then XORed with a pattern chosen to avoid large blank areas.

The fixed regions

RegionWhereJob
Finder patternsThree corners, 7×7 eachLocate the code and establish orientation
SeparatorsAround each finderOne blank module so the finder is unambiguous
Timing patternsRow 6 and column 6Alternating modules that establish the grid
Alignment patterns5×5 squares, version 2+Correct for perspective distortion
Format informationBeside the findersError correction level and mask, stored twice
Version informationVersion 7+The size, stored twice
Quiet zone4 modules all roundBlank margin — required, not decorative
Data and parityEverything elseThe payload plus Reed-Solomon correction

Why the finder pattern is that shape

The three corner squares are a concentric arrangement: a 7×7 dark square, a 5×5 light square inside it, a 3×3 dark square inside that. Draw a line through the centre in any direction — horizontal, vertical, or diagonal — and you cross dark and light regions in the ratio 1:1:3:1:1.

█████████████ ← 7 modules of the outer square █ █ █ █████ █ ← 3 modules of the inner square █ █████ █ █ █████ █ █ █ █████████████ Scanning across the centre row: 1 dark : 1 light : 3 dark : 1 light : 1 dark

That ratio was chosen because it is rare in natural images. A scanner can sweep lines across a video frame at high speed looking only for that proportion, and it will almost never produce a false positive on a photograph, a page of text or a face. This is why QR scanning feels instant while other barcode formats need careful aiming.

Using three corners rather than four is the second piece of the design. Three points define orientation unambiguously — the scanner knows which corner is missing and can therefore work out rotation. A code can be read upside down, at an angle, or in a mirror, and it costs one fewer pattern.

Reading the version

QR versions run from 1 to 40, and each step adds 4 modules per side:

modules per side = 4 × version + 17 Version 121 × 21 Version 225 × 25 Version 537 × 37 Version 1057 × 57 Version 40177 × 177

Count the modules along one edge, subtract 17, divide by 4. You now know the version — and therefore roughly how much data it holds. It is the one thing you can read from a QR code without any tools.

Encoding modes

QR codes support four modes, and choosing the right one changes capacity dramatically:

ModeCharacter setBits per characterCapacity (v40)
Numeric0–93.337,089 digits
Alphanumeric0–9, A–Z, space, $%*+-./:5.54,296 characters
ByteAny 8-bit data82,953 bytes
KanjiShift-JIS131,817 characters

Numeric mode packs three digits into ten bits rather than the twelve that four bits each would need. Alphanumeric packs two characters into eleven bits.

✅ Uppercase URLs produce smaller codes

Alphanumeric mode has no lowercase letters, so https://example.com/page must use byte mode at 8 bits per character. Written as HTTPS://EXAMPLE.COM/PAGE it fits alphanumeric mode at 5.5 bits — roughly 30% fewer bits, which often means a smaller version and visibly larger, easier-to-scan modules.

Domain names are case-insensitive so this is safe for the host portion. Paths are not case-insensitive on most servers, so only apply it where you control the URL and know uppercase paths resolve.

Reed-Solomon error correction

This is the part that makes QR codes practical in the physical world, where things get creased, smudged and partially obscured.

LevelRecoversCapacity costUse for
L (Low)~7%Smallest codeClean digital display
M (Medium)~15%ModestThe usual default
Q (Quartile)~25%NoticeablePrint, or a small logo
H (High)~30%Largest codeIndustrial, or a large logo

Reed-Solomon works by treating the data as coefficients of a polynomial and adding extra values computed from it. Given enough surviving values, the original polynomial — and therefore the original data — can be reconstructed algebraically. It is the same family of codes used on CDs, in deep-space communication, and in RAID storage.

The important consequence: the correction is distributed across the whole code, not stored in one place. Damage anywhere is recoverable up to the level's limit. This is what allows a logo in the centre — those modules are simply treated as errors.

⚠️ Do not spend the whole error budget on decoration

Level H tolerates about 30% loss, and a logo covering 25% leaves only 5% for real-world damage — a crease, a smudge, a reflection, poor lighting. The code scans perfectly on your screen and fails on a printed flyer that has been in someone's pocket.

Keep decorative coverage under about 15% even at level H, and always test the printed article rather than the design file.

Masking: why it looks random

Here is the step that surprises most people. After the data and parity are placed, the encoder XORs the whole data region with a repeating pattern.

The reason is that raw encoded data often produces awkward results — a large blank area where the data happened to be mostly zeros, or an accidental sequence resembling a finder pattern. Both confuse scanners badly.

So the encoder generates the code eight times, once with each of eight defined mask patterns, and scores each result against four penalty rules:

PenaltyPenalisesWhy it matters
Rule 1Runs of 5+ same-colour modulesLong runs are hard to count accurately
Rule 22×2 blocks of one colourSolid areas lose grid alignment
Rule 3Patterns resembling a finderCauses false detection
Rule 4Dark/light imbalanceSkews the scanner's brightness threshold

The lowest-scoring mask wins, and which one was used is recorded in the format information so the decoder can reverse it. The visual noise is therefore engineered: a QR code looks random because randomness is precisely what scans most reliably.

This also answers a common question — two encoders producing visibly different codes for identical text are simply making different mask choices, and both are valid.

How the data is laid out

Data is placed in two-module-wide columns, starting from the bottom-right, moving upward in a zigzag, then down the next pair of columns, alternating direction. Fixed patterns are skipped and the flow continues around them.

// Direction of travel ↑ ↑ ↓ ↓ ↑ ↑ │ │ │ │ │ │ ← ← ┘ └ ← ← ┘ └ ← ← ┘ └ start here (bottom right) // Bits fill each 2-wide column pair, right then left, // alternating up and down. Fixed regions are stepped over.

The upward-from-bottom-right start is inherited from the original specification and is arbitrary in itself — what matters is that it is deterministic, so any decoder can retrace it.

Micro QR and other variants

VariantDifferenceUse
Micro QROne finder pattern, 11×11 to 17×17Small parts, very limited data
rMQRRectangularNarrow spaces on packaging
Model 1The original 1994 designObsolete
Frame QRDefined space for artworkMarketing
iQRHigher density, rectangular optionIndustrial; limited support

Designing codes that actually scan

  1. Keep the quiet zone. Four modules of blank margin on all sides is part of the specification, not padding. Codes that fail to scan against a busy background are usually missing it.
  2. Dark on light, always. Scanners expect dark modules on a light background. Inverted codes fail on many readers.
  3. Maintain contrast. Aim for a ratio of at least 4:1 between module and background. Pale grey on white does not work in real lighting.
  4. Size for distance. A useful rule is width ≥ distance ÷ 10 — a code read from 2 metres needs to be at least 20 cm across.
  5. Shorten the URL. Fewer characters means a lower version, which means larger modules at the same physical size.
  6. Avoid red on white. Some scanners use red illumination, against which red modules have very little contrast.
  7. Test the real thing — printed, at the actual size, under the lighting where it will be used, on several phones.

💡 Why QR codes won

Denso Wave created the format in 1994 to track car parts, and holds patents on it. They chose to publish the specification openly and have never enforced those patents against implementers.

Competing 2D barcode formats of the era were proprietary and licensed. That single decision is the main reason QR codes are in every phone camera and the alternatives are not — the technology was comparable, and the licensing was not.

Generate or decode a QR code

Create codes with your choice of error correction level, or decode one from an image — entirely in your browser, nothing uploaded.

Open the QR Generator →

Summary

  • The 1:1:3:1:1 finder ratio is rare in nature, which makes detection fast and reliable.
  • Three corners, not four — that asymmetry is what encodes orientation.
  • Version = (side modules − 17) ÷ 4. You can read it by counting.
  • Uppercase alphanumeric is 30% denser than byte mode.
  • Reed-Solomon distributes correction across the code, which is what allows logos.
  • Do not spend the whole error budget on decoration — leave room for real damage.
  • The random appearance is engineered by masking, and the mask is chosen by scoring.
  • The quiet zone is mandatory, and its absence is the most common scanning failure.

Frequently Asked Questions

Why do QR codes have three big squares in the corners?

They are finder patterns, and their ratio of dark to light along any line through the centre is 1:1:3:1:1 — a proportion chosen because it almost never occurs by chance in natural images. A scanner sweeps lines across the frame looking for it. Three corners rather than four is what tells the scanner which way up the code is.

Can a damaged QR code still be read?

Yes. QR codes carry Reed-Solomon error correction at one of four levels, the highest of which recovers from about 30% of the code being unreadable. This is what allows a logo to be placed in the middle — the covered modules are treated as errors and reconstructed.

Why do two QR codes for the same text look different?

Because of masking. After the data is placed, the encoder tries eight different XOR patterns and picks whichever produces the most balanced result, avoiding large blank areas that confuse scanners. Different encoders may choose differently, and the mask used is recorded in the format information.

How much data fits in a QR code?

Version 40 at the lowest error correction holds up to 7,089 digits, 4,296 alphanumeric characters, or 2,953 bytes. In practice, a code that dense needs to be printed large and scanned closely. For real-world use, keeping URLs under about 300 characters keeps the code comfortably scannable.

Are QR codes patented?

The format was created by Denso Wave in 1994 and they hold patents, but they chose to make the specification open and have never exercised those rights against implementers. That decision is the main reason QR codes became universal while competing 2D barcode formats did not.

P

Written by Paras

We build free, browser-based file tools and write the reference material we wish existed when we were looking things up. Spotted an error? Tell us and we will fix it.