Checkout
Nobody at a till has ever had to think about which way up to hold a tin. That is not the scanner being clever. It is the label carrying the answer.
New to encodings? Start here
A computer only has numbers
There are no letters in a computer, no colours and no sound. There are numbers, and an agreement about what a given number means. The letter A is a particular number because a committee said so, and for no other reason.
That agreement is an encoding, and the interesting part is never the table. It is what the table costs: how many bits each symbol takes, which symbols were favoured, what happens to the ones nobody thought of, and whether you can start reading in the middle. Every machine in this topic is an argument about that cost, settled differently.
The machine for this idea on its own is ASCII, if you would rather press it than read about it.
The label
A UPC-A symbol, ninety-five modules wide.
Guard bars at both ends and in the middle run taller than the rest. Between them, twelve digits at seven modules each: six on the left drawn in odd parity and six on the right drawn in even.
1 Scan: 95 modules of black and white, guards at both ends and the middle
2 Orient: odd parity on the left, even on the right, so backwards is obvious
3 Decode: seven modules a digit, through whichever table the half calls for
4 Check: weight three and one, mod ten, and what that can never catch
Sound, and no two neighbours in this number could be swapped without the check digit noticing.
Checked when this page loaded: of the 99 single-digit changes to this number, 0 go unnoticed. Of the 90 ways to swap a neighbouring pair, 10 go unnoticed, and every one of them is a pair differing by 5.
Troy, Ohio, a Wednesday morning
At about one minute past eight on 26 June 1974, in a Marsh supermarket in Troy, Ohio, Clyde Dawson took a ten-pack of Wrigley's Juicy Fruit out of a basket and drew it across a sheet of glass. Sharon Buchanan rang it up. The pack cost 67 cents and it did not need a price sticker.
Dawson had chosen the gum deliberately. The question in the room was whether a symbol could be printed small enough to fit on something that small and still be read, and a ten-pack of gum was the smallest thing anybody thought a shop would sell.
Almost everything written about that morning finishes by saying the pack is in the Smithsonian, and this page said it too until somebody read the museum's own record. It is not. What the museum holds is the scanner, a Spectra Physics model A and one of the first ten built, and what went on display was a facsimile of the gum. The record for the scanner says plainly that the scanned pack stayed with Clyde Dawson and never came to them. The correction is on the same page as the object we were citing for the claim.
Why the label is drawn twice
Each digit is seven modules wide and every digit has two spellings. The six on the left are drawn with an odd number of dark modules; the six on the right with an even number. The right-hand spelling is the left-hand one inverted, which is exactly what flips the parity.
That looks like redundancy and is not. Reversing a pattern does not change how many dark modules are in it, so a label dragged across the glass backwards still presents odd-parity patterns where the odd-parity patterns were. They simply arrive last. A scanner that meets an even-parity pattern first knows, before it has decoded a single digit, that it is reading from the wrong end. It turns the bits around and carries on.
The guard patterns are the other half of that. Their job is the pattern: 101 at each end, 01010 in the middle, in a code where no digit can produce either. That is what tells the beam where a digit begins, how wide a module is on this particular packet at this particular distance, and where the two halves divide. That those bars are drawn taller is a separate thing, about where a human or a scanner aims rather than about what is decoded: the pattern would work at the same height as the rest.
Why three and one
The twelfth digit is not part of the product number. It is chosen so that the first eleven, weighted alternately by three and one, add up with it to a multiple of ten.
Change any single digit and the total moves by one or three times the difference. Neither can land back on a multiple of ten unless the digit did not really change, because three and ten share no factor. So every single-digit error is caught. Not most of them. All of them.
Swap two neighbours and the total moves by twice their difference, and twice a difference of five is ten. Pairs differing by five are therefore invisible to it, and there are exactly five such pairs: 0 and 5, 1 and 6, 2 and 7, 3 and 8, 4 and 9. No amount of care at the till will catch one. The machine above tries every single-digit change and every neighbouring swap when the page loads, and reports what it actually found rather than asking you to take this paragraph's word for it.
Two things that are not in the digits at all
Everything above is about the number. A label that gets the number perfectly right can still be unreadable, because a barcode is not a fact about a bit string. It is a fact about a surface and a beam.
The first is the clear space at each end. Nine modules of it, and it is part of the symbol rather than a margin around it: the scanner uses it to know where the label starts, so a label crowded up against other printing is a label with no beginning. The nine modules on this page are inside the drawing, so they stay nine modules however wide it is shown.
The second is colour, and it is the one that catches people. A scanner works at around 660 nanometres, which is a red light, and it grades what comes back. Black ink absorbs that and returns almost nothing. Red ink returns nearly as much as white paper does. So a barcode with red bars is perfectly legible to you and simply is not there as far as the beam is concerned, which is why every printing guide says bars are black or dark blue or dark green, and never red, orange, pink or gold.
This page shipped with that mistake. The three guard groups were drawn in the machine's accent, which is a red, on the reasoning that the guards are what the beam finds first and so deserved the emphasis. Measured the way a verifier measures, at the wavelength the beam uses, those bars returned 9% where 70% is the top grade. The bars called out as the ones a scanner looks for first were the ones it could not see. They are black now, and the accent marks them from underneath.
These ran in this browser when the page loaded. Each claim, whether it held, and the number behind it.
| claim | held | measured |
|---|---|---|
| all 5 labels decode to the same 12 digits whichever way round they cross the glass | yes | and the scanner knows which way it was: reversing a pattern does not change how many ones are in it, so odd parity in the first position still means the left half arrived first |
| all 10 left-half patterns are odd parity and all 10 right-half patterns are even | yes | the right half is the inverse of the left, so this is one table and not two; a wrong bit anywhere would break the count |
| every one of 495 single-digit errors changes the check digit, so none of them gets past | yes | weights of 3 and 1 alternating, and a total that must be a multiple of 10; one wrong digit cannot leave that total alone |
| of 22 transpositions of neighbouring digits, 1 slip past unnoticed | yes | swapping a and b moves the weighted sum by 2(b - a), which is invisible exactly when the two differ by 5; found by trying every pair rather than by stating the rule |
| these checks cannot tell this table from the 45 others reachable by exchanging two of its rows | yes | structure is not identity, and this table's known failure is exactly that: swap seven and eight and everything above stays green while every seven and eight encodes wrong. Identity is witnessed against another implementation in tests/upc-cross.test.mjs and against the standard's own printed table, neither of which a page can reach while it loads |
| a UPC-A symbol is 95 modules wide, plus 9 of quiet space each end | yes | 12 digits of 7 modules, two end guards and a centre guard; the quiet space is part of the symbol and not a margin around it |
What is real here, and what is not
The circles came first, and the printing presses killed them
Woodland and Silver's patent, filed in 1949 and granted in 1952, drew the code two ways: as parallel lines, and as a bullseye of concentric circles. The bullseye is the famous one, and RCA built a pilot on it at a Kroger.
It lost to the presses. Grocery labels were printed cheaply and fast, and a press laying down too much ink smeared the rings into one another until the code could not be read. George Laurer's linear grid survives the same smear, because ink spreading on a straight bar makes it taller and a scan line reads across the widths, not down them. That is also why the bars are tall: the height is spare, and the information is entirely in the horizontal.
It models the decode, not the reading
A real scanner sweeps a raster of beams at many angles, catches fragments of the symbol as the packet moves, and stitches partial reads together. There is no laser here, no depth of field, no glare off a crumpled bag, and no failure to read at all, which in a shop is the common case.
Two things about the reading are real, though, because they are geometry and ink rather than optics: the nine-module quiet zone is in the drawing, and every bar is dark enough to grade A for symbol contrast at the wavelength a scanner uses. Both are checked on every build by screenshotting this label out of a browser and handing the image to the same decoders the rest of this workshop uses for QR codes. It reads back as 0036000291452, upright and upside down, on a phone and on a desktop.
This is UPC-A, and EAN-13 is not the same thing
The thirteen-digit symbol used outside North America looks nearly identical and works differently. Its left half mixes two parity tables, and the pattern of that mixing is how the thirteenth digit is carried. Everything here about parity meaning orientation is true of UPC-A and only partly true of EAN-13. Conflating the two is the most common mistake written about barcodes.
The first digit is not explained
The number system character has carried different meanings across fifty years and the conventions have shifted more than once. Rather than print a table that is half retired, this page treats it as another digit.
The bars are nominal
Real symbols are printed with deliberate compensation for ink spread, and those tolerances are part of the standard. These are drawn as exact modules, which is what the arithmetic describes and not quite what a press produces.
The minute rests on recollection
The date, the shop, the people and the product are documented. "8:01am" comes from accounts given afterwards and is repeated everywhere without a contemporaneous source. Treat the date as a record and the minute as a story.
Sources
- National Museum of American History, the Marsh supermarket scanner
- Smithsonian, object record for the same scanner
- HISTORY, 26 June 1974 and the first item scanned
- GS1 General Specifications — the standard that defines the symbol this page draws, by the body that defines it. It gives the structure the page builds on directly: “seven modules per symbol character”, four elements of one to four modules each, and the check digit arithmetic. It does not settle the encoding table, whose witness here is better than a document anyway: the test rebuilds all fifteen symbols and compares them module for module against bwip-js, an independent implementation, then reads the drawn symbol back with a real decoder.
- Universal Product Code, an encyclopaedia, kept for the history around the standard rather than the standard. The encoding tables and the check digit it used to carry have moved to GS1 above and to the cross-check in the tests.
- IBM, on the UPC and George Laurer
- Smithsonian, the history of the bar code
- cut-the-knot, barcode encoding worked through