How QR Codes Store Information: A Grid Designed for Detection and Recovery
📑 On this page
- A concrete example: a payment QR
- Modules
- Finder patterns
- Quiet zone
- Timing patterns
- Alignment patterns
- Version information
- Data modes
- Encoding
- Error correction
- Error-correction levels
- Interleaving
- Masking
- Format information
- Perspective correction
- Color and design
- Static and dynamic QR codes
- Security
- Privacy
- Capacity and readability
- Knowledge check
- The one idea to remember
A QR code is more than random black and white squares.
Its grid contains data plus patterns that help a camera locate, orient, sample, unmask, and repair the code.
A QR code is structured encoded data with built-in geometry and error correction.
The code can remain readable even when viewed at an angle or partly damaged.
A concrete example: a payment QR
A payment QR may encode text containing:
- payment scheme,
- recipient identifier,
- currency,
- optional amount,
- reference,
- and checksum.
The camera decodes bytes. The payment app interprets those bytes according to the payment format and asks the user to confirm.
The QR image itself does not transfer money.
Modules
Each small square is a module.
Modules represent:
- encoded data,
- error correction,
- alignment,
- timing,
- format,
- and required fixed patterns.
A code's version determines the number of modules per side.
Finder patterns
Three large square patterns appear near corners.
They help a detector find:
- the code,
- orientation,
- scale,
- and perspective.
Using three rather than four makes rotation distinguishable.
Quiet zone
A blank margin surrounds the QR code.
The quiet zone separates it from nearby graphics and text. Cropping or decorating into this margin can make detection unreliable.
Printing guidelines specify a minimum module-width border.
Timing patterns
Alternating black and white modules connect finder regions.
They help the decoder determine:
- module spacing,
- grid alignment,
- and sampling positions.
Without reliable geometry, the camera might read between squares.
Alignment patterns
Larger QR versions include smaller alignment patterns.
They help correct distortion, especially when a code is curved, viewed at an angle, or printed unevenly.
Their positions are defined by the version.
Version information
The QR version indicates grid size and data capacity.
Higher versions contain more modules and can store more data, but they require more pixels or physical area to scan reliably.
A dense code printed too small becomes difficult for cameras.
Data modes
QR codes support modes optimized for:
- numeric,
- alphanumeric,
- bytes,
- and some character sets.
The encoder can choose efficient modes based on content.
Arbitrary URLs commonly use byte mode.
Encoding
The encoder creates a bit stream containing:
- mode,
- length,
- content,
- terminator,
- and padding.
It then divides data into codewords and adds error-correction codewords.
The final bits are placed into allowed grid positions.
Error correction
QR uses Reed-Solomon error correction.
Extra mathematical information allows a decoder to reconstruct some missing or corrupted codewords.
More error correction improves damage tolerance but reduces data capacity.
Error-correction levels
Standard levels trade capacity for recovery:
- L,
- M,
- Q,
- H.
The familiar approximate recovery percentages depend on damage distribution and code conditions; they are not a guarantee for any arbitrary missing area.
Interleaving
Data and error-correction blocks are interleaved.
This spreads nearby physical damage across several blocks rather than destroying one continuous section of logical data.
Interleaving improves recovery from localized marks.
Masking
Raw data placement can accidentally create:
- large solid areas,
- misleading finder-like patterns,
- or difficult alternating runs.
The encoder tries several mask patterns and chooses one with lower visual penalty. The decoder reads format information to reverse the chosen mask.
Masking changes appearance, not content.
Format information
Protected format bits identify:
- error-correction level,
- mask pattern.
They are repeated and error protected because the decoder needs them before reading the main data correctly.
Perspective correction
A camera image may show the square as a trapezoid.
The decoder:
- locates finder patterns,
- estimates corners,
- computes a perspective transform,
- maps the image back to a square grid,
- samples module centers.
Good focus, contrast, and resolution still matter.
Color and design
QR codes can use color and logos when:
- contrast remains high,
- finder patterns remain clear,
- quiet zone remains,
- and damage stays within correction capacity.
Inverted, low-contrast, reflective, or heavily decorated codes can fail on some scanners.
Always test across devices and print conditions.
Static and dynamic QR codes
A static QR directly stores its final payload.
A "dynamic QR" usually stores a short redirect URL whose destination can change on a server. The printed code remains the same.
Dynamic services add availability, tracking, privacy, and account-lifecycle dependencies.
Security
A QR can encode a malicious link just as ordinary text can.
Applications should:
- display the destination,
- validate payment recipient and amount,
- request confirmation,
- restrict dangerous schemes,
- and warn about suspicious domains.
Users should not assume a professionally printed code is trustworthy.
Privacy
Scanning through a redirect service can reveal:
- time,
- approximate location,
- device,
- and campaign.
Payment and identity QR formats may contain personal or transaction data visible to any camera.
Encode only necessary information and protect server-side records.
Capacity and readability
More data creates a denser code.
For better scanning:
- shorten URLs,
- choose only needed correction,
- print large enough,
- preserve contrast,
- and avoid unnecessary embedded data.
Capacity is not the same as practical readability.
Knowledge check
- What do finder patterns tell a camera?
- Why is the quiet zone important?
- How does error correction trade against capacity?
- Why does masking change the visible pattern?
- How does a dynamic QR differ from a static payload?
The one idea to remember
A QR code arranges encoded data, geometry, masking, format details, and error-correction codewords in a precisely defined grid. A camera detects and straightens that grid, samples its modules, repairs limited damage, and returns bytes for an application to interpret safely.