How QR Codes Work: Structure and Encoding
QR (Quick Response) codes are two-dimensional matrix barcodes invented by Denso Wave in 1994 for tracking automotive parts. Unlike traditional one-dimensional barcodes that encode data in a single row of varying-width bars, QR codes use a grid of black and white modules (squares) to encode data in both horizontal and vertical dimensions, dramatically increasing data capacity.
Every QR code contains several structural elements that enable reliable scanning. The three large square patterns in the corners (finder patterns) allow scanners to detect the QR code's position and orientation from any angle. Timing patterns (alternating black and white modules) between the finder patterns establish the grid spacing. Alignment patterns (smaller squares) help scanners correct for perspective distortion when the code is photographed at an angle.
The data area contains the encoded payload in one of four modes — Numeric (digits only, most efficient), Alphanumeric (uppercase letters, digits, and some symbols), Byte (arbitrary binary data including UTF-8 text), and Kanji (Japanese characters). The mode is selected automatically based on the input content, with the encoder choosing the most space-efficient mode that can represent the data.
QR codes range from Version 1 (21x21 modules, up to 25 alphanumeric characters) to Version 40 (177x177 modules, up to 4,296 alphanumeric characters). Higher versions create denser, larger codes that require higher-resolution cameras to scan reliably.
A Version 40 QR code with Low error correction can store up to 7,089 numeric characters, 4,296 alphanumeric characters, or 2,953 bytes of binary data. For practical use, keep payloads under 300 characters for reliable scanning.
Error Correction Levels and Reliability Engineering
One of QR codes' most powerful features is Reed-Solomon error correction, which allows partial data recovery even when the code is damaged, dirty, or partially obscured. QR codes support four error correction levels, each trading data capacity for reliability.
Level L (Low) recovers approximately 7% of damaged data. This provides maximum data capacity and is suitable for clean, controlled environments like digital screens and printed materials that won't be damaged.
Level M (Medium) recovers approximately 15% of damaged data. This is the default level for most use cases, balancing capacity with reasonable tolerance for minor scratches, smudges, or wear.
Level Q (Quartile) recovers approximately 25% of damaged data. This is recommended for QR codes printed on product packaging, outdoor signage, or materials that may experience moderate physical wear.
Level H (High) recovers approximately 30% of damaged data. This maximum correction level is required when logos or images are placed over the QR code centre (a common branding technique) because the logo effectively "damages" the underlying modules. It is also essential for QR codes exposed to harsh environments — factory floors, outdoor installations, or codes that may be partially covered.
The choice of error correction level directly impacts the QR code's physical size and minimum scanning resolution. Higher correction levels add more redundancy data, requiring more modules and thus a larger physical code or a denser grid for the same payload.
- Use Level M (Medium, 15% recovery) as the default for standard web and print QR codes.
- Use Level H (High, 30% recovery) when embedding logos in the QR code centre.
- Keep payloads short — shorter data produces simpler codes that scan faster and more reliably.
- Test QR codes on multiple devices and at various distances before deploying to production.
Practice the concepts from this article using ToolZeno's browser-based developer tools. No sign-up, no server tracking — 100% client-side.
QR Code Generator
FreeGenerate highly customizable QR codes for URLs, text, email, phone numbers, SMS, and locations with logo upload, custom colors, SVG export, and batch mode.
QR Code Scanner
FreeScan QR codes instantly online using device camera or uploaded image files (PNG, JPG, WebP), drag & drop, and clipboard paste. 100% client-side private decoding.
Wi-Fi QR Code Generator
FreeGenerate customized QR codes for Wi-Fi networks (WPA/WPA2/WPA3, WEP, Open). Instant connection for iOS and Android devices without typing passwords. 100% client-side private.
vCard QR Code Generator
FreeCreate standards-compliant contact QR codes (vCard 3.0 and vCard 4.0). Instant camera scan to import contacts on iOS and Android. 100% client-side private.
Practical QR Code Applications: WiFi, vCard, and URL Encoding
Beyond simple URL encoding, QR codes support standardised payload formats for specific use cases that trigger native device actions when scanned.
WiFi Network Sharing — The WIFI: URI scheme encodes network credentials in the format WIFI:T:WPA;S:NetworkName;P:Password;H:false;; where T is the security type (WPA, WEP, or nopass), S is the SSID, P is the password, and H indicates whether the network is hidden. When scanned, modern smartphones automatically prompt the user to join the network without manual credential entry. This is invaluable for guest networks, hotel rooms, co-working spaces, and events.
vCard Contact Sharing — The vCard format (BEGIN:VCARD ... END:VCARD) encodes structured contact information including name, phone numbers, email addresses, organisation, title, and physical address. Scanning a vCard QR code prompts the user's phone to add the contact directly to their address book. This is widely used on business cards, conference badges, and networking events.
URL Encoding — The simplest and most common QR code payload is a URL. When scanned, the device opens the URL in the default browser. Best practices include using HTTPS URLs, keeping URLs short (use URL shorteners if necessary to reduce QR code complexity), and including UTM parameters for marketing attribution tracking.
Plain Text and Email — QR codes can encode plain text messages or mailto: URIs that pre-compose emails with subject lines and body text. These are useful for feedback forms, support contact shortcuts, and automated reporting workflows.
QR Code Security: Phishing, Quishing, and Safe Scanning
The widespread adoption of QR codes has introduced new security attack vectors collectively known as "quishing" (QR phishing). Malicious actors replace legitimate QR codes on parking meters, restaurant menus, package delivery notices, and public signage with codes that redirect to phishing websites, malware downloads, or credential-harvesting pages.
The fundamental security challenge is that humans cannot visually inspect a QR code to determine its destination — unlike a visible hyperlink where you can read the domain name before clicking, a QR code's payload is opaque until scanned and decoded.
For QR code generators, security best practices include clearly displaying the encoded URL or data next to the generated QR code so users can verify the destination, using HTTPS URLs exclusively to prevent man-in-the-middle interception, and avoiding URL shorteners in security-sensitive contexts (like banking or authentication) because they obscure the final destination.
For QR code consumers, best practices include using a scanner that previews the decoded content before navigating to URLs (most modern smartphone cameras do this), being suspicious of QR codes placed as stickers over existing codes (a common replacement attack technique), and never scanning QR codes from unsolicited sources like random flyers, unexpected package labels, or unfamiliar emails.
ToolZeno's QR Code Generator and Scanner tools run entirely client-side, meaning the generated codes and scanned data never leave your browser. This prevents the privacy risk of external QR services potentially logging your encoded URLs, WiFi passwords, or contact information.