QR Code Generation: Error Correction, Sizing, and Best Practices
QR codes are everywhere — restaurant menus, payment terminals, event tickets, Wi-Fi sharing, product packaging. They are simple to generate but easy to get wrong. A code that scans perfectly on your screen may fail entirely when printed on a business card. This guide covers the fundamentals that make the difference.
How QR codes encode data
A QR code is a two-dimensional barcode that stores data in a matrix of black and white modules (squares). The encoding process works in layers:
- Data analysis — The encoder examines the input and selects the most efficient encoding mode: numeric (digits only), alphanumeric (digits + uppercase + a few symbols), byte (UTF-8), or kanji.
- Error correction — Redundant data is added using Reed-Solomon error correction, allowing the code to be read even if parts are damaged or obscured.
- Matrix construction — The data is arranged in the grid along with finder patterns (the three large squares in the corners), alignment patterns, and format information.
- Masking — A mask pattern is applied to balance the distribution of black and white modules.
The result is a square grid that can store up to 7,089 numeric characters or 4,296 alphanumeric characters.
Error correction levels
This is the single most important setting when generating QR codes. There are four levels:
| Level | Redundancy | Recovery capacity |
|---|---|---|
| L (Low) | ~7% | Smallest code, least resilient |
| M (Medium) | ~15% | Good balance for most uses |
| Q (Quartile) | ~25% | Recommended for printed materials |
| H (High) | ~30% | Best for logos in the center, harsh environments |
When to use each level:
- L — Digital-only display (screens, apps) where the code will not be physically damaged. Produces the smallest, most scannable code for long URLs.
- M — General purpose. Good for stickers, flyers, and web pages.
- Q — Printed materials that might get folded, scratched, or partially covered.
- H — When you plan to place a logo or image over part of the QR code. The 30% redundancy compensates for the obscured area.
Higher error correction means a larger code (more modules), so do not default to H when L would suffice.
Optimal size for scanning
The minimum module size for reliable scanning depends on the scanning distance and camera quality:
- Business cards and close-range (10-20 cm): Each module should be at least 0.5 mm. A QR code for a URL typically needs about 25x25 mm total.
- Posters and signs (1-3 meters): Scale up to at least 2 cm per module. A code on an A3 poster should be at least 10x10 cm.
- Billboards (10+ meters): Modules need to be 5+ cm. Test from the expected viewing distance before printing.
The formula is roughly: minimum QR size = scanning distance / 10. A code scanned from 2 meters away should be at least 20 cm wide.
Colors and contrast
QR scanners rely on contrast between the dark and light modules. Follow these rules:
- Dark modules on a light background. The classic black-on-white works best. Inverting (white on black) works with most modern scanners but fails on older devices.
- Maintain a contrast ratio of at least 4:1. Dark blue on white is fine. Light gray on white is not. Yellow on white will not scan.
- Avoid gradients across the code. A subtle gradient on the background is okay, but do not apply gradients to the modules themselves.
- Keep the quiet zone. The white border around the QR code (at least 4 modules wide) is required for scanners to detect the code boundaries.
[Quiet Zone]
+---+-------+---+
| | ##### | | <- Finder pattern
| | | |
| | Data | |
| | | |
| | ##### | | <- Finder pattern
+---+-------+---+
[Quiet Zone]
SVG vs PNG
Choose your output format based on where the code will be used:
SVG (vector):
- Scales to any size without quality loss
- Ideal for print materials, PDFs, and responsive web pages
- Smaller file size for simple QR codes
- Can be styled with CSS (change colors dynamically)
PNG (raster):
- Universal compatibility — works everywhere
- Necessary for email, social media, and platforms that do not support SVG
- Must be generated at the target resolution — scaling up causes blurriness
- Generate at 2x or 3x the display size for high-DPI screens
For print, always use SVG. For digital, SVG is preferred but PNG at 2x resolution is acceptable.
What to encode
The data type affects how devices handle the scanned result:
- URL — Opens in the browser. The most common use case.
- Plain text — Displayed as-is. Useful for serial numbers or codes.
- Wi-Fi —
WIFI:T:WPA;S:NetworkName;P:Password;;auto-connects on most phones. - vCard — Contact information that opens the "Add Contact" prompt.
Keep the data short. Every additional character increases the code complexity and size. For URLs, use a URL shortener if the original is very long. Always test your QR code with at least three different devices before distributing.
Try our QR Code Generator to create QR codes with custom settings instantly — right in your browser, no upload required.