How QR Codes Work
See what the squares in a QR code do, how error correction survives damage and how to make and scan codes sensibly.
Key takeaways
- A QR code holds data directly in its pattern, and most codes you see simply contain a web address.
- Finder, timing and alignment patterns let a camera locate and straighten the grid from many angles.
- Reed-Solomon error correction lets a code survive dirt or damage, at the cost of a denser pattern.
- Good contrast, a blank margin around the code and adequate size matter more than decoration.
- Check the address your phone shows before opening it, especially on stickers and unexpected messages.
A QR code is a two-dimensional barcode: a grid of dark and light squares that stores data, usually text such as a web address. A camera finds the three large squares in the corners, works out how the grid is tilted and scaled, reads each small square as a bit, and uses built-in redundancy to repair any it misread.
The code itself does nothing. Your phone decodes the text and then decides what to offer, such as opening a link or joining a network. Understanding that split helps you make codes that scan reliably and judge the ones you come across.
From barcode to grid
A traditional retail barcode stores a short number in the widths of vertical lines and is read in one direction. A QR code stores information across both height and width, so it fits far more into a small area. The name stands for "Quick Response". It was developed in the 1990s by Denso Wave, a Japanese company, for tracking automotive parts, and is now defined in the international standard ISO/IEC 18004.
Each small square is called a module. Codes come in 40 sizes, called versions. Version 1 is 21 modules on each side, each step up adds 4 modules per side, and version 40 is 177 modules square.
The maximum capacity, reached only at the largest size with the lowest error correction, is about seven thousand digits or a few thousand bytes. Practical codes carry far less, because dense patterns are harder to scan.
Basis: ISO/IEC 18004 QR Code symbol specification.
What the fixed patterns do
Much of the grid is there to help the reader, before any of your data appears.
The finder patterns are the three large nested squares in three corners. Their proportions look the same from any direction, so software can spot them quickly. Because only three corners have one, the reader also knows which way is up.
Timing patterns are lines of alternating modules running between the finders. They act as a ruler that tells the reader where each row and column falls.
Alignment patterns are smaller squares in larger versions. They help correct distortion from a curved surface or a steep viewing angle.
Format information, stored near the finders in two copies, records the error correction level and the mask in use. Larger versions also record their version number.
The quiet zone is the blank border. Without it, surrounding artwork can confuse the search for the finders.
How your text becomes squares
The encoder first picks a mode. Numeric mode packs digits tightly. Alphanumeric mode covers digits, capital letters and a few symbols. Byte mode handles anything else, including lowercase letters, and there is also a mode for Japanese characters. A web address with lowercase letters therefore takes more room than a string of digits of the same length.
The data is turned into a stream of bits, split into 8-bit codewords and divided into blocks. Error correction codewords are calculated for each block. The blocks are then interleaved, so that one smudge damages a little of several blocks instead of destroying one.
The bits are laid into the free modules in a zigzag path, starting at the bottom right.
Finally the encoder applies a mask, a regular pattern that flips selected data modules. Large blank patches or shapes resembling a finder could mislead a camera, so the encoder tries the eight standard masks, scores each result and keeps the best. The reader undoes the mask using the format information.
Error correction and damaged codes
QR codes use Reed-Solomon coding, a family of error-correcting mathematics also used on optical discs. Extra codewords let the reader reconstruct data even when some modules are unreadable.
| Level | Approximate share of codewords recoverable | Typical use |
|---|---|---|
| L | 7% | Clean screens, maximum data |
| M | 15% | General printing |
| Q | 25% | Rougher environments |
| H | 30% | Codes likely to be damaged or partly covered |
Higher levels need more modules for the same content. For a fixed printed size, that means smaller squares, which can be harder to scan. Choose a higher level for outdoor labels or a logo in the middle, and keep the content short.
A logo works by deliberately destroying part of the code and relying on repair. It uses up your safety margin, and covering a finder or other fixed pattern can break scanning altogether. Test on several phones.
What can be inside
Camera apps recognize certain text formats and offer a matching action:
- a web address beginning with
https:// -
mailto:andtel:links for email and phone calls - contact cards in vCard format
- Wi-Fi details in a widely supported format such as
WIFI:T:WPA;S:NetworkName;P:password;; - payment or ticket data defined by a particular app or system
Support varies, so test anything beyond a plain link. A Wi-Fi code reveals the password to anyone who photographs it, which makes a guest network the sensible choice.
You may see "static" and "dynamic" codes advertised. A static code contains your final destination. A dynamic code contains a short redirect address run by a service, which lets the owner change the destination and count scans. It also means the code stops working if that service closes or the subscription lapses, and the service sees each visit.
How a camera reads the code
Scanning runs the encoding steps in reverse, many times a second, on frames from your camera.
First the software turns the picture into pure black and white, choosing a threshold that copes with shadows and uneven light. It searches for the finder proportions, and once it has three of them it knows the corners of the symbol. Using those, the timing lines and any alignment squares, it calculates the perspective and samples the center of each module.
Next it reads the format information, removes the mask and collects the bits along the same zigzag path. The blocks are separated again, and Reed-Solomon decoding repairs wrong codewords. Only when the repair succeeds does the reader report a result. That is why a code usually either reads correctly or doesn't read at all, instead of giving you a slightly wrong address.
If a code won't scan, think about which stage is failing. Glare and low contrast defeat the black and white conversion. A missing margin or a covered corner defeats detection. Tiny, dense modules or camera blur defeat sampling. Moving closer, tilting away from reflections or adding light often solves it.
Related formats make other trade-offs. Micro QR is a smaller variant with a single finder pattern for very tight spaces, and Data Matrix and Aztec codes are other two-dimensional symbols you will see on components, parcels and tickets.
Make codes that scan
- Keep the content short. A shorter address produces a sparser, sturdier grid.
- Use dark modules on a light background with strong contrast. Inverted colors fail on some readers.
- Leave the quiet zone blank.
- Export a vector format such as SVG, or a large PNG, and don't stretch or blur it.
- Size for the viewing distance. A rough guide is a code width of at least a tenth of the distance, with about 2 cm as a comfortable minimum for handheld print.
- Print a proof and scan it under realistic light, on glossy and curved surfaces if that's where it will live.
- Put a readable address or description beside it for people who can't or won't scan.
Our QR code generator creates codes, and the QR scanner shows what a code contains. If you add tracking tags to a printed link, keep them brief, as explained in UTM parameters.
Scan with care
You can't read a QR code by eye, so a harmful link looks like any other. Criminals have placed stickers over genuine codes on payment signs and included codes in emails to move victims from a protected work computer to a phone. The article on QR code phishing covers the warning signs.
Read the previewed address before tapping. Be wary of shortened or misspelled domains, and check physical codes for signs of a sticker on top. Don't type a password or card number into a page just because a code led you there; open the organization's app or type its address yourself. Knowing the parts of a URL makes that preview much easier to judge.
Common questions
Do QR codes expire?
The pattern never expires. The destination can: a page can be removed, a domain can lapse or a redirect service can stop.
Can scanning a code infect my phone?
Decoding the text is low risk on an updated device. The danger usually lies in what you do next, such as signing in on a fake page or installing an app from outside the official store.