How QR Codes Work: Structure, Data Encoding, and Best Practices

Learn how QR codes store data, why they still scan when damaged, and how to create effective codes for print and digital use.

The Quick Answer

A QR (Quick Response) code is a two-dimensional barcode that stores data in a grid of black and white squares called modules. Your phone's camera detects the pattern, decodes the data, and takes action — opening a URL, connecting to WiFi, or displaying text.

QR codes can hold up to 4,296 alphanumeric characters and remain scannable even when partially damaged, thanks to built-in error correction.

Why QR Codes Exist

Traditional barcodes (like those on grocery items) store data in one dimension — a series of vertical lines. They hold about 20–25 characters and must be scanned at a specific angle.

QR codes were invented in 1994 by Masahiro Hara at Denso Wave, a Japanese automotive parts company. The goal was to track components during manufacturing faster than barcodes allowed. The "Quick Response" name reflects that original purpose: speed.

The key improvements over barcodes:

  • Two-dimensional data storage — data is encoded in both rows and columns, increasing capacity by orders of magnitude
  • Orientation-independent scanning — finder patterns in three corners let scanners detect the code from any angle
  • Built-in error correction — data can be recovered even if up to 30% of the code is damaged
  • Multiple data types — a single code can encode URLs, text, numbers, WiFi credentials, and more

Denso Wave holds the patent but chose not to enforce it, which is why QR codes are free to use worldwide.

Anatomy of a QR Code

Every QR code contains fixed structural elements that help scanners locate and decode it:

Finder Patterns

The three large squares in the top-left, top-right, and bottom-left corners. These tell the scanner "this is a QR code" and establish its orientation. The scanner uses these three points to calculate the code's size, rotation, and perspective distortion.

The bottom-right corner deliberately has no finder pattern. This asymmetry is how the scanner determines which way is "up."

Alignment Patterns

Smaller squares that appear in larger QR codes (version 2 and above). They help correct for warping when the code is scanned at an angle or on a curved surface. The number of alignment patterns increases with the QR code version — a version 7 code has 6 alignment patterns; a version 40 code has 46.

Timing Patterns

Alternating black and white modules in a line between the finder patterns (one horizontal, one vertical). These establish the grid coordinates so the scanner knows exactly where each data module falls, even if the image is slightly distorted.

Format Information

A 15-bit strip near the finder patterns that encodes two things: the error correction level (L, M, Q, or H) and the mask pattern used. The scanner reads this first to know how to decode the rest.

Version Information

Present in QR codes version 7 and above (those with more than 44 modules per side). It tells the scanner exactly which version the code is, so it knows the grid dimensions.

Data and Error Correction

The remaining modules store the actual payload (your URL, text, or WiFi credentials) interleaved with Reed-Solomon error correction codes. The data is not stored in a simple left-to-right sequence — it follows a specific two-column zigzag pattern from the bottom-right corner.

QR Code Versions

QR codes come in 40 versions, numbered 1 through 40. Each version adds 4 modules per side:

  • Version 1: 21 × 21 modules (smallest)
  • Version 10: 57 × 57 modules
  • Version 20: 97 × 97 modules
  • Version 40: 177 × 177 modules (largest)

The version is automatically determined by the amount of data and the error correction level. More data or higher error correction requires a higher version number.

For most practical uses (URLs, WiFi credentials, short text), codes stay within versions 1–10.

Data Encoding Modes

QR codes support four encoding modes, each optimized for different character sets:

Numeric Mode

Encodes digits 0–9 only. Three digits are packed into 10 bits, making this the most efficient mode. Maximum capacity: 7,089 digits.

Use case: Phone numbers, numeric IDs, tracking codes.

Alphanumeric Mode

Encodes digits, uppercase letters A–Z, and nine symbols: space, $, %, *, +, -, ., /, and colon. Two characters are packed into 11 bits. Maximum capacity: 4,296 characters.

Use case: URLs (when uppercase), simple codes, product references.

Byte Mode

Encodes any byte value (0–255), typically used for UTF-8 text. One character uses 8 bits. Maximum capacity: 2,953 bytes.

Use case: URLs with lowercase, free-form text, non-Latin characters.

Kanji Mode

Encodes Japanese Kanji characters using the Shift JIS character set. One character uses 13 bits. Maximum capacity: 1,817 characters.

The QR code encoder automatically selects the most efficient mode for your data. Some encoders switch modes within a single code to optimize space — encoding a phone number section in numeric mode and a text section in byte mode.

Error Correction: How QR Codes Survive Damage

This is the feature that makes QR codes practical in the real world. Reed-Solomon error correction adds redundant data so the original message can be reconstructed even if some modules are unreadable.

Four levels are available:

Level Recovery Capacity Extra Data Added Best For
L (Low) ~7% Small Clean screens, short data
M (Medium) ~15% Moderate General purpose — default for most uses
Q (Quartile) ~25% Significant Printed materials that may get worn
H (High) ~30% Large Logos overlaid on the code, harsh environments

The trade-off: higher error correction means more modules for the same data, which means a larger code or a code that's harder to scan at small sizes.

Practical guidance: Use Level M as your default. Use Level H only if you plan to place a logo over part of the code. Use Level L when you need to encode a lot of data and the code will be displayed on a clean digital screen.

Data Types and Standard Formats

QR codes can trigger specific actions on smartphones by using standardized URI prefixes:

URL

Simply encode the full URL:

https://example.com/page

The phone opens the link in its browser. This is the most common use case.

WiFi

The WiFi standard uses this format:

WIFI:T:WPA;S:NetworkName;P:MyPassword;;
  • T: — Security type (WPA, WEP, or nopass)
  • S: — SSID (network name)
  • P: — Password

Supported on iOS 11+ and Android 10+. When scanned, the phone connects to the network automatically without the user typing the password.

Email

Uses the mailto: scheme:

mailto:[email protected]?subject=Hello&body=Message%20here

Opens the user's email app with pre-filled fields.

Phone Call

Uses the tel: scheme:

tel:+15551234567

Initiates a phone call (with user confirmation on most devices).

SMS

Uses the smsto: scheme:

smsto:+15551234567:Your message here

Opens the messaging app with the number and message pre-filled.

vCard (Contact)

Encodes a full contact card:

BEGIN:VCARD
VERSION:3.0
N:Doe;John
TEL:+15551234567
EMAIL:[email protected]
END:VCARD

The phone offers to save the contact.

Static vs. Dynamic QR Codes

Static Codes

The data is encoded directly in the QR pattern. What you see is what you get.

Advantages:

  • Never expire
  • Work offline (no server dependency)
  • No subscription required
  • Complete privacy (no tracking)

Limitation: The data cannot be changed after the code is created.

Dynamic Codes

A short redirect URL is encoded (e.g., https://qr.example.com/abc123). A server behind that URL redirects to the actual destination.

Advantages:

  • Destination can be changed after printing
  • Scan analytics (count, location, device)
  • Can be deactivated

Limitations:

  • Depends on an external service
  • May expire if the service shuts down or the subscription lapses
  • The service can see who scans the code and when

When to use which: Static codes are ideal for WiFi sharing, stable URLs, personal use, and any case where privacy matters. Dynamic codes are useful for marketing campaigns where you need analytics or might change the destination.

Sizing Guide

The relationship between QR code size and scanning distance follows a simple rule:

Minimum QR code width ≈ scanning distance ÷ 10

Scanning Distance Minimum Code Size Typical Use
10 cm (phone in hand) 1 cm Probably too small — use 2 cm minimum
25 cm (arm's length) 2.5 cm Business cards, product labels
1 m (standing nearby) 10 cm Posters, table tents, signs
3 m (across a room) 30 cm Large posters, trade show displays
10 m (billboard) 1 m Outdoor advertising

These are minimums. Going larger improves scan reliability.

Additional factors that affect scanability:

  • Data density (more data = more modules = needs to be larger)
  • Print resolution (low-quality printing blurs module edges)
  • Surface texture (matte surfaces scan better than glossy ones)
  • Lighting conditions (glare on glossy surfaces can cause failures)

Best Practices for Creating QR Codes

Contrast

The foreground must be darker than the background. Black on white provides the highest reliability. Colored codes work if the contrast ratio is strong — dark blue on white is fine; yellow on white is not.

Avoid inverted codes (white on black). While some modern scanners handle them, many older devices and camera apps do not.

Quiet Zone

Leave white space around all four sides of the QR code — at least 4 modules wide. This "quiet zone" helps scanners distinguish the code from surrounding design elements. Cropping too close is a common cause of scan failures.

Data Length

Shorter data produces simpler codes that scan faster and print smaller. For long URLs, consider using a URL shortener. A 20-character URL creates a version 2 code (25×25 modules); a 200-character URL might create a version 8 code (49×49 modules).

File Format

Use SVG for anything that will be printed or resized. SVG is vector-based and scales to any size without quality loss. Use PNG for digital sharing where the size is fixed.

Testing

Always scan your QR code with at least 2–3 different devices before printing. Test at the intended scanning distance and in representative lighting conditions. What works perfectly on your monitor may fail on a printed flyer.

Common Mistakes

  1. Encoding too much data. Long URLs, paragraphs of text, or detailed vCards create dense codes that need to be large to scan. Keep it concise.

  2. Printing too small. A 1 cm QR code might render fine on screen but fail in print because the modules blur together.

  3. Low contrast colors. Custom colors look appealing but light foregrounds on light backgrounds kill scanability.

  4. No quiet zone. Placing the code edge-to-edge against other graphics confuses scanners.

  5. Not testing. Different phones, camera apps, and QR scanner apps have different capabilities. Always test.

  6. Linking to non-mobile pages. Most QR scans happen on phones. If the destination is not mobile-friendly, users will bounce immediately.

  7. Using dynamic codes when static will do. If you don't need analytics or URL changes, static codes are simpler, more private, and permanent.

The Future of QR Codes

QR codes saw explosive growth during the COVID-19 pandemic (contactless menus, check-ins, health passes) and have remained part of daily life. Several trends are shaping their evolution:

  • Payment systems — QR-based payments are standard in many countries (Alipay, WeChat Pay, UPI, Pix)
  • Digital IDs and tickets — boarding passes, event tickets, and identity verification increasingly use QR codes
  • Augmented reality — some QR codes now trigger AR experiences in addition to opening URLs
  • Micro QR and rMQR — smaller format variants designed for space-constrained applications like tiny electronic components

The format itself is stable and well-understood. The ISO/IEC 18004 standard defines it precisely, ensuring interoperability across all implementations.

Try It

Create your own QR code with our free QR code generator — supports URLs, WiFi, email, SMS, and phone numbers with customizable colors and downloadable PNG or SVG output. No sign-up required.

Related Tools