A QR code stores a message in a grid of light and dark squares. Three corner targets help a scanner line up the grid. It reads the message squares in a zigzag and undoes a pattern of color flips to recover the zeros and ones. In our example, those bits spell “hi.” A restaurant can put a web address in the same kind of code. Then the kitchen can change the menu at that address while the ink on the table stays exactly as it was.236
What can you spot before you scan?
Look at the three big targets in the corners. Each has a dark center, a light ring and a dark rim. The fourth corner looks like the rest of the jumble. Give the picture a quarter turn in your mind. Can you still point to the odd corner? A scanner uses the positions of those three targets to work out which way the grid is turned.23
Our code is 21 squares across and 21 down. Each little square is called a module. A blank margin four modules wide gives the symbol a clear edge. Between the top two targets, dark and light squares alternate like ticks on a ruler. Another line runs down the left. These timing patterns mark the spacing of the grid. Once a reader has lined it up, it can sample the center of every square, even in a patch of white where no edges are visible.1237
Which eight squares say “h”?
Our message is one word, “hi,” in lowercase. We wrote it in byte mode. A byte is eight bits, and each bit can be zero or one. In the character table called ASCII, lowercase h has the value 104. Written in eight bits, that’s 01101000. Lowercase i is the very next entry, 105. To get from h to i, only the last bit has to change.24
Start at the bottom right of our code. The reader works up the first two columns, taking the right square of each pair first. Once the mask is undone, the first four bits tell it to read bytes. The next eight say how many bytes to read. In our code that’s two, one for each letter. Those instructions take up six rows. The next four pairs on the same edge hold the h.23
Look at those four pairs in the enlargement. Count dark as one and light as zero. Start at the bottom and you get 11110001. Where did the h go? When it drew the code, the encoder applied a mask. It flipped selected squares to help break up long runs of one color and shapes that could be mistaken for a corner target. Our example uses a checkerboard rule.23
Keep your eye on the bottom-right square and switch to “Mask undone.” That square changes from one to zero. Three others flip with it. Read the four pairs upward again and you get 01101000. There’s our h. The same rule that disguised the letter on the way into the grid gives it back on the way out.234
Why so much ink for two letters?
The code records its choice of mask near the corner targets, so the reader knows which flips to undo. Follow the path a little farther and it turns back down the next pair of columns, then up the next, skipping the reserved markings. The length near the start tells the reader where “hi” ends. The encoder fills the unused message space with padding.23
Other squares hold check values calculated from the data. Say a smudge makes the scanner read a group of eight bits incorrectly. The data and the check values no longer agree. A method called Reed–Solomon error correction uses those mismatches to locate a damaged group and reconstruct its value. It can repair several such errors if enough check values are available. The scanner still has to find the grid in the first place.35
In a grid of a given size, every extra group reserved for error correction leaves less room for the message. Printing this same code twice as wide would give us bigger squares and exactly the same two letters. To make room for a longer message, the encoder can choose a grid with more squares across and down.15
