QR Code Guide

What Is a QR Code? A Complete Guide

By K. Narendra·Published ·Updated ·14 min read

QR codes are everywhere — restaurant menus, payment apps, boarding passes, Wi-Fi sharing, product packaging. But how do they actually work? This guide covers the internal structure of a QR code, how data is encoded and recovered after damage, and how to generate QR codes in code.

What Is a QR Code?

A QR code (Quick Response code) is a two-dimensional matrix barcode that encodes data as a pattern of black and white squares (called modules) arranged on a grid. Unlike the one-dimensional barcodes on grocery products — which store only ~20 characters — a QR code can hold thousands of characters of text, URLs, binary data, or even Kanji, all in a compact square that any modern smartphone camera can decode in milliseconds.

QR codes are standardized under ISO/IEC 18004 (first published in 2000, revised in 2006 and 2015). The standard defines everything from the physical structure of the code to the encoding algorithms and error correction mechanisms. A scanner only needs to see the code — no network connection required — making QR codes reliable in offline environments.

Critically, QR codes are not encrypted. Anyone with a camera can read one. Security, where needed, comes from the content itself (HTTPS URLs, signed tokens) not from the QR code format.

History

In 1994, Masahiro Hara, an engineer at Denso Wave (a Toyota subsidiary), invented the QR code to solve a real logistics problem: the 1D barcodes used to track automotive parts were too small to hold enough information. Warehouse workers had to scan multiple barcodes per item to capture all the necessary data.

Hara drew inspiration from the game of Go — black and white stones on a grid — and designed a 2D code that could be scanned from any direction (omnidirectional reading) at high speed. The three distinctive square finder patterns in the corners were chosen because that specific 1:1:3:1:1 ratio pattern was the least likely to appear naturally in printed text or graphics, ensuring fast, reliable detection.

Denso Wave published the QR code specification and released it to the public royalty-free, a decision that directly enabled global adoption. Key milestones:

  • 1994 — First QR code created at Denso Wave
  • 1997 — AIM International standardizes QR code
  • 2000 — ISO/IEC 18004 international standard published
  • 2002 — Camera phones in Japan begin scanning QR codes for marketing
  • 2010s — Mobile payment systems (Alipay, WeChat Pay, UPI) drive mass adoption
  • 2020 — COVID-19 contactless menus trigger global mainstream adoption outside Asia

Today, QR codes are scanned billions of times per day. iOS (since 2017) and Android can scan them natively through the camera app — no third-party app required.

QR Code Anatomy

Every QR code is a square grid of black and white modules. The structure is divided into several distinct functional regions:

Finder Patterns

Three identical 7×7 module squares sit in the top-left, top-right, and bottom-left corners. Each is a black border surrounding a white frame surrounding a black center (the 1:1:3:1:1 ratio). Scanners use these to locate the code, determine its orientation, and calculate the module size — even from unusual angles or distances.

Separators

A one-module-wide white border separates each finder pattern from the rest of the code, ensuring the scanner doesn't confuse finder pattern data with encoded data.

Timing Patterns

Alternating black-white stripes run horizontally and vertically between the finder patterns. They tell the scanner how large each module is and allow it to handle slight distortions or warping in the image.

Alignment Patterns

Smaller 5×5 squares scattered throughout larger QR codes (Version 2 and above). They help scanners correct for perspective distortion when a code is photographed at an angle.

Format Information

Two strips near the finder patterns encode the error correction level and masking pattern used by this specific code. This data is duplicated for redundancy — the scanner reads it first, before attempting to decode anything else.

Data & Error Correction Region

The remaining modules hold the actual encoded data interleaved with error correction codewords. Data is placed in a zigzag pattern starting from the bottom-right, moving upward in two-column wide strips.

Quiet Zone

A mandatory 4-module-wide white border surrounds the entire code. Without it, scanners cannot reliably locate the finder patterns — especially on busy backgrounds. Cropping the quiet zone is one of the most common reasons printed QR codes fail to scan.

Generate QR codes instantly

Use the free QR Encoder to generate QR codes for URLs, text, Wi-Fi credentials, and more — entirely in your browser.

Open QR Encoder

How QR Codes Work

Encoding data into a QR code follows a precise sequence defined by ISO/IEC 18004:

  1. Choose encoding mode — The encoder picks the most efficient mode (Numeric, Alphanumeric, Byte, or Kanji) based on the input characters.
  2. Convert to a bitstream — The data is converted to binary according to the mode's rules (e.g., numeric mode packs three digits into 10 bits).
  3. Pad to fill capacity — Padding bytes (11101100 and 00010001 alternating) fill any unused capacity at the end of the bitstream.
  4. Generate error correction codewords — Reed-Solomon error correction generates additional bytes. The number of EC codewords depends on the version and error correction level chosen.
  5. Interleave data and EC blocks — For larger QR codes, the data is split into blocks and interleaved before placement, improving burst-error recovery.
  6. Place modules on the grid — Data is placed in the functional regions using a two-column zigzag pattern, skipping over finder patterns, alignment patterns, and timing patterns.
  7. Apply a mask pattern — One of 8 predefined mask patterns (XOR operations) is applied to the data area to balance the ratio of black and white modules, preventing scanner confusion from large uniform areas.
  8. Write format and version information — The chosen error correction level and mask pattern index are encoded into the format information strips.

Decoding reverses this process: the scanner locates the finder patterns, reads the format information, removes the mask, extracts and deinterleaves the data/EC codewords, applies Reed-Solomon correction, and finally decodes the bitstream back to the original text.

Error Correction Levels

QR codes use Reed-Solomon error correction, the same algorithm used in CDs, DVDs, and deep-space communications. It adds redundant data that allows the original message to be reconstructed even when part of the code is missing or unreadable.

There are four error correction levels. Higher levels add more redundancy but reduce the amount of data that can be stored in a given code size:

LevelRecovery CapacityBest For
L (Low)7%Clean environments — screens, digital displays
M (Medium)15%General use — the default choice
Q (Quartile)25%Industrial labels with expected wear
H (High)30%Logo overlays, heavy physical damage

The practical implication: if you want to overlay a company logo on a QR code, choose error correction level H and keep the logo under 15% of the total area. The code will still scan perfectly because the logo obscures data that Reed-Solomon can reconstruct.

Versions & Capacity

QR codes come in 40 versions. Each version is larger than the previous one by 4 modules per side. The formula is: size = 4 × (version − 1) + 21. So Version 1 is 21×21 modules, Version 2 is 25×25, and Version 40 is 177×177 modules.

Capacity grows with version because more modules mean more data. The table below shows representative versions at error correction level L (maximum capacity):

VersionGridNumericAlphanumericBinary (bytes)Kanji
121×2141251710
537×3731419113484
1057×57652395271168
2097×971,8521,122782480
40177×1777,0894,2962,9531,817

Encoders automatically select the smallest version that fits the data. You rarely need to choose a version manually — just provide the content and error correction level, and the library handles the rest.

Encoding Modes

QR codes use different encoding modes to pack data as efficiently as possible. Choosing the right mode significantly affects how much data fits in a given version:

ModeAllowed CharactersBits/CharMax (V40-L)
Numeric0–93.337,089 digits
Alphanumeric0–9, A–Z, space, $%*+-./:5.54,296 chars
ByteAny UTF-8 byte82,953 bytes
KanjiShift JIS characters131,817 chars

The encoder automatically selects the most efficient mode. A URL like https://example.com uses Byte mode (because lowercase letters aren't in the Alphanumeric character set). A phone number like 14155552671 uses Numeric mode, packing 3 digits per 10 bits instead of 8 bits per character — roughly 60% more efficient.

The Extended Channel Interpretation (ECI) mechanism allows QR codes to specify character sets beyond the defaults (e.g., UTF-8, Latin-1, Shift JIS), enabling QR codes for any language.

Static vs Dynamic QR Codes

This is one of the most practically important distinctions for anyone using QR codes in business or marketing:

Static QR Codes

The destination data is encoded directly in the QR modules. Once printed, the code is permanent — changing the content means generating and printing a new code. Static codes are ideal for permanent information: Wi-Fi credentials, product serial numbers, vCards, app store links, and any content that won't change.

Dynamic QR Codes

Instead of encoding the final destination, a dynamic code encodes a short redirect URL (e.g., https://qr.co/abc123). When scanned, that URL redirects to the real destination. You can update the destination at any time through your QR management platform — without reprinting. Dynamic codes also collect analytics: scan count, time, location (city-level), and device type.

The trade-off: dynamic codes require a third-party redirect service to remain operational. If the provider goes down or you stop paying, the redirect breaks. Static codes work forever, offline, with no dependencies.

Common Use Cases

Payments

QR-based payments dominate in Asia (Alipay, WeChat Pay, India's UPI) and are growing globally. The payer either scans a merchant's QR code or shows their own for the merchant to scan. The QR code encodes a payment URI that the banking app processes securely.

URLs and Deep Links

The most common use in the West. A QR code encodes a plain URL: https://example.com/landing. Scanners open it in the default browser. Deep links (e.g., myapp://product/123) open directly in a mobile app if installed.

Wi-Fi Credentials

The WIFI: URI scheme lets users join a network by scanning a single code — no typing required. The format is:

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

Fields: T = authentication type (WPA, WEP, or nopass), S = SSID (network name), P = password, H = true if hidden network. Special characters in the SSID or password must be escaped with a backslash.

vCards / Contact Information

A QR code can encode a full vCard 3.0 record — name, phone, email, address, website — allowing instant contact saving from a business card.

Event Tickets & Boarding Passes

Airlines and event venues encode booking references or signed tokens in QR codes. Gate scanners verify them offline or with a fast API call. The high density of QR codes (vs 1D barcodes) means a single scan captures the full booking ID plus flight or seat data.

Restaurant Menus & Government IDs

Contactless menus (popularized during COVID-19) encode a URL to a hosted PDF or web menu. Government-issued documents (vaccine certificates, driver's licenses in some countries) embed signed data or verification URLs in QR codes to prevent tampering.

Generating QR Codes in Code

Most ecosystems have mature, well-maintained QR code libraries. Here are the most widely used:

JavaScript / Node.js

The qrcode npm package is the standard choice. It works in both Node.js and the browser (via Canvas or SVG):

import QRCode from 'qrcode';

// Generate as PNG file (Node.js)
await QRCode.toFile('qrcode.png', 'https://example.com', {
  errorCorrectionLevel: 'H',
  margin: 4,                          // quiet zone in modules
  color: { dark: '#000000', light: '#ffffff' },
});

// Generate as Data URL for HTML/React embedding
const dataUrl = await QRCode.toDataURL('https://example.com', {
  errorCorrectionLevel: 'M',
  width: 300,
});
// <img src={dataUrl} alt="QR code" />

// Generate as SVG string
const svg = await QRCode.toString('https://example.com', { type: 'svg' });

// Wi-Fi QR code
const wifiUrl = 'WIFI:T:WPA;S:MyNetwork;P:MyPassword;;';
await QRCode.toFile('wifi-qr.png', wifiUrl, { errorCorrectionLevel: 'M' });

Python

The qrcode library (with Pillow for image output) is the standard choice in Python:

import qrcode
from qrcode.constants import ERROR_CORRECT_H

qr = qrcode.QRCode(
    version=None,            # auto-select smallest version
    error_correction=ERROR_CORRECT_H,
    box_size=10,             # pixels per module
    border=4,                # quiet zone in modules
)
qr.add_data('https://example.com')
qr.make(fit=True)            # fit=True: auto-pick smallest version

img = qr.make_image(fill_color='black', back_color='white')
img.save('qrcode.png')

# Overlay a logo (Pillow required)
from PIL import Image

logo = Image.open('logo.png').convert('RGBA')
qr_img = qr.make_image(fill_color='black', back_color='white').convert('RGBA')
qr_w, qr_h = qr_img.size
logo_size = qr_w // 4          # keep logo under 15% of QR area
logo = logo.resize((logo_size, logo_size))
pos = ((qr_w - logo_size) // 2, (qr_h - logo_size) // 2)
qr_img.paste(logo, pos, mask=logo)
qr_img.save('qrcode-with-logo.png')

Decode any QR code instantly

Paste or upload an image of any QR code — the free QR Decoder reveals its content immediately, in your browser.

Open QR Decoder

Best Practices

  1. Use error correction level H for physical print. Level H (30% recovery) gives the maximum tolerance for scratches, smudges, and stickers. It also allows logo overlays up to ~15% of the total area.
  2. Always test before printing at scale. Scan the final output with at least two different devices (iOS and Android) and two different apps. Verify the full URL loads correctly. Do this before any print run.
  3. Preserve the quiet zone. The 4-module white border is mandatory. Cropping it — even slightly — is one of the top causes of scan failure in printed materials. Measure it explicitly in your design templates.
  4. Use HTTPS URLs. HTTP URLs expose users to interception and downgrade attacks. Modern scanner apps warn about non-HTTPS destinations, which erodes user trust. Always use HTTPS.
  5. Prefer dynamic QR codes for marketing campaigns. If there's any chance the destination URL will change (typo fix, seasonal redirect, A/B test), use a dynamic code. Reprinting is expensive; a redirect update is free.

Common Errors

These four problems account for the vast majority of QR code failures in the wild.

Error: QR code won't scan

✗ Cause

Quiet zone cropped or insufficient contrast

✓ Fix

Keep a 4-module white border on all sides. Use pure black on white — avoid light grey on light backgrounds.

Error: Scanned URL is garbled

✗ Cause

Special characters in the URL not percent-encoded

✓ Fix

URL-encode the destination: encodeURIComponent() in JavaScript or urllib.parse.quote() in Python.

Error: Wi-Fi QR code won't connect

✗ Cause

Incorrect WIFI: format or unescaped special characters in SSID/password

✓ Fix

Escape ;, ,, ", \, and : in SSID/password values with a preceding backslash. Double-check the trailing ;; terminator.

Error: Logo overlay makes code unscannable

✗ Cause

Logo covers more than the error correction budget allows

✓ Fix

Use error correction level H (30% recovery) and keep the logo under 15% of total QR code area.

Frequently Asked Questions

What does QR code stand for?
QR code stands for "Quick Response" code. The name was chosen by its inventor, Masahiro Hara of Denso Wave, to reflect the goal of decoding at high speed. Originally designed in 1994 to track automotive parts during manufacturing, the QR code was made publicly available without licensing fees, enabling its global adoption.
How much data can a QR code hold?
At error correction level L, a Version 40 QR code (the largest standard size) can hold up to 7,089 numeric characters, 4,296 alphanumeric characters, 2,953 bytes of binary data, or 1,817 Kanji characters. Higher error correction levels reduce capacity because more of the code's modules are used for redundancy data.
What is the difference between a static and dynamic QR code?
A static QR code has the destination data encoded directly in the code — it cannot be changed after printing. A dynamic QR code encodes a short redirect URL; the actual destination can be updated at any time through a management platform without reprinting the code. Dynamic codes also support scan analytics such as location, device type, and scan count.
Can a damaged QR code still be scanned?
Yes — QR codes use Reed-Solomon error correction, which allows them to be reconstructed even when partially damaged. At error correction level H (High), up to 30% of the code can be damaged or obscured and it will still scan correctly. This is why brands can safely overlay logos in the center of a QR code, as long as the logo covers no more than about 15% of the total code area.
Are QR codes secure?
QR codes themselves are unencrypted — anyone can generate one pointing anywhere. The main risk is QR phishing (called "quishing"): attackers place malicious QR codes over legitimate ones, or send them in phishing emails. To stay safe, always verify the URL displayed by your scanner app before opening it, ensure the destination uses HTTPS, and use trusted QR management platforms for business campaigns.

Ready to work with QR codes?

JSON Buddy gives you free browser-based QR tools — generate QR codes for URLs, Wi-Fi, and text, or decode any existing QR code to inspect its content. No signup. Your data never leaves your browser.