How Barcodes Read A Product
A laser or camera scans a pattern of lines and turns it into a number β and a number into a product, a price, and a place in the world.
A barcode is just a font for machines. The width of each bar and gap encodes digits; the scanner reads the bars and turns them back into a number.
The pattern
A standard UPC-A barcode has 59 bars of varying widths β black bars and white gaps. The widths aren't random: each digit from 0β9 is encoded as a unique pattern of two bars and two gaps, each 1, 2, 3, or 4 units wide. The pattern is the same idea as Morse code, drawn in rectangles.
The scanner's job
- A laser (or, in modern scanners, a camera) sweeps across the bars.
- Dark bars absorb light; white gaps reflect it.
- A sensor measures the timing of reflections β long flashes = wide gaps, short flashes = narrow gaps.
- The timing pattern is decoded back into digits.
The hidden structure
A UPC isn't one random number. It's:
- 6 digits identifying the manufacturer (assigned by GS1, the global standards body).
- 5 digits for the product (chosen by the manufacturer).
- 1 final check digit, computed from the previous 11, that lets the scanner detect a misread.
If the check digit doesn't match, the scanner rejects the read and asks for another pass.
Two-way reading
A UPC is symmetrical but mirror-encoded: the left half and right half of the same digit are exact mirror images. That's why the scanner can read the code in any direction and still figure out which way is "forward."
From bars to product
The scanner sends the decoded number to the store's system. The system looks up the number in a database and returns the product name and price. The barcode doesn't contain the price β it contains only the ID. The price lives in the store's database, which is why the same product can ring up different prices in different stores.
The quiet zones
The blank space on either end of the barcode. Without them, the scanner can't tell where the code starts and stops. The whole system rests on a few millimeters of white space at each end.
A barcode is, in the end, a number painted in stripes β a font designed to be read by light at arm's length, in any direction, in a fraction of a second.
Written with π by Waela Β· Back to The Side Quest
Built with π by Waela
Keep going down the rabbit hole
How QR Codes Work
A QR code looks like a glitchy chessboard, but it's an engineered grid that can survive coffee stains, sun glare, and a 30-degree tilt.
How Noise-Canceling Headphones Work
They don't block sound β they fight it. Inside each earcup, a microphone listens and broadcasts the exact opposite of what it hears.
How Tap-To-Pay Works
You tap, you beep, you leave. Behind that half-second is a handshake, a cryptography trick, and a one-time-use number.
How Elevators Decide Where To Go
In a busy building, the elevator you're waiting for isn't the one closest to you β it's the one a computer thinks should come.