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 a_{1}a_{2}a_{3}a_{4}a_{5}a_{6}a_{7}a_{8}a_{9}a_{10}a_{11}*D*, the number *S* is:

*S* = 3a_{1} + a_{2} + 3a_{3} + a_{4} + 3a_{5} + a_{6} + 3a_{7} + a_{8} + 3a_{9} + a_{10} + 3a_{11}

**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.