QR Codes for Developers: Error Correction, Size and Scannability

How QR codes store data, what the L, M, Q and H error correction levels trade off, and the practical rules for printing codes that scan the first time.

QR codes went from niche to everywhere in a few years. Restaurant menus, event tickets, payment terminals, product packaging and conference slides all use them. Generating one takes seconds. Generating one that scans reliably on the first try, from a poster across a room or a label on a curved bottle, takes a little understanding.

This guide covers how QR codes store data, what error correction actually buys you, and the practical rules for size, contrast and content. You can try every setting in the QR Code Generator.

A brief history

The QR code was invented in 1994 by Masahiro Hara and his team at Denso Wave, then part of the Toyota group, to track car parts on production lines. One-dimensional barcodes held too little data and had to be scanned in a particular orientation. "QR" stands for Quick Response.

Denso Wave held the patent but chose not to enforce it, which let the format spread freely. It became an ISO standard, ISO/IEC 18004, in 2000. The real turning point for consumers came when phone cameras started scanning QR codes natively: Apple added it to the iOS 11 Camera app in 2017, and Android followed in its default cameras around the same period. No separate scanning app was needed any more.

What is inside a code

A QR code is a grid of dark and light modules. Several structures help a scanner find and read it:

  • Finder patterns: the three large squares in the corners, which tell the scanner where the code is and how it is rotated.
  • Alignment patterns: smaller squares that help correct for distortion on larger codes.
  • Timing patterns: alternating lines that set the module grid.
  • Format and version information: which error correction level and mask are used.
  • Data and error correction codewords: everything else.

Codes come in 40 versions, from 21 x 21 modules (version 1) to 177 x 177 (version 40). The more data you encode, the higher the version and the denser the code.

Data is stored in modes optimized for different content: numeric, alphanumeric (upper-case letters, digits and a few symbols), byte (arbitrary data, usually UTF-8 text), and kanji. A version 40 code holds up to 7,089 digits or 2,953 bytes at the lowest error correction level, but codes that large are impractical to scan.

Error correction: L, M, Q and H

QR codes use Reed-Solomon error correction, the same family of codes used on CDs and in deep-space communication. Extra codewords let the scanner reconstruct data even when part of the code is dirty, damaged or covered.

LevelApproximate recoveryUse when
L7%Clean, screen-displayed codes where size matters
M15%A sensible default for most print
Q25%Industrial labels, outdoor use, rough surfaces
H30%A logo is placed over the center, or heavy wear is expected

The trade-off is density. For the same content, higher levels need more modules, so the code becomes busier and must be printed larger to stay readable. Choose H only when you need it.

Size and scanning distance

A widely used rule of thumb in the print industry is a 10:1 ratio: the scanning distance should be no more than about ten times the width of the code. A code meant to be scanned from one meter away should be roughly 10 cm wide. For a business card or product label scanned at arm's length, 2 to 2.5 cm is a common practical minimum.

Content matters as much as print size. A short URL produces a low-version code with large modules that scan easily. A long URL full of tracking parameters produces a dense code that needs to be printed much bigger. If you control the destination, a short, clean URL is the single best improvement you can make.

The quiet zone

The standard specifies a blank margin, the quiet zone, of four modules around the code. It tells the scanner where the code ends and its surroundings begin. Codes printed right up against text, borders or busy backgrounds are a leading cause of scan failures. The generator's border setting controls this margin; do not set it to zero for print.

Contrast and colors

Scanners look for dark modules on a light background. You can use brand colors, but:

  • Keep strong contrast, a dark foreground on a light background.
  • Avoid inverted codes (light on dark). Many modern scanners read them, but not all do.
  • Avoid low-contrast pairings like mid-grey on white or red on black.
  • Do not put gradients or photos behind the modules.

Test with more than one phone, in the lighting where the code will actually be used.

Static and dynamic codes

The code itself simply contains your text. If it contains a URL, it works as long as that URL works; nothing about a QR code expires. "Dynamic" QR services encode a short redirect URL they control, so the destination can be changed later and scans can be counted. The trade-off is that the code depends on that service staying in business. For long-lived print, point the code at a URL on a domain you own, and redirect from there if you need flexibility.

Security considerations

Because people cannot read a QR code before scanning, attackers have used fake codes stuck over real ones on parking meters and posters to send people to phishing sites, a tactic sometimes called "quishing". If you deploy codes in public places, use a recognizable domain and check periodically that your codes have not been covered.

How the RedBison generator works

The RedBison QR Code Generator lets you set size, error correction (L, M, Q, H), border, style and colors, and download the result as PNG or JPEG. The image itself is produced by the third-party QR Server API (api.qrserver.com), so the text you encode is sent to that service as part of the request. That is fine for public URLs and everyday text; do not encode passwords, Wi-Fi keys for private networks or other secrets.

A pre-print checklist

  1. Scan it with at least two different phones.
  2. Use a short URL on a domain you control.
  3. Keep a quiet zone of at least four modules.
  4. Use dark modules on a light background.
  5. Follow the 10:1 size to distance rule.
  6. Use M as a default; raise it for logos or harsh conditions.
  7. Put a short call to action next to it, such as "Scan for the menu".

Related tools

Launch QR Code Generator