How Do QR Codes Work?
A QR code looks random, but every square has a job. Here’s what a camera sees, and why a scratched or logo-covered code still works.
A short history
QR codes were invented in 1994 by Masahiro Hara’s team at Denso Wave, a Toyota group company, to track parts in car factories faster than traditional barcodes allowed. Denso Wave chose not to enforce its patent, and the format became an international standard, ISO/IEC 18004. “QR Code” is a registered trademark of Denso Wave Incorporated.
Modules and versions
The small squares in a QR code are called modules. A dark module is a 1 and a light one is a 0, though not in a simple left-to-right order. Codes come in 40 sizes, called versions. Version 1 is 21 × 21 modules; each version adds four modules per side, up to version 40 at 177 × 177. Generators choose the smallest version that fits your content, which is why longer content produces denser codes.
The parts a scanner looks for
- Finder patterns: the three large squares in the corners. Their ratio of dark to light (1:1:3:1:1) is distinctive from any angle, so a camera can find the code and work out its rotation.
- Alignment patterns: smaller squares in larger codes that help correct for perspective and curved surfaces.
- Timing patterns: alternating rows of modules between the finder patterns that let the scanner measure the grid.
- Format information: strips next to the finders recording the error correction level and mask used.
- Quiet zone: the blank margin around the code, which separates it from its surroundings. The standard calls for four modules.
Encoding the data
Content is stored in one of several modes. Numeric mode packs three digits into 10 bits. Alphanumeric mode handles capital letters, digits and a few symbols. Byte mode stores anything else, including lowercase letters and UTF-8 text in any language. A version 40 code can hold up to 7,089 digits, 4,296 alphanumeric characters or 2,953 bytes.
Error correction: why damaged codes still scan
Extra data calculated with Reed–Solomon codes, the same family of math used on CDs and in satellite links, is added alongside your content. If part of the code is unreadable, the scanner reconstructs it from this extra data. There are four levels:
| Level | Approximate recovery | Typical use |
|---|---|---|
| L (Low) | 7% | Clean screens, maximum capacity |
| M (Medium) | 15% | Most print and digital uses |
| Q (Quartile) | 25% | Industrial labels, outdoor use |
| H (High) | 30% | Codes with logos, harsh conditions |
The data is split into blocks, and each block can recover a limited number of damaged codewords. That’s why the position and size of a logo matter, not just its area. Ziqeno checks this block by block when you add a logo.
Masking
Large solid areas or patterns that look like finder squares would confuse a scanner. So the encoder tries eight mask patterns, each flipping modules in a fixed pattern, and keeps the one that produces the most even, scanner-friendly result. The format information tells the scanner which mask to undo.
What the scanner does
A phone finds the three finder patterns, works out the grid size and angle, samples each module, reads the format information, removes the mask, corrects errors and decodes the content. Then it decides what to offer you: open a link, join Wi-Fi, add a contact and so on, based on the content’s format.