Technical Details
Learn about the technical aspects of QR codes, including encoding, error correction, and data capacity.
QR Code Structure
A QR code is a two-dimensional barcode that consists of black and white modules arranged in a square grid. The structure is carefully designed to allow for efficient data storage and reliable scanning.
A QR code consists of several key components that work together to store and protect data:
- 🔍Finder Patterns
Three identical position detection patterns located at the corners (except bottom-right). These help scanners identify and orient the code. Each finder pattern consists of a 7×7 black square with a 5×5 white square inside, surrounded by a 1-module black border.
- 📊Alignment Patterns
Smaller square patterns that help correct distortion. The number of alignment patterns increases with the QR code version (size). Each alignment pattern is a 5×5 black square with a 3×3 white square inside, surrounded by a 1-module black border.
- 📏Timing Patterns
Alternating black and white modules that help determine the size of the data matrix. The timing pattern runs horizontally and vertically between the finder patterns.
- 🔢Format Information
Contains error correction level and mask pattern used for the QR code. The format information is encoded using a (15,5) BCH code, allowing for error correction of up to 3 bits.
- 📦Data and Error Correction Codewords
The actual encoded data and error correction information. Data is encoded in 8-bit codewords, and error correction codewords are generated using Reed-Solomon error correction.
The arrangement of these components follows a specific pattern to ensure reliable scanning and error correction. The finder patterns help scanners locate and orient the code, while the alignment patterns correct for perspective distortion.
Error Correction
QR codes use Reed-Solomon error correction to ensure data integrity. This mathematical technique allows the code to be read even if parts of it are damaged or obscured.
QR codes use Reed-Solomon error correction with four levels:
- LLevel L (Low)
7% of codewords can be restored. Uses Reed-Solomon code with generator polynomial g(x) = (x - α⁰)(x - α¹)...(x - αⁿ⁻¹), where α is a primitive element of GF(2⁸).
- MLevel M (Medium)
15% of codewords can be restored. The Reed-Solomon code is constructed over GF(2⁸) with primitive polynomial p(x) = x⁸ + x⁴ + x³ + x² + 1.
- QLevel Q (Quartile)
25% of codewords can be restored. Error correction uses systematic encoding where the message polynomial m(x) is multiplied by xⁿ⁻ᵏ and divided by g(x) to get the remainder r(x).
- HLevel H (High)
30% of codewords can be restored. The final codeword is c(x) = m(x) × xⁿ⁻ᵏ + r(x), where n is the codeword length and k is the message length.
The error correction process involves encoding the data using a generator polynomial and creating parity codewords. During decoding, the syndrome polynomial is calculated to detect and correct errors.
Data Encoding
QR codes support multiple encoding modes to efficiently store different types of data. Each mode is optimized for specific character sets and uses different bit lengths per character.
QR codes support four different encoding modes to efficiently store different types of data:
- 🔢Numeric Mode
Stores numbers (0-9) most efficiently, using 3.3 bits per digit. The data is divided into groups of 3 digits, each group encoded into 10 bits: 3 digits = 10 bits (3.33 bits/digit).
- 🔤Alphanumeric Mode
Stores uppercase letters, numbers, and some symbols, using 5.5 bits per character. Characters are encoded in pairs, with each pair using 11 bits: 2 characters = 11 bits (5.5 bits/character).
- 💾Byte Mode
Stores any 8-bit data, including lowercase letters and special characters, using 8 bits per character. Each byte is encoded directly using its 8-bit value.
- 🈯Kanji Mode
Stores Japanese characters efficiently, using 13 bits per character. Characters are encoded using their Shift JIS values, with each character using 13 bits.
The encoding process begins with a mode indicator (4 bits) followed by a character count indicator. The actual data is then encoded according to the selected mode's rules.
Version and Size
QR codes come in different versions (sizes) to accommodate varying amounts of data. The version number determines the size of the code and its data capacity.
QR codes have specific size and capacity characteristics:
- 📐Version 1-40
QR codes come in 40 versions, with version 1 being 21×21 modules and each subsequent version adding 4 modules per side. Version 40 is 177×177 modules.
- 🔲Module Size
Each module (black or white square) represents one bit of data. The minimum module size is typically 0.33mm × 0.33mm for reliable scanning.
- ⬜Quiet Zone
A 4-module wide white border around the QR code is required for proper scanning. This helps scanners distinguish the code from its surroundings.
The total number of modules in a QR code is calculated as (21 + 4 × (version - 1))². For example, version 1 has 21×21 = 441 modules, while version 40 has 177×177 = 31,329 modules.
Data Capacity
The amount of data a QR code can store depends on its version (size) and error correction level:
Version | Modules | Numeric | Alphanumeric | Binary |
---|---|---|---|---|
1 | 21×21 | 41 | 25 | 17 |
10 | 57×57 | 652 | 395 | 271 |
40 | 177×177 | 7,089 | 4,296 | 2,953 |