One extra barcode digit catches every one-digit change

The stripes get all the attention. The quietest piece of engineering in a UPC is the final digit.

Take the sample code 036000291452. The last 2 does not name a flavor, a package size or a manufacturer. It is a check digit: an answer computed from the eleven digits before it. If one digit is copied incorrectly, the answer usually stops matching.

For a UPC, the arithmetic alternates between multiplying digits by three and by one. Add the results, including the check digit, and a valid code lands on a multiple of ten:

0×3 + 3×1 + 6×3 + 0×1 + 0×3 + 0×1
+ 2×3 + 9×1 + 1×3 + 4×1 + 5×3 + 2×1 = 60

GS1's manual calculation describes the same method from the other direction: weight the digits, add them, then choose the final digit that reaches the next multiple of ten. The arithmetic is small enough to do on paper and strict enough to notice a surprisingly large class of mistakes.

I tried every one-digit mistake

I took that sample UPC and replaced each of its twelve digits with each of the other nine possibilities. That made 108 altered codes. Every one failed the check.

This is not luck peculiar to the sample. Changing one digit changes the sum by that difference, multiplied by either one or three. Neither multiplier can turn a nonzero change between digits into zero modulo ten. The new sum therefore cannot end in zero.

That is the useful bargain. One extra decimal digit gives the number enough redundancy to detect every single-digit substitution, including a mistake in the check digit itself. It does not need to know what product the code belongs to. It can reject the malformed number before any database lookup.

Detection is not correction. A failed check does not identify which digit is wrong or what it should have been; many different mistakes can spoil the same sum. The system can ask for a rescan or a second look, but it cannot reconstruct the intended UPC from the check digit alone.

The bargain has loopholes

People also swap neighboring digits. In my sample, there were nine adjacent swaps involving different digits, and the check caught all nine. But the method is not guaranteed to catch every transposition.

The weights reveal the escape hatch. Swap neighboring digits and each moves between a one-weighted and a three-weighted position. If the two digits differ by five, the changes cancel modulo ten. A Cornell lesson on check digits gives a neat example: both 016000291454 and the mistyped 061000291454 pass. The neighboring 1 and 6 traded places, but their difference is five.

Swaps farther apart can be even less visible. Two positions separated by one digit have the same weight, so exchanging their values does not change the sum at all. A check digit is error detection, not proof of identity and certainly not a tiny security system. Many wrong numbers can still be mathematically tidy.

A local answer before the lookup

When the first supermarket UPC scanners entered service in Troy, Ohio, in 1974, a laser read the label and a computerized register matched the result against stored product information. The Smithsonian's description of one of those scanners says a package of Wrigley's gum became the first purchase made with the new system.

The lookup and the check digit solve different problems. The database answers, “What item is this?” The final digit asks a smaller question first: “Is this number internally plausible?” That distinction still matters anywhere a number may be scanned, copied or typed by hand.

The check digit knows almost nothing. It cannot tell cereal from soap, and it cannot catch every rearrangement. It knows just enough arithmetic to object when one digit changes. For one extra character, that is an excellent little job.