How do QR codes work? A plain explanation
What the squares in a QR code mean, how data and error correction fit inside, and what your phone does in the moment between scanning and opening a link.
The short answer
A QR code stores information as a grid of dark and light squares. Three large squares in the corners let a camera find the code and work out its angle, and the rest of the grid holds the data plus spare information that repairs damage. Your phone reads the grid, decodes the content, and offers to open the link, join the network or save the contact inside.
The parts of a QR code
Every small square in the grid is called a module. A dark module and a light module stand for two different values, much like the ones and zeros a computer uses. Some modules are fixed and help the camera read the code. The rest carry the content.
- Finder patterns: the three large squares in the top-left, top-right and bottom-left corners. They tell the camera where the code is and which way up it is.
- Timing patterns: two lines of alternating dark and light modules between the finder patterns. They tell the reader how big each module is.
- Alignment patterns: smaller squares that appear in all but the smallest codes. They help the reader correct for a curved or tilted surface.
- Format information: a strip next to the finder patterns that records the error correction level and the mask used.
- Data and error correction: everything else, filling the grid in a zigzag from the bottom-right corner.
How the data is encoded
Before anything is drawn, the content is turned into a string of bits. QR codes have several encoding modes, and the encoder picks the most compact one for the content. Numeric mode is for digits only and packs them tightly. Alphanumeric mode covers digits, capital letters and a few symbols. Byte mode handles anything else, including lowercase letters and most web addresses. A Kanji mode exists for Japanese characters.
The amount of data decides the code’s size, which the standard calls its version. Version 1 is a grid of 21 by 21 modules. Each version adds four modules to each side, up to version 40 at 177 by 177. A longer web address needs a higher version, which means more, smaller modules at the same printed size. That’s why short links are easier to scan.
Finally, the encoder applies a mask: a fixed pattern that flips some modules to avoid large blocks of one color or shapes that look like finder patterns. It tries eight masks, keeps the one that scans best, and records which it chose so the reader can undo it.
Error correction keeps damaged codes readable
QR codes use Reed–Solomon error correction, the same family of math used on CDs. Extra codewords are added alongside the data, and they let a reader rebuild missing or misread parts. There are four levels, from L, which can recover about 7% of the data, to H, which can recover about 30%.
This is why a code can survive a scratch, a coffee ring or a logo in the middle. It’s also why higher levels make bigger codes: the spare information takes up room in the grid.
The quiet zone
A QR code needs an empty border around it, called the quiet zone. The standard asks for four modules of plain background on every side. Without it, the camera can’t tell where the code ends and the surrounding text or picture begins, and a perfectly good code fails to scan.
What your phone does when it scans
Your camera is looking for the three finder patterns all the time. When it spots them, it works out the code’s position and angle, straightens the grid, and reads each module as dark or light. It reads the format information, undoes the mask, uses the error correction to repair anything it misread, and decodes the content.
Then the phone decides what to do based on what it found. A web address appears as a link you can tap. A Wi-Fi code offers to join the network. A contact card offers to save a contact. Plain text is simply shown. All of this usually takes a fraction of a second, and none of it needs an internet connection until you open a link.
Static and dynamic codes
The pattern works the same way in every QR code. What differs is what’s stored in it. A static code stores the final content: the full web address, or the Wi-Fi password. It never changes and needs nothing behind it.
A dynamic code stores a short link to a service. When you scan it, the service decides where to send you, so the owner can change the destination after printing, count scans, or send people to different pages by time or device. The pattern stays the same while the destination changes.
Questions
Who invented the QR code?
Denso Wave, a Japanese company, created the QR code in 1994 to track car parts in factories. QR stands for “Quick Response”. The format is now an international standard, ISO/IEC 18004.
Do QR codes need the internet to work?
No. Reading a code happens entirely on your phone. You only need a connection to open a web link from the code. Wi-Fi, contact and text codes work offline.
How much information can a QR code hold?
The largest version, at the lowest error correction level, holds up to 7,089 digits, 4,296 alphanumeric characters or 2,953 bytes. In practice, codes holding far less scan much more easily.
Can two QR codes look the same?
Two codes with the same content, version, error correction level and mask are identical. Change any of those and the pattern changes, even if the content is the same.
Related