QR codes encode data in a two-dimensional pattern of black and white squares (modules). Invented in 1994 by Denso Wave for tracking auto parts, they now encode everything from URLs to Wi-Fi credentials. This guide explains the technical structure behind QR codes and best practices for generating them.
QR Code Structure
Every QR code contains these structural elements:
- Finder patterns — three large squares in the corners that help scanners detect and orient the QR code
- Alignment patterns — smaller squares that help correct for perspective distortion (absent in Version 1)
- Timing patterns — alternating black/white strips that help the scanner determine module density
- Format information — encodes error correction level and mask pattern
- Version information — encodes the QR code version (size) for versions 7+
- Data and error correction codewords — the actual encoded data plus Reed-Solomon error correction
- Quiet zone — a 4-module-wide white border required for scanner detection
Encoding Modes
QR codes support four encoding modes, each optimized for different character sets:
| Mode | Characters | Bits per Character | Best For |
|---|---|---|---|
| Numeric | 0-9 | 3.33 | Phone numbers, IDs |
| Alphanumeric | 0-9, A-Z, space, $%*+-./:= | 5.5 | Short codes, SKUs |
| Byte | Any byte (ISO 8859-1 / UTF-8) | 8 | URLs, text, binary data |
| Kanji | Shift JIS double-byte | 13 | Japanese text |
💡 Optimization: URLs are typically encoded in Byte mode (8 bits/char). But if you uppercase the URL scheme and domain (HTTP://EXAMPLE.COM), the alphanumeric portion uses only 5.5 bits/char — making a smaller QR code. Most servers handle uppercase URLs identically.
Error Correction Levels
QR codes use Reed-Solomon error correction to remain scannable even when partially damaged:
| Level | Recovery Capacity | Data Overhead | When to Use |
|---|---|---|---|
| L (Low) | ~7% | Minimal | Clean environments, digital screens |
| M (Medium) | ~15% | Moderate | General purpose (default) |
| Q (Quartile) | ~25% | Significant | Industrial/outdoor environments |
| H (High) | ~30% | Maximum | Logo overlays, harsh conditions |
Higher error correction increases the QR code's physical size because more redundant data modules are added.
Version and Data Capacity
QR codes range from Version 1 (21×21 modules) to Version 40 (177×177 modules):
| Version | Modules | Numeric (L) | Alphanumeric (L) | Byte (L) |
|---|---|---|---|---|
| 1 | 21×21 | 41 | 25 | 17 |
| 5 | 37×37 | 202 | 122 | 84 |
| 10 | 57×57 | 652 | 395 | 271 |
| 20 | 97×97 | 2,061 | 1,249 | 858 |
| 40 | 177×177 | 7,089 | 4,296 | 2,953 |
QR Code Best Practices
For Print
- Minimum size: 2×2 cm for close-range scanning; scanning distance ÷ 10 for the minimum dimension
- Contrast: Dark modules on light background (not just black-on-white; dark blue on white works too)
- Quiet zone: Maintain at least 4 modules of white space around the QR code
- Test before printing: Scan with multiple devices and apps
For Digital
- Use SVG format for scalability — vector graphics stay sharp at any size
- PNG minimum: 200×200 pixels for web display, 600×600 for high-DPI screens
- Avoid JPEG — compression artifacts can interfere with scanning
For Logo Overlays
- Use High (H) error correction
- Logo should cover ≤15% of total QR area
- Place logo in the exact center
- Add a small white border around the logo
Common QR Code Use Cases
- URLs:
https://example.com/page - Wi-Fi:
WIFI:T:WPA;S:NetworkName;P:Password;; - vCard: Contact information in vCard format
- Email:
mailto:[email protected]?subject=Hello - SMS:
smsto:+1234567890:Message text - Geo location:
geo:40.7128,-74.0060