How a Barcode Turns Stripes Into a Price
“The stripes on a cereal box aren't a picture — they're a number written in a language of light and dark. And hidden in that number is a clever trick that stops the scanner from ever charging you for the wrong item.”
Look closely at the stripes on any product in your kitchen. They seem random — thick bars, thin bars, wide gaps, narrow gaps. But there's nothing random about them. That pattern is a number, written in a language a laser can read in a thousandth of a second.
And it's a language you already understand: binary. A dark bar means one thing, a light space means the other. Just like the 1s and 0s inside a computer, a barcode is only two symbols, repeated in a careful pattern.
Stripes Are Just Ones and Zeros
Zoom in and a barcode is built from a grid of equal-width slivers called modules. A module is either dark or light. Read left to right, a dark module is a 1 and a light module is a 0.
The most common retail barcode, UPC-A, uses 95 of these modules to store 12 digits. Each digit is drawn as a group of 7 modules in a specific pattern. For example, the digit 0 on the left half of the code is always the pattern 0001101 — space, space, space, bar, bar, space, bar.
So the whole "picture" is really just a 95-character string of 1s and 0s that happens to be printed as stripes.
Guard Bars: Knowing Where to Start
There's a problem. A scanner might sweep across the code left-to-right, right-to-left, fast, slow, or at an angle. How does it know where the number begins, or which way round it is?
The answer is guard bars — fixed patterns that never change:
| Position | Pattern | Job |
|----------|---------|-----|
| Start | 101 | marks the left edge |
| Middle | 01010 | splits the two halves |
| End | 101 | marks the right edge |
Because these guards are always the same, the scanner can spot them and figure out the layout no matter how the code is swept. The left digits and right digits even use slightly different patterns, so the scanner can tell if it read the code backwards and simply flip the result. That's why you can wave almost any orientation past a supermarket scanner and it still beeps.
The Clever Part: the Check Digit
Here's the trick that makes barcodes trustworthy. Of the 12 digits, the first 11 identify the product. The 12th is calculated from the other 11 using a fixed recipe:
- Add the digits in the odd positions (1st, 3rd, 5th…, 11th) and multiply by 3.
- Add the digits in the even positions (2nd, 4th…, 10th).
- Add those two results together.
- The check digit is whatever you'd add to reach the next multiple of 10.
When the scanner reads a code, it runs this same calculation on the first 11 digits and checks whether the answer matches the 12th digit it read. If a smudge, a scratch, or a bad angle caused even a single digit to be misread, the maths won't line up — and the scanner rejects the read and beeps for a re-scan.
That's why you almost never get charged for the wrong item because of a bad scan. The barcode carries its own proof. Try it in the interactive above: change any of the first 11 digits and watch the check digit's badge flip from green to red the instant the number stops adding up.
The Price Isn't in There
One last surprise: the barcode doesn't contain the price, the product name, or anything but an ID number. The scanner reads the number, then looks it up in the store's database to find the price. That's why a store can change a price without reprinting a single label — the object carries only its name, and the meaning lives somewhere else.
A one-dimensional row of stripes can only hold so much, though — about a dozen digits. What if you wanted to pack in a whole web address, or a Wi-Fi password? For that, the code had to grow a second dimension — which is exactly where QR codes come in.
Ready to explore?
4 interactive activities waiting in the next tab.
The check digit catches any single wrong digit, and most cases where two neighbouring digits get swapped. But it can miss some errors — for example, certain pairs of swapped digits slip through. Why might a simple check like this fail to catch every possible mistake, and what would you trade to catch more of them?
Reflect
A barcode is just a number, and the price isn't in it at all — it's looked up from a database. That means the same physical box can change price without reprinting anything. What are the upsides and downsides of storing an ID on the object but keeping the real information somewhere else?