How Barcode Check Digits Work (EAN-13, UPC-A, EAN-8)
Almost every product you buy carries a barcode whose final digit isn't part of the product number at all — it's a check digit, a single digit calculated from the others to catch scanning and typing mistakes. This guide explains how that digit works on the three most common retail formats — EAN-13, UPC-A and EAN-8 — with a worked example you can follow by hand.
What a check digit is for
A check digit is a form of built-in redundancy. The barcode's data digits already identify the product; the check digit adds no new information about the item itself. Instead it encodes a relationship that must hold among all the digits, so that if a scanner misreads a bar or a person types a number wrong, the relationship breaks and the error is detected immediately rather than silently accepted.
The scheme used by retail barcodes is GS1 modulo 10. It is deliberately simple — a handful of multiplications and one subtraction — because a checkout scanner must verify it thousands of times a day, instantly and reliably.
The GS1 modulo-10 algorithm
Take all the digits except the final check digit. Starting from the right-most of those data digits and moving left, multiply the digits alternately by 3 and 1. Add up all the products. The check digit is whatever value you must add to that sum to reach the next multiple of ten.
Written as a formula: check = (10 − (weighted sum mod 10)) mod 10. The outer 'mod 10' handles the case where the sum is already a multiple of ten, which makes the check digit zero.
- Weights alternate 3, 1, 3, 1 … starting from the right-most data digit.
- Only the final digit is the check digit; everything before it is data.
- The same algorithm is used for EAN-13, UPC-A and EAN-8 — only the length differs.
A worked example
Take the EAN-13 data 400638133393 (twelve digits; the thirteenth will be the check digit). Reading from the right and weighting 3, 1, 3, 1 …, the products are 3×3 + 9×1 + 3×3 + 3×1 + 3×3 + 1×1 + 8×3 + 3×1 + 6×3 + 0×1 + 0×3 + 4×1, which add up to 89.
The next multiple of ten above 89 is 90, so the check digit is 90 − 89 = 1. The complete, valid barcode is 4006381333931. If a scanner had instead read the last digit as a 7, the recomputed check would not match and the read would be rejected on the spot.
Why weighting by 3 catches more errors
The alternating weight of 3 is not arbitrary. A plain sum of digits would catch any single wrong digit, but it would miss a very common human error: transposing two adjacent digits, such as typing 21 as 12. Multiplying alternate positions by 3 gives transposed neighbours different weights, so most transpositions change the total and are caught.
No single check digit can catch every possible error — modulo-10 with weight 3 misses transpositions of two digits that differ by 5, and any pair of mistakes that happen to cancel out. It is a cheap, fast safeguard against the most frequent mistakes, not a cryptographic guarantee.
EAN-13, UPC-A and EAN-8
The three formats differ only in length. EAN-13 has 12 data digits plus 1 check digit and is the global standard. UPC-A, common in North America, has 11 data digits plus 1 check — and is in fact an EAN-13 with a leading zero. EAN-8 packs 7 data digits plus 1 check into a shorter symbol for small items where a full barcode won't fit.
Because they share the modulo-10 algorithm, the same calculation validates all three; you only need to know how many digits to expect. A 13-digit ISBN printed as a barcode is also an EAN-13 and uses this exact check digit, which is why a book's barcode can be validated the same way as a tin of beans.