What Are QR Codes?
A QR code (Quick Response code) is a two-dimensional matrix barcode invented in 1994 by Denso Wave, a subsidiary of Toyota. Originally designed to track automotive parts on assembly lines, QR codes have become one of the most widely used data-encoding formats in the world. You encounter them on restaurant menus, event tickets, payment terminals, product packaging, and billboard advertisements.
Unlike traditional one-dimensional barcodes that store data in a single row of varying-width lines, QR codes store data in a grid of black and white squares called modules. This two-dimensional layout allows QR codes to encode dramatically more information — up to 7,089 numeric characters or 2,953 bytes of binary data — in a compact square that can be scanned from any angle.
QR codes can encode many types of data: URLs, plain text, contact information (vCards), Wi-Fi network credentials, email addresses, phone numbers, geographic coordinates, and calendar events. When you scan a QR code with your phone's camera, the device reads the encoded data and takes the appropriate action — opening a website, joining a Wi-Fi network, or adding a contact.
How QR Codes Encode Data
QR codes support four encoding modes, each optimized for a different type of data. The encoder automatically selects the most efficient mode (or mixes modes within a single QR code) to minimize the number of modules needed:
- Numeric mode: Encodes digits 0-9. Three digits are packed into 10 bits, making this the most space-efficient mode. A Version 1 QR code with low error correction can hold up to 41 numeric characters.
- Alphanumeric mode: Encodes digits, uppercase letters A-Z, and nine special characters (
$ % * + - . / : space). Two characters are packed into 11 bits. Note that lowercase letters are not supported — a URL likehttps://example.commust be encoded in binary mode because of the lowercase letters. - Byte (binary) mode: Encodes any 8-bit byte value, which covers the full ISO 8859-1 character set and, in practice, UTF-8 encoded text. Each character takes 8 bits. This is the mode used for most URLs and arbitrary text.
- Kanji mode: Encodes characters from the Shift JIS character set, packing each double-byte Kanji character into 13 bits instead of the 16 bits that binary mode would require.
The data capacity varies significantly by mode. Here is a comparison for a Version 10 QR code (57 x 57 modules) at each error correction level:
| Error Correction | Numeric | Alphanumeric | Binary (bytes) | Kanji |
|---|---|---|---|---|
| L (7%) | 652 | 395 | 271 | 167 |
| M (15%) | 513 | 311 | 213 | 131 |
| Q (25%) | 364 | 221 | 151 | 93 |
| H (30%) | 288 | 174 | 119 | 74 |
Beyond the data payload, every QR code contains several structural elements that enable scanning. Three finder patterns — the large squares in three corners — allow the scanner to locate and orient the code regardless of rotation. Alignment patterns (smaller squares) help correct for perspective distortion on larger codes. Timing patterns (alternating black and white modules in rows and columns) establish the grid spacing. A format information strip encodes the error correction level and mask pattern used.
Error Correction Levels
One of the most important features of QR codes is built-in error correction using Reed-Solomon codes. This means a QR code can still be decoded even if part of it is damaged, dirty, or obscured. The QR standard defines four error correction levels:
- Level L (Low): Recovers up to 7% of damaged data. Produces the smallest QR code for a given data payload. Best for clean, controlled environments like digital screens.
- Level M (Medium): Recovers up to 15% of damaged data. This is the default level used by most QR code generators. A good balance between size and resilience for general-purpose use.
- Level Q (Quartile): Recovers up to 25% of damaged data. Useful for QR codes printed on packaging or surfaces that may get scuffed, scratched, or partially covered.
- Level H (High): Recovers up to 30% of damaged data. Required when you plan to embed a logo in the center of the QR code, since the logo effectively destroys the modules it covers.
The tradeoff is straightforward: higher error correction means more redundant data, which means more modules, which means a larger QR code. For the same data payload, a QR code at level H can be up to 1.5 times wider than one at level L because it needs a higher-version code to fit all the error correction codewords.
// Error correction overhead comparison
// Encoding "https://toolplex.dev" (20 characters, binary mode)
Level L → Version 2 (25×25 modules) — 160 bits of data capacity
Level M → Version 2 (25×25 modules) — 128 bits of data capacity
Level Q → Version 3 (29×29 modules) — 104 bits of data capacity
Level H → Version 3 (29×29 modules) — 72 bits of data capacity
// Same data, but H-level needs a larger version to fit it
Reed-Solomon error correction works by treating the data as a polynomial over a finite field (Galois field GF(28)) and generating error correction codewords that can locate and fix errors. The mathematics is the same used in CD/DVD error correction and digital television broadcasting. For QR codes, the data is divided into blocks, and each block gets its own set of error correction codewords. This block structure means that burst damage (like a scratch across one area) is less likely to destroy an entire block.
QR Code Versions and Size
QR codes come in 40 versions, numbered 1 through 40. Each version increase adds 4 modules to each side of the grid:
- Version 1: 21 x 21 modules — the smallest QR code. Can hold up to 17 bytes at level M.
- Version 5: 37 x 37 modules — suitable for short URLs or small text strings.
- Version 10: 57 x 57 modules — handles URLs up to about 200 characters.
- Version 20: 97 x 97 modules — suitable for longer text, paragraphs, or vCard data.
- Version 40: 177 x 177 modules — the maximum size. Can hold up to 2,953 bytes of binary data at level L.
The general formula is: a Version V QR code has (4V + 17) modules per side. Version 1 has 4(1) + 17 = 21 modules; Version 40 has 4(40) + 17 = 177 modules.
In practice, you should aim for the lowest version that fits your data at your chosen error correction level. Lower versions produce simpler codes with larger individual modules, which are easier to scan at a distance and more tolerant of printing imperfections. Most URL-based QR codes fall in the Version 2 to Version 6 range.
Versions 7 and above include version information — a small encoded block near the finder patterns that tells the scanner which version the code is. Versions 2 and above include alignment patterns to help correct for perspective distortion, with more alignment patterns added as the version increases.
Design Best Practices
A QR code that looks perfect on your screen can fail completely in the real world if you ignore a few critical design rules. Here are the most important ones:
- Maintain the quiet zone: The QR specification requires a blank margin of at least 4 modules on all sides of the code. This quiet zone lets the scanner distinguish the QR code from surrounding visual elements. Cropping into the quiet zone is the single most common reason QR codes fail to scan.
- Minimum print size: Each module should be at least 0.33 mm wide for reliable scanning. For a Version 3 QR code (29 x 29 modules plus quiet zone = 37 modules across), that means a minimum printed size of about 1.2 cm (0.5 inches). A safer recommendation is 2 cm x 2 cm (0.8 inches) as a minimum for codes scanned at arm's length.
- Distance rule: For QR codes scanned from a distance, the code should be at least 1/10th the scanning distance in width. A poster meant to be scanned from 3 meters away needs a QR code at least 30 cm wide.
- High contrast: QR code scanners rely on a strong contrast ratio between the dark and light modules. The ideal combination is black modules on a white background. Dark modules on a light background always works — dark blue on white, dark green on white, or black on light yellow are all fine.
- Avoid inverted codes: Some designers create "inverted" QR codes with white modules on a dark background. While many modern scanners can handle inverted codes, older scanners and some camera apps cannot. If you must invert, test thoroughly on multiple devices.
- Do not distort the shape: QR codes must be perfectly square. Stretching, skewing, or warping the code — even slightly — can prevent scanning. If you place a QR code on a curved surface like a bottle, test it at the actual curvature.
// Quick checklist for QR code design
✓ Quiet zone: 4+ module margin on all sides
✓ Module size: ≥ 0.33 mm per module
✓ Total size: ≥ 2 cm for close-range scanning
✓ Contrast ratio: dark on light (not inverted)
✓ Shape: perfectly square, no distortion
✓ Error correction: M for standard, H for logos
✓ Test: scan with at least 3 different devices
Embedding Logos in QR Codes
One of the most common QR code customizations is placing a logo or icon in the center. This is possible because of error correction — the logo covers and destroys some modules, but the Reed-Solomon algorithm recovers the lost data from the redundant codewords.
To embed a logo safely, follow these rules:
- Use error correction level H (30%): Since the logo destroys modules, you need the highest error correction level to ensure the code remains scannable. Level Q (25%) can also work for smaller logos.
- Limit logo size to 10-15% of the total area: Even though H-level correction can theoretically recover 30% of damaged data, the damage from a logo is concentrated in one area rather than distributed randomly. Keeping the logo under 15% of the total QR code area provides a safety margin.
- Center the logo precisely: The center of the QR code is the safest place for a logo because it is farthest from the finder patterns, timing patterns, and format information strips that are critical for initial code detection.
- Add a small white border around the logo: A 1-2 module white border between the logo edges and the surrounding modules helps scanners distinguish between the logo and actual data modules.
- Always test: Generate the QR code with the logo and test it on at least 3-5 different devices, including older phones. What scans perfectly on a new iPhone may fail on a budget Android device with a lower-quality camera.
Keep in mind that adding a logo increases the effective version of the QR code. The data payload stays the same, but the error correction level must increase from M to H, which requires more codewords. For a short URL, this might bump you from a Version 2 code (25 x 25) to a Version 4 code (33 x 33) — a noticeable size increase.
QR Code Use Cases
QR codes are versatile enough to encode many types of structured data. Here are the most common use cases and the data format each one uses:
- URLs: The most common use case. The QR code simply encodes the full URL (e.g.,
https://toolplex.dev). When scanned, the device opens the URL in a browser. Use a URL shortener for long URLs to keep the QR code version low. - vCards (contact information): A QR code can encode a full vCard with name, phone, email, address, and organization. The format starts with
BEGIN:VCARDand ends withEND:VCARD. When scanned, the device prompts to add the contact. - Wi-Fi login: Encode network credentials in the format
WIFI:T:WPA;S:NetworkName;P:Password;;and scanning the code automatically connects the device to the network. This is commonly used in hotels, cafes, and offices. - App store links: Deep links to iOS App Store or Google Play Store pages. Some implementations use smart URLs that detect the device OS and redirect to the appropriate store.
- Mobile payments: Payment platforms like Alipay, WeChat Pay, and many banking apps use QR codes for peer-to-peer and point-of-sale transactions. The QR code typically encodes a payment URL with the merchant's account information and transaction amount.
- Event tickets and boarding passes: Airlines, concert venues, and transit systems encode ticket data in QR codes. The encoded data usually includes a booking reference, seat assignment, and a digital signature for fraud prevention.
- Calendar events: QR codes can encode iCalendar (ICS) data to add events directly to a user's calendar, including the event title, date, time, location, and description.
// Common QR code data formats
// URL
https://toolplex.dev/qr-code-generator/
// Wi-Fi credentials
WIFI:T:WPA;S:MyNetwork;P:MyPassword123;;
// vCard contact
BEGIN:VCARD
VERSION:3.0
N:Doe;John
FN:John Doe
TEL:+1-555-123-4567
EMAIL:[email protected]
END:VCARD
// Calendar event
BEGIN:VEVENT
SUMMARY:Team Meeting
DTSTART:20260401T100000Z
DTEND:20260401T110000Z
LOCATION:Conference Room B
END:VEVENT
When choosing a use case, keep data length in mind. A URL like https://example.com is 19 characters and produces a small, easily scannable Version 2 QR code. A full vCard with address and organization details might be 300+ characters, requiring a Version 8 or higher code with densely packed modules that are harder to scan from a distance.