How Do QR Codes Work?

The technical details explained simply

QR codes look like random black and white squares, but every element has a purpose. This guide explains the technical architecture of QR codes -- from finder patterns to error correction -- in clear, accessible language.

Explore more topics:

Anatomy of a QR Code

Every QR code is made up of several distinct components, each serving a specific function. Understanding these components helps explain why QR codes look the way they do and why they are so reliable.

The three large squares in the corners (top-left, top-right, bottom-left) are finder patterns. They allow a scanner to instantly locate the code and determine its orientation, size, and angle. This is why QR codes can be scanned from any direction -- the scanner uses these three reference points to orient itself. The bottom-right corner is intentionally left without a finder pattern so the scanner can determine which way is "up."

Between and around the finder patterns, you will find timing patterns (alternating black and white modules in straight lines) that help the scanner determine the grid spacing. Alignment patterns (smaller squares) appear in larger QR codes to compensate for distortion -- if the code is printed on a curved surface or photographed at an angle, these patterns help the scanner correct for warping.

The quiet zone is the blank white border surrounding the entire code. This margin (at least 4 modules wide) is essential -- it tells the scanner where the code ends and the background begins. Without a sufficient quiet zone, scanners may fail to detect the code or include surrounding visual noise in their reading.

Data Encoding Modes

QR codes support four primary encoding modes, each optimized for different types of data. The mode determines how efficiently data is packed into the available modules.

Numeric mode is the most efficient, encoding digits 0-9 at approximately 3.3 bits per character. This allows a QR code to store up to 7,089 numeric characters. Alphanumeric mode handles digits, uppercase letters A-Z, and nine special characters (space, $, %, *, +, -, ., /, :) at about 5.5 bits per character, storing up to 4,296 characters. Byte mode encodes any 8-bit data (including lowercase letters, Unicode via UTF-8, and binary data) at 8 bits per character, with a maximum capacity of 2,953 bytes. Kanji mode is optimized specifically for Japanese kanji and kana characters.

The encoding mode is specified in a small section of the QR code's data area, so the scanner knows how to interpret the bit stream. A single QR code can actually mix multiple encoding modes to optimize space -- for example, encoding a URL's numeric port number in numeric mode and the rest in byte mode. Most QR code generators handle this optimization automatically.

Error Correction Levels

One of the QR code's most important features is built-in error correction using Reed-Solomon algorithms. This means a QR code can be partially damaged, dirty, or even have a logo placed over part of it and still scan successfully. There are four error correction levels, each offering a different trade-off between data capacity and damage tolerance.

Level L (Low) can recover from approximately 7% data loss. This is the default for most use cases and maximizes the amount of data the code can hold. Level M (Medium) recovers from about 15% loss and is a good balance for general use. Level Q (Quartile) handles roughly 25% loss, suitable for environments where the code may get scuffed or dirty. Level H (High) can recover from up to 30% data loss and is the level to choose when you want to place a logo or image over part of the QR code.

Higher error correction comes at a cost: it reduces the code's data capacity because more modules are used for redundancy rather than data. A QR code with Level H error correction holds significantly less data than the same version code with Level L. When adding a logo to a QR code, Level H is recommended, but you should keep the logo small (no more than about 10-15% of the code area) and always test that the code scans reliably after adding it.

Version and Size

QR codes come in 40 versions (Version 1 through Version 40), with each version adding more modules to the grid. Version 1 is a 21x21 module grid, and each subsequent version adds 4 modules per side. Version 40, the largest, is a 177x177 module grid with 31,329 individual modules.

The version used depends on the amount of data being encoded and the error correction level selected. A short URL might fit in a Version 3 code (29x29 modules), while a full vCard with extensive contact details might require Version 10 or higher. QR code generators automatically select the smallest version that can hold your data at the chosen error correction level.

Bigger is not always better. Higher-version QR codes are more complex and require more precise printing and scanning conditions. For most consumer applications, keeping data concise (using URL shorteners for long URLs, for example) results in lower-version codes that are easier to scan. Dynamic QR codes have an advantage here because they always encode a short redirect URL, keeping the version low regardless of how long the final destination URL is.

The Scanning Process

When you point your phone camera at a QR code, a series of steps happen in milliseconds. First, the camera's image processing software detects the three finder patterns and uses them to locate the code within the frame. It calculates the code's position, rotation, and perspective distortion.

Next, the software maps the grid of modules, using the timing patterns and alignment patterns to determine the exact position of each module. Each module is classified as black (1) or white (0), creating a binary data stream. The software then reads the format information (which specifies the error correction level and mask pattern used), applies the inverse of the data mask to reveal the true data pattern, and decodes the binary stream according to the encoding mode specified.

Finally, the error correction algorithm checks the decoded data for errors and corrects any that it finds. If the data is a URL, the phone offers to open it in a browser. If it is a WiFi configuration, it offers to connect. If it is a vCard, it offers to save the contact. The entire process -- from image capture to decoded data -- typically takes well under a second on modern smartphones.

Frequently Asked Questions

What are the finder patterns in a QR code?
The finder patterns are the three large squares located in the top-left, top-right, and bottom-left corners of every QR code. They allow scanners to detect the code's position, orientation, and size from any angle. Each finder pattern consists of a 7x7 module square with a specific ratio of black-white-black that is unique and easily detectable.
What happens if part of a QR code is damaged?
QR codes include Reed-Solomon error correction that can recover lost data. Depending on the error correction level, a QR code can still be scanned with 7% (Level L), 15% (Level M), 25% (Level Q), or 30% (Level H) of its data area damaged or obscured. This is the same technology that allows QR codes to have logos placed over part of them.
Why do QR codes have a white border?
The white border (called the quiet zone) helps scanners distinguish the QR code from its surroundings. Without a sufficient quiet zone (at least 4 modules wide), scanners may fail to detect where the code ends and the background begins, leading to scan failures. Always ensure your QR code has adequate white space around it.
How much data can a QR code store?
A QR code can store up to 7,089 numeric characters, 4,296 alphanumeric characters, or 2,953 bytes of binary data. The actual capacity depends on the QR code version (1-40) and the error correction level selected. Higher error correction reduces capacity. For most practical applications, keeping data under 300 characters ensures a small, easily scannable code.
Can QR codes be scanned upside down?
Yes. QR codes can be scanned from any angle -- 0, 90, 180, or 270 degrees and everything in between. The three finder patterns in the corners allow the scanner to determine the code's orientation regardless of how it is rotated. This is a significant advantage over traditional barcodes, which must be oriented correctly to scan.

Ready to create your QR code?

Start for free with Quality QR. Create static or dynamic QR codes with custom styling, analytics, and no expiration.