QR codes are everywhere now: on menus, parking meters, business cards, and the back of cereal boxes. Most people scan a dozen a week without ever wondering what those little black-and-white squares actually are. This guide explains what is going on inside a QR code, why they almost always scan on the first try, and what makes the rare one fail.
A QR code is a way to store text in a picture. The text might be a website link, a phone number, a WiFi password, or a short note. A scanner reads the pattern of black and white squares and turns it back into that text. That is the whole idea. The code is just a printed container for a small amount of data.
The name stands for Quick Response. The black and white squares are called modules. Each module is one bit of the stored data, either marked or blank, and the scanner reads thousands of them in a fraction of a second.
QR codes were invented in 1994 by Masahiro Hara and his team at Denso Wave, a Japanese company that supplies parts to Toyota. The factory needed a better way to track car parts as they moved down the line. The barcodes they used at the time held very little data and had to be lined up just right to scan.
Hara wanted a code that held more information and could be read fast from any angle. The story goes that he got the idea for the square finder patterns, the three big squares in the corners, while playing the board game Go during a lunch break. Those corner squares are what let a scanner find the code and figure out which way is up, even if the code is upside down or tilted.
Denso Wave still holds the patent on QR codes but chose to let anyone use them for free. That decision is a big reason the codes spread to every corner of the world.
A QR code looks random, but every section has a job. Once you know what to look for, you can spot the structure in any code.
The three large squares in the corners. The scanner looks for these first to locate the code and work out its size, angle, and orientation.
Smaller squares spread through the code on all but the tiniest versions. They help the scanner stay accurate when the code is printed on a curved surface or photographed at an angle.
A line of alternating black and white modules running between the finder patterns. It acts like a ruler, telling the scanner exactly where each row and column sits.
The blank margin around the code. It needs to be clear, about four modules wide, so the scanner can tell where the code ends and the background begins.
A few strips of modules near the finder patterns that tell the scanner the code's size and which error correction level it uses, before any real reading begins.
Everything else. This is where your actual text lives, along with the backup information that lets a damaged code still scan correctly.
When you point a camera at a QR code, a lot happens in well under a second. The scanner finds the three corner squares and uses them to lock onto the code. It measures the angle and corrects for any tilt, so a code held sideways reads the same as one held straight. It then maps out the grid of modules using the timing pattern as a guide.
Once the grid is mapped, the scanner reads the format information to learn the version and error correction level. It walks through the data modules in a set zigzag order, turns the marked and blank squares into ones and zeros, and reassembles the original text. Finally it checks the error correction data to confirm the result is correct, and only then hands the text to your phone.
QR codes pack data more tightly when it is simple. A code encoding only digits holds more than a code encoding letters and symbols, because digits take fewer bits to store. There are four storage modes:
At the largest size, a single QR code can hold roughly 7,000 digits, about 4,300 letters and symbols, or close to 3,000 bytes of general text. In practice you almost never get near those limits, because a longer message needs a bigger, denser code that is harder to scan. Short and simple scans best.
QR codes come in 40 sizes, called versions. Version 1 is a grid of 21 by 21 modules. Each step up adds four modules to every side, so the codes get denser as they hold more data, all the way up to version 40 at 177 by 177 modules.
The more you ask a code to store, the higher the version it needs, and the smaller each module becomes at a fixed print size. That is the main reason a short link makes a friendlier, more reliable code than a long one. If you can shorten what goes in, do it.
One of the cleverest parts of a QR code is that it keeps working even when part of it is missing. A coffee stain, a crease, or a small logo placed on top will not stop the scan. This is thanks to error correction, a method that stores backup copies of the data using a technique called Reed-Solomon coding, the same math used on CDs and in deep-space radio.
There are four error correction levels, and the code's creator picks one when it is made:
Higher protection means the code carries more backup data, which makes it denser for the same message. For a clean code printed on paper, a lower level is fine. For a code on a sign that will face weather, sun, and scuffs, a higher level is worth the extra density.
There are two ways a QR code can point to a link. A static code stores the destination directly in the pattern. A dynamic code stores a short redirect link that bounces through a company's server to reach the real destination. The difference matters for cost, privacy, and how long the code keeps working. We cover it in full in our guide to static versus dynamic QR codes.
QR codes are forgiving, but a few mistakes still break them. Almost every failed scan traces back to one of these:
A good rule of thumb is that a code should be at least one tenth as wide as the distance people scan it from. A code on a business card held in the hand can be small, around one inch. A code on a table tent needs an inch and a half or more. A code on a window or yard sign meant to be scanned from the sidewalk should be several inches across. When unsure, go larger. A code that is too big just looks bold; one that is too small simply does not work.
Because a QR code hides its destination inside a pattern, you cannot read a link with your eyes before you scan it. Scammers have started printing fake codes and sticking them over real ones, on parking meters and restaurant tables, to send people to lookalike payment pages. This trick has a name now: quishing, short for QR phishing. The defense is simple. Before you act on a scanned link, glance at the web address your phone shows you, and be wary of any code that asks for a password or a payment on a page you did not expect.
Now that you know what is inside a QR code, you can make one in a few seconds. StackQR builds static codes right in your browser, so the data you type, like a WiFi password or a phone number, never leaves your device. Type what you need in plain English, pick a format, and you have a code that works for as long as the link behind it does.