An EAN-13 barcode encodes 13 digits. Twelve of them are data; the last is a check digit - a calculated number that allows the scanner to verify its own read without consulting any database. It is one of the most quietly elegant pieces of everyday engineering in commerce: five lines of arithmetic that silently prevent millions of scan errors every day. This article walks through exactly how it works.
Why it exists
A retail scanner reads a barcode and needs to know immediately whether it decoded correctly. It cannot make a network call to verify - at a checkout scanning hundreds of items per minute, that latency is impossible. The check digit makes the code self-verifying: after reading the 12 data digits, the scanner runs the same algorithm the encoder ran, and compares the result to the 13th digit. If they match, the scan is accepted. If they disagree, the scan is rejected silently and the scanner tries again.
The algorithm catches single-digit errors with near certainty - any one incorrect digit changes the weighted sum and almost always produces a wrong check digit. It also catches most adjacent transpositions: swapping two neighboring digits shifts one from an x1 position to an x3 position and the other in reverse, changing the total. The only transpositions it misses are swaps between digits that differ by 5 (0 with 5, 1 with 6, 2 with 7, and so on), which are uncommon in practice. The GS1 General Specifications document the full error detection properties in detail.
The algorithm
An EAN-13 barcode has 12 data digits (positions 1 through 12) and 1 check digit (position 13). Calculate the check digit as follows:
- Multiply the digits at odd positions (1, 3, 5, 7, 9, 11) by 1.
- Multiply the digits at even positions (2, 4, 6, 8, 10, 12) by 3.
- Sum all 12 products.
- Compute
sum mod 10. - Check digit =
(10 - (sum mod 10)) mod 10.
The outer mod 10 in step 5 handles the special case where the sum is already a multiple of 10: (10 - 0) mod 10 = 0, so the check digit is 0, not 10. Without it you would occasionally get an 11th possible check value, which would require an 11-digit modulus - the whole point of the design is that one additional decimal digit is sufficient.
Worked example: 5901234123457
This is a real, valid EAN-13 from GS1 Poland (prefix 590). The 12 data digits are 590123412345 and the check digit is 7. Here is the calculation:
| Position | Digit | Weight | Product |
|---|---|---|---|
| 1 | 5 | x1 | 5 |
| 2 | 9 | x3 | 27 |
| 3 | 0 | x1 | 0 |
| 4 | 1 | x3 | 3 |
| 5 | 2 | x1 | 2 |
| 6 | 3 | x3 | 9 |
| 7 | 4 | x1 | 4 |
| 8 | 1 | x3 | 3 |
| 9 | 2 | x1 | 2 |
| 10 | 3 | x3 | 9 |
| 11 | 4 | x1 | 4 |
| 12 | 5 | x3 | 15 |
Sum: 5 + 27 + 0 + 3 + 2 + 9 + 4 + 3 + 2 + 9 + 4 + 15 = 83
83 mod 10 = 3
Check digit: (10 - 3) mod 10 = 7
The last digit of 5901234123457 is 7. Verified correct. You can check any GTIN against the GS1 check digit calculator.
The same algorithm runs every GS1 format
The EAN-13 algorithm is the foundation of all GS1 linear barcode check digits. Every format below uses the identical alternating x1/x3 weight scheme - the only thing that changes is which position gets which weight, determined by the total digit count (the rightmost data digit always gets weight x3).
UPC-A (11 data digits + check = 12 total): UPC-A is EAN-13 with an implicit leading zero. A US barcode prefix of 0 occupies EAN-13 position 1 (weight x1, contributes 0), shifting all UPC-A positions by one - so UPC-A digit 1 lands in EAN-13 position 2 and gets weight x3. The check digit is identical whether you treat the code as UPC-A or as EAN-13 with a leading zero. They are the same barcode. This is why a GS1 US prefix appears as 0 in the first digit of an EAN-13: it was already a UPC-A.
EAN-8 (7 data digits + check = 8 total): identical algorithm, smaller symbol. Used for small products where an EAN-13 would not fit - a lip balm tube, a small battery pack, a portion-sized product. Allocated and licensed by national GS1 organizations because the compressed number space is a limited resource.
ISBN-13: literally identical to EAN-13. An ISBN-13 is an EAN-13 barcode that uses the prefix 978 or 979, allocated to the book industry by the International ISBN Agency. The ISBN-13 check digit is the EAN-13 check digit, calculated the same way. ISBN-13 replaced ISBN-10 on barcode labels in 2007; if you encounter a legacy ISBN-10, note that its check algorithm is completely different (mod 11, with weights 10, 9, 8 down to 1, and X representing 10).
GTIN-14 (13 data digits + check = 14 total): used on shipping cartons, outer cases, and trade units. Wraps a GTIN-13 (EAN-13) by prepending a packaging indicator digit (1-8) or zero. Same algorithm, same formula.
SSCC-18 (17 data digits + check = 18 total): the Serial Shipping Container Code on logistics pallet labels. Same algorithm at a larger scale.
Code 128 uses a completely different scheme
Code 128 - the symbology underlying GS1-128, UPS and FedEx shipping labels, and most warehouse barcodes - does not use mod 10 at all. Its check character is calculated as: (start symbol value + sum of position x codeword value for each data codeword) mod 103. Start symbol values are Code A = 103, Code B = 104, Code C = 105.
The Code 128 check character is embedded in the physical symbol and is transparent to users. The encoder calculates it automatically and it is not returned as part of the decoded data string. When a GS1-128 label encodes a GTIN in the (01) Application Identifier, there are two simultaneous verification mechanisms: the GTIN's own mod-10 check digit as part of the encoded payload, and the Code 128 mod-103 check character in the barcode structure. They operate independently.
What the prefix tells you
The first 2-3 digits of an EAN-13 identify which GS1 Member Organization issued the company prefix - not where the product was manufactured or sold. A barcode starting with 890 (GS1 India) means the brand owner registered their company prefix with GS1 India. The product might be manufactured in China, sold in Germany, and shipped globally.
Commonly encountered prefixes:
| Prefix range | GS1 Member Organization |
|---|---|
| 000-099 | GS1 US (020-029 and 040-049 restricted for in-store / internal use) |
| 300-379 | GS1 France |
| 400-440 | GS1 Germany |
| 450-459, 490-499 | GS1 Japan |
| 500-509 | GS1 UK |
| 590 | GS1 Poland (our worked example) |
| 690-699 | GS1 China |
| 754-755 | GS1 Canada |
| 789-790 | GS1 Brazil |
| 800-839 | GS1 Italy |
| 840-849 | GS1 Spain |
| 880 | GS1 South Korea |
| 890 | GS1 India |
| 930-939 | GS1 Australia |
| 977 | ISSN (serial publications) |
| 978-979 | ISBN (books, worldwide) |
Common mistakes
Entering all 13 digits as data. If you supply a full 13-digit EAN to a generator that auto-appends a check digit, you get 14 digits and a wrong barcode. Supply 12 digits and let the encoder compute the 13th, or supply all 13 and use a generator that validates the check digit you provide. Barcode Press handles both.
Transcription errors. Mistyping a GTIN from memory or a spreadsheet is the most common source of check digit failures. Even a single transposed digit changes the weighted sum. Verify against the GS1 check digit calculator before printing at scale.
Inventing digits. A made-up 12-digit string will almost certainly produce a wrong check digit compared to any existing GTIN in the market. If you need a real GTIN, register with GS1 US (or your national GS1 organization). If you need a barcode for internal use only, Code 128 with a custom internal numbering scheme is the right tool - not a fabricated EAN-13.
Assuming prefix = country of manufacture. A German prefix (400-440) on a product sold anywhere does not mean it was made in Germany.
Off-by-one in position numbering. The GS1 specification counts positions from 1. Code that counts from 0 will flip which positions get x1 vs x3, producing wrong check digits for any barcode whose first digit is non-zero.