How the EAN-13 Check Digit Is Calculated (With a Worked Example)
A complete walkthrough of the EAN-13 check digit algorithm, a worked example with a real barcode, why the check digit exists, and how the same algorithm underlies UPC-A, ISBN-13, and every GTIN format.
The EAN-13 check digit is the 13th digit of an EAN-13 barcode, calculated from the first 12. Multiply the digits in odd positions by 1 and the digits in even positions by 3, add the twelve products, and subtract the last digit of that sum from 10. If the sum already ends in 0, the check digit is 0. The scanner repeats the same arithmetic on every read and rejects any read where the result does not match.
Why it exists
A retail scanner reads a barcode and needs to know immediately whether it decoded correctly. It cannot wait on a network lookup for every item. 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 every single-digit error, because changing any one digit changes the weighted sum by an amount that is never a multiple of 10. It also catches most adjacent transpositions. Swapping two neighbouring digits moves one from an x1 position to an x3 position and the other in reverse, which changes 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 calculation is defined in the GS1 General Specifications.
The algorithm
An EAN-13 barcode has 12 data digits (positions 1 through 12) and 1 check digit (position 13). The calculation takes five steps.
- 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 case where the sum is already a multiple of 10. Then (10 - 0) mod 10 = 0, so the check digit is 0. Without the outer mod 10 the formula would give 10, an 11th possible value, and the design depends on one extra decimal digit being enough.
Worked example with 5901234123457
This is a valid EAN-13 with the 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 |
The sum is 5 + 27 + 0 + 3 + 2 + 9 + 4 + 3 + 2 + 9 + 4 + 15 = 83.
83 mod 10 = 3.
The check digit is (10 - 3) mod 10 = 7.
The last digit of 5901234123457 is 7, so the code is valid. You can check any GTIN against the GS1 check digit calculator.
The same algorithm runs every GS1 format
Every GS1 linear barcode uses the same alternating x1/x3 weight scheme. The only thing that changes is which position gets which weight, and that follows from the total digit count, because the rightmost data digit always gets weight x3.
UPC-A has 11 data digits plus a check digit, 12 in total. UPC-A is EAN-13 with an implicit leading zero. That zero occupies EAN-13 position 1 (weight x1, contributing 0) and shifts every UPC-A position along 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, which is why most GS1 US prefixes show up as a 0 in the first digit of an EAN-13. It was already a UPC-A. GS1 US also issues prefixes in the 100-139 range, and a GTIN-13 starting with 1 has no UPC-A form.
EAN-8 has 7 data digits plus a check digit, 8 in total. Same algorithm, smaller symbol. It is used on products too small for an EAN-13, such as a lip balm tube, a small battery pack, or a single-portion product. National GS1 organisations allocate and license EAN-8 numbers individually, because the compressed number space is a limited resource.
ISBN-13 is identical to EAN-13. An ISBN-13 is an EAN-13 barcode with 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. The ISBN itself moved to 13 digits on 1 January 2007. Book barcodes had used the 13-digit Bookland EAN form since the 1980s. A legacy ISBN-10 uses a different check algorithm (mod 11, with weights 10, 9, 8 down to 1, and X representing 10).
GTIN-14 has 13 data digits plus a check digit, 14 in total. It goes on shipping cartons, outer cases, and trade units, and wraps a GTIN-13 (EAN-13) by prepending a packaging indicator digit (1-8) or zero. Same algorithm, same formula.
SSCC-18 has 17 data digits plus a check digit, 18 in total. It is the Serial Shipping Container Code on logistics pallet labels, and it runs the same algorithm at a larger scale.
Code 128 uses a 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 (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 invisible to users. The encoder calculates it automatically and the decoder strips it before returning the data string. When a GS1-128 label encodes a GTIN in the (01) Application Identifier, two checks run independently. The GTIN carries its own mod-10 check digit inside the encoded payload, and the Code 128 symbol carries a mod-103 check character in its structure.
What the prefix tells you
The first 2-3 digits of an EAN-13 identify which GS1 Member Organisation issued the company prefix. They say nothing about where the product was manufactured or sold. A barcode starting with 890 (GS1 India) means the brand owner registered its company prefix with GS1 India. The product might be manufactured in China, sold in Germany, and shipped globally.
These are the prefixes you will meet most often.
| Prefix range | GS1 Member Organisation |
|---|---|
| 001-019, 030-039, 060-139 | GS1 US |
| 020-029, 040-049 | Restricted circulation (in-store and 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) |
| 680-681, 690-699 | GS1 China |
| 754-755 | GS1 Canada |
| 789-790 | GS1 Brazil |
| 800-839 | GS1 Italy |
| 840-849 | GS1 Spain |
| 880-881 | 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, because 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 scan, because the check digit is computed from whatever you type, but the number belongs to nobody or to somebody else. If you need a GTIN of your own, register with GS1 US or your national GS1 organisation. If you need a barcode for internal use only, use Code 128 with your own numbering scheme.
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 and which get x3, producing wrong check digits for any barcode whose first digit is non-zero.