How to Calculate a UPC Check Digit (and EAN)
Calculate a UPC-A, EAN-13, EAN-8 or ITF-14 check digit with one rule: weight 3,1,3,1 from the right. Four worked examples, checked in code.
The one rule behind every check digit
To calculate a UPC check digit, multiply the digits before it by 3 and 1 in turn, starting with 3 on the digit nearest the check position, add them up, and take whatever it takes to reach the next multiple of 10. That is the whole method. The same rule works for UPC-A (11 digits before the check), EAN-13 (12), EAN-8 (7) and ITF-14 (13), because all four count the weights from the right. Many guides explain it as odd and even positions counted from the left, which gives the same answer for UPC-A but looks different for each format. Counting from the right means you only learn one rule. The steps: 1) Write the digits without the check digit. 2) Starting at the right, weight them 3, 1, 3, 1 and so on. 3) Add the products. 4) Check digit = (10 minus the sum's last digit) mod 10.
UPC-A: worked example
The UPC-A check digit for 03600024145 is 7. Weight the 11 digits from the right, 3 then 1 alternating: 5x3=15, 4x1=4, 1x3=3, 4x1=4, 2x3=6, 0, 0, 0, 6x3=18, 3x1=3, 0x3=0. The sum is 53. The last digit of 53 is 3, and 10 minus 3 is 7, so the full code is 036000241457. If the sum already ends in 0, the check digit is 0, not 10. We ran this in code and cross-checked it with the jsbarcode library the Barcode Generator uses: it accepts 036000241457 and prints the same 7. Change the last digit to 8 and it refuses the code.
EAN-13: worked example
The EAN-13 check digit for 400638133393 is 1. The rule is unchanged: 12 digits before the check, weighted 3,1,3,1 from the right. From the right: 3x3=9, 9x1=9, 3x3=9, 3x1=3, 3x3=9, 1x1=1, 8x3=24, 3x1=3, 6x3=18, 0, 0, 4. The sum is 89, the last digit is 9, and 10 minus 9 is 1. The full code is 4006381333931. The Barcode Generator takes 12 digits and adds the 13th, or takes all 13 and verifies them. Note that the rightmost digit always gets weight 3, whatever the format, so you never need to ask whether a position is odd or even.
EAN-8 and ITF-14: worked examples
EAN-8 and ITF-14 use the same rule on a different number of digits. For EAN-8, take 9638507. From the right: 7x3=21, 0, 5x3=15, 8, 3x3=9, 6, 9x3=27. The sum is 86, so the check digit is 4 and the full code is 96385074. For ITF-14, take 1234567890123. From the right: 3x3=9, 2, 1x3=3, 0, 9x3=27, 8, 7x3=21, 6, 5x3=15, 4, 3x3=9, 2, 1x3=3. The sum is 109, so the check digit is 1 and the full code is 12345678901231. Both results match what jsbarcode produces. In the Barcode Generator, EAN-8 takes 7 or 8 digits and ITF-14 takes 13 or 14.
A UPC-A is an EAN-13 with a leading 0
A UPC-A and an EAN-13 with a leading zero have the same check digit. Take the UPC-A 036000241457 and put a 0 in front: 0036000241457. Run the EAN-13 calculation on 003600024145 and you get 7, the same digit. The reason is the right-to-left weighting. Adding a 0 on the left changes no existing weight, and the new digit adds 0 times its weight, which is nothing. This is why scanners and retail systems can treat a 12-digit UPC as a 13-digit code padded with a zero. In the Barcode Generator, the EAN-13 value 0036000241457 draws the same bars as UPC-A 036000241457 (only the blank margin padding differs) and shows the same 7.
What a wrong check digit does
A wrong check digit makes the Barcode Generator reject the code. Enter 036000241458 as UPC-A and the tool says: "That value isn't valid for this format. If it includes a check digit, the check digit may be wrong. Remove it to have one added." Do what it says: delete the last digit and enter the first 11, and the tool adds the correct 7. The tool does this because it checks any full-length value. A wrong length gets its own message, such as how many digits the format needs and how many you entered. A code that fails its own check digit is exactly what the digit exists to flag, so fix it before printing rather than hoping a scanner copes.
What a check digit catches, and what it misses
A check digit catches every single-digit typo but not every transposition. A wrong digit changes the sum by its difference times a weight of 1 or 3, and neither can be a multiple of 10, so the check always changes. We tested 20,000 random UPC-A codes with every possible single-digit change, and none slipped through. Swapped neighbors are different. Swapping two adjacent digits shifts the sum by twice their difference, so it slips through when the digits differ by exactly 5. Real example: 501234567890 and 051234567890 are both valid UPC-A codes, because swapping the 5 and the 0 moves the sum by 10. The generator accepts both. So a valid check digit means the code is internally consistent, not that it is the number you meant.
Frequently asked questions
Try it on PixelTools — free, no upload needed