Check Digits: Luhn, Barcodes, ISBN & the Mistakes They Miss

Type a card number, an IMEI, a barcode or an ISBN and choose the scheme that checks it. The page shows what each digit contributes and whether the number passes, then tries every mistake one slip away from it and lists the ones the check digit would not notice.

Loading interactive simulation...

Lesson

The theory โ€” Check Digits: Luhn, Barcodes, ISBN & the Mistakes They Miss

A check digit is one extra digit chosen so that the whole number satisfies a rule: here, that the digits, each multiplied or transformed according to its place, add up to a multiple of the modulus, 10 or 11. A mistake that breaks the rule is detected. One that keeps it is not, so a check digit can prove a number wrong and can never prove it right.

What each symbol means

dแตข
the digit i places from the right; the check digit is d0
wแตข
the weight of place i: 1 and 3 alternately for a barcode, i + 1 for ISBN-10
D(d)
Luhn's doubling: 2d, less 9 when that is more than 9, so 0 2 4 6 8 1 3 5 7 9
S
the sum of what every digit contributes
m
the modulus, 10 for Luhn and the barcode, 11 for ISBN-10; the number passes when S is a multiple of m
Assumes
One mistake at a time. Two mistakes in one number can cancel, and the page's counts say nothing about them. The ladder counts every pair of digits as equally likely, which real typing is not: Luhn's one blind neighbour pair is 09 and 90, and how often those two sit side by side depends on what the numbers are.
Breaks when
A check digit is not security. Anyone who knows the scheme can make a number that passes, which is why a card number that passes Luhn is only a number that was typed correctly, and ISBN-13 uses the barcode's scheme because an ISBN-13 is itself a barcode number, under the prefixes 978 and 979 that GS1 made available.

Luhn catches every swap of neighbours but one: 09 and 90 🖖

Press 1234567890 + check. Swap the 9 and the 0 and the result, 12345678093, passes. Luhn doubles every second digit and, when the double has two digits, adds them: 9 becomes 18 and then 9, and 0 stays 0. Swapping two neighbours moves the sum by the difference between what doubling adds to each, and doubling adds 0 to a 0, 1 to a 1, 4 to a 4, โˆ’4 to a 5, โˆ’1 to an 8 and 0 to a 9. The 0 and the 9 are the only two digits it treats alike, which is why the left-hand grid has exactly two red cells, 09 and 90, and the scheme catches 97.8% of neighbour swaps. Press IMEI: it has no 9 beside a 0, and none of its 13 neighbour swaps gets through.

No check digit made by adding digits mod 10 catches every swap 🖖

Press UPC barcode. Two of its nine neighbour swaps pass: the 3 with the 8, and the 0 with the 5. A barcode multiplies alternate digits by 3 and 1, so swapping a and b changes the sum by 2(a โˆ’ b), a multiple of 10 whenever they are five apart. That is 10 of the 90 pairs. Other weights do no better. To catch every single wrong digit, a weight must be 1, 3, 7 or 9 mod 10, any two of those differ by an even number, and an even number times 5 is a multiple of 10: 88.9% is the ceiling for any weighting. Luhn's doubling is not a weight, and it reaches 97.8%. It cannot reach 100%: Gallian gives H. P. Gumm's 1985 proof that no scheme adding up its digits, however each place transforms them first, can catch every single wrong digit and every swap of neighbours when the modulus is even. J. Verhoeff got both in 1969 by multiplying in the dihedral group of the pentagon, where the order of the factors matters.

Swap two digits one place apart and Luhn never notices 🖖

Press IMEI. All 12 of its swaps across one digit pass. The two digits sit at places of the same parity, so Luhn doubles both or neither, and the barcode gives both the same weight: swapping them cannot move the sum, and the ladder puts both schemes at 0.0%. ISBN-10 gives every place its own weight, 10 down to 1, so a swap changes the sum by the difference of two weights times the difference of two digits, and with 11 prime that product is never a multiple of 11. Press ISBN-13 and then ISBN-10: one number, and 9 of 9 such swaps get through the first against 0 of 6 through the second. It is a rare mistake, 0.8% of real errors in Verhoeff's count against 10.2% for neighbour swaps. And mod 11 has its own gap: it spends a symbol, X, on the check digit 10, and at the places weighted 6 and 5, which add to 11, it lets every twin mistake through.

Problem solved in full

  1. Recovering a smudged digit of an ISBN-10 4 steps

    An ISBN-10 reads 0-11-000?22-9, with the seventh digit smudged. Find it, and say why there is exactly one answer. Press ISBN-10 to check the result.

    Open this problem in the tool

    1. The weights run 10 down to 1 from the left, so the smudged seventh digit carries weight 4. Add up the other nine digits times their weights.

    2. The whole sum has to be a multiple of 11, so 4 times the missing digit must make up the difference.

    3. Mod 11 you can divide, because 11 is prime: 4 ร— 3 = 12 is 1 more than 11, so multiplying by 3 undoes multiplying by 4.

    4. Put the 2 back and the page's sum is 44, four elevens exactly.

    Answer

    The digit is 2, and the ISBN is 0-11-000222-9. It is the only digit that fits because multiplying by 4 sends the eleven values 0 to 10 to eleven different remainders mod 11, so exactly one of them lands on 8. That is the same property that lets the scheme catch every wrong digit at this place, seen from the other side: a weight that makes every single mistake visible also makes every single smudge recoverable. A mod-10 scheme with a weight of 2 at that place would give two candidates or none, and it would miss every wrong digit there that is five away from the right one.

References (3)