Developer

QR codes: what is actually encoded, and how to make one that scans

There is no database behind a QR code. Everything it knows is printed in the squares, which is why a long URL makes a code nobody can scan.

4 minute read

A QR code is not a link to a record somewhere. It is the text itself, encoded as black and white squares with enough redundancy to survive being scuffed. Nothing is looked up, nothing phones home, and the code works forever offline. That one fact explains most of what follows.

Size is driven by content length

The grid is made of modules, the individual squares. QR codes come in 40 versions, from 21×21 modules up to 177×177. The more characters you encode, the higher the version, the more modules, and the smaller each module becomes at a fixed print size.

Small modules are harder for a camera to resolve. So a code encoding a 200-character URL printed on a business card is harder to scan than one encoding 30 characters at the same physical size. This is not a quality setting, it is geometry.

Encoding mode matters too, because the specification packs different character sets differently:

Mode Characters allowed Bits per character
Numeric 0-9 about 3.3
Alphanumeric 0-9, A-Z, space, $%*+-./: about 5.5
Byte Anything, including lowercase 8

Alphanumeric mode has no lowercase. So HTTPS://EXAMPLE.COM/OFFER encodes in alphanumeric mode at 5.5 bits per character, while https://example.com/offer falls into byte mode at 8. The same URL, a meaningfully smaller code.

Error correction and the logo in the middle

Every QR code carries Reed-Solomon error correction, at one of four levels.

Level Recoverable Cost
L about 7% Smallest code
M about 15% The usual default
Q about 25%
H about 30% Largest code

This is why a code still scans with a coffee ring on it, and it is why you can put a logo in the centre. The logo is damage, and the error correction repairs it.

The rule of thumb is to use level H if you are covering the middle, and keep the logo under about 20% of the code area even though H tolerates 30%. Leave headroom for real-world damage on top of the damage you added deliberately.

The quiet zone is not optional

The specification requires a blank margin of four modules on all sides. Scanners use it to find where the code ends.

Placing a code flush against a coloured background, a border, or the edge of a card is one of the most common reasons a code fails to scan, and it looks like nothing is wrong. Leave the margin.

Two related points. Contrast must be dark-on-light, and inverting to light-on-dark breaks many scanners. And the dark modules should be dark: a mid-grey code on a cream background may pass a designer's eye and fail a phone camera in a dim restaurant.

Beyond URLs

The content is just text, so the meaning comes from conventions the scanning app recognises.

WIFI:T:WPA;S:NetworkName;P:password123;;

That is the Wi-Fi format, and it is why a café can put a card on the table that joins you to the network. It also means the password is printed in plain text on the wall, readable by anyone who scans it, which is fine for a guest network and not for anything else.

The same pattern covers contact cards, calendar events, phone numbers and plain text. QR generators offer these as presets, but underneath they are all just strings.

Practical sizing

The working guideline is that the code should be about one tenth of the scanning distance. Scanned from 30cm, a 3cm code is comfortable. On a poster read from 3 metres, you need 30cm.

And the rest of the checklist:

  1. Shorten the URL before generating anything.
  2. Choose error correction based on whether a logo is going on it.
  3. Keep the four-module quiet zone.
  4. Print it and scan it, from the actual distance, on a cheap phone, in poor light.

Step four catches almost everything. A code that scans on your screen at arm's length tells you very little about a code on matte card under a restaurant's lighting.

Before printing a code, scan it with two different phones at the size it will actually be printed. The QR generator lets you raise the error-correction level for codes that will be printed small, laminated or partly covered by a logo.

Further reading

Do it hereQR Code GeneratorGenerate QR codes for links, Wi-Fi, contact cards and UPI paymentsOpen

Written for NextTool. Every statement about a tool is checked against that tool's code, and corrections are dated above. How guides are written

qrencodingurl