The Check Digit

When the bar code is entered by the bar reader, or by a human being, the machine instantly makes the following calculation:

  • Add the first, third, fifth, seventh, ninth and eleventh numbers.
  • Multiply this result by 3.
  • Add to this result the sum of the second, fourth, sixth, eight and tenth numbers.
  • Call this sum S.

For the UPC code digit a1a2a3a4a5a6a7a8a9a10a11D, the number S is:

S = 3a1 + a2 + 3a3 + a4 + 3a5 + a6 + 3a7 + a8 + 3a9 + a10 + 3a11

Note: S is an example of a weighted sum with weights (3,1,3,1,3,1,3,1,3,1,3).

For the bar code example 81123400000, verify that the sum S = 43.

What then is "D", the check digit number for this code? Informally, D is the number that you must add to S to reach the next highest multiple of 10 above S.

For the bar code above, since S = 43, D must be 7, since 43 + 7 = 50, the next multiple of 10.

The formal definition of D is this: If r is the remainder when S is divided by 10, then D = 10 – r unless r = 0, in which case D = 0. Thus, since 43 = 10(4) + 3, the remainder is 3, and the check digit D is (again) 10 - 3 = 7.

An equivalent alternative definition for the check digit D for a code with sum S is that number D such that S + D is a multiple of 10.

Suppose that a person entered, instead, 811324000007. The number S for this code is S = 41, which should have a check digit of 9. So the operator or the computer immediately knows that an error has been made because the code gives the check digit to be 7.