Home › Check digit
EAN and UPC check digit: how to calculate it
The last number of a barcode is not decoration: it is there to catch mistakes. Here we calculate it step by step, with worked examples, and see which errors it detects and which it misses.
- Your data never leaves your browser
- PDF in real millimetres
- Automatic check digit
- Avery models for A4 and Letter
Pick a type and everything is set up for you (code, sheet size and design). You can change anything afterwards.
Order if there is no header: name, price, code, reference, old price, copies. With a header row (name, price, code, ref…) the columns are recognized automatically. A single column = codes only.
| # | Name | Price | Code | Ref. | Old price | Copies |
|---|
Current type: · Change label type
The file is saved on your computer and is not uploaded anywhere. Use it to reuse the same design another day or on another computer.
The logo is processed right here and is not uploaded anywhere. Use a simple image: fine details are lost on small labels.
Your product lists, prices and logos are never uploaded to any server. The PDF, PNG, SVG and ZIP are created on your own device. So you don't lose your work, a copy is kept only in this browser (you can delete it with “Clear all”).
What the check digit is and what it is for
The last digit of an EAN-13, an EAN-8, a UPC-A or an ITF-14 is called the check digit. It identifies nothing about the product: it is calculated from all the other digits and lets the checkout scanner verify, in a fraction of a second, that it has read the code correctly. If a number fails, the checkout rejects the read instead of charging for the wrong product.
For you, as someone generating codes, it means two things: that you can't make up the last digit (if it isn't the right one, the scanner will reject the code) and that, if you type the others, it can be calculated by itself. That is what GeneraEtiquetas does: if you type the first 11 digits of a UPC-A (or the first 12 of an EAN-13), it adds the last one.
The algorithm step by step (EAN-13)
All four formats use the same algorithm, called GS1 modulo 10. For an EAN-13 you start from the first 12 digits:
- Number the digits from right to left, starting with the last of those 12 (the one that will sit next to the check digit).
- Multiply by 3 the odd positions (1st, 3rd, 5th…) and by 1 the even positions (2nd, 4th, 6th…).
- Add up all the results.
- Work out what is missing to reach the next multiple of ten. If the sum already ends in 0, the check digit is 0.
Example with 590123412345:
| Position (from the right) | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Digit | 5 | 4 | 3 | 2 | 1 | 4 | 3 | 2 | 1 | 0 | 9 | 5 |
| Weight | 3 | 1 | 3 | 1 | 3 | 1 | 3 | 1 | 3 | 1 | 3 | 1 |
| Product | 15 | 4 | 9 | 2 | 3 | 4 | 9 | 2 | 3 | 0 | 27 | 5 |
The sum is 15 + 4 + 9 + 2 + 3 + 4 + 9 + 2 + 3 + 0 + 27 + 5 = 83. The next multiple of ten is 90, so 7 is missing. The full EAN-13 is 5901234123457.
The same algorithm in UPC-A, EAN-8 and ITF-14
With the other formats the procedure is identical: number from the right, starting with the last digit of the body (not counting the check digit), with weight 3 for the first one and alternating 3 and 1. Only the number of digits in the body changes:
| Format | Body | Sum | Check | Full code |
|---|---|---|---|---|
| UPC-A | 03600029145 (11) | 58 | 2 | 036000291452 |
| EAN-13 | 590123412345 (12) | 83 | 7 | 5901234123457 |
| EAN-8 | 9638507 (7) | 86 | 4 | 96385074 |
| ITF-14 | 1001234567890 (13) | 88 | 2 | 10012345678902 |
Notice that the algorithm always puts weight 3 on the digit nearest the check digit. That is why, if you convert a UPC-A to an EAN-13 by adding a zero in front (0036000291452), the check digit is still the same, 2: the zero adds nothing and the weights of the rest don't change.
How to check a code you already have
There is a quick way to validate a full code: multiply its digits, from left to right, by the weights 1, 3, 1, 3… (in an EAN-13; the last one, the check digit, ends up with weight 1) and add. If the result is a multiple of 10, the code is valid. With 5901234123457: 5×1 + 9×3 + 0×1 + 1×3 + 2×1 + 3×3 + 4×1 + 1×3 + 2×1 + 3×3 + 4×1 + 5×3 + 7×1 = 90. It is a multiple of 10, so the code is valid.
In a UPC-A or an EAN-8, which have an even number of digits, the weights from left to right start with 3 (3, 1, 3, 1…). The most reliable way not to slip up is always to count from the right.
How to calculate it in Excel
If you have a column of 12-digit codes stored as text in cell A1, this Excel formula returns the check digit of an EAN-13:
=MOD(10-MOD(SUMPRODUCT(--MID(A1,{1,2,3,4,5,6,7,8,9,10,11,12},1),{1,3,1,3,1,3,1,3,1,3,1,3}),10),10)
It multiplies the digits, from left to right, by 1, 3, 1, 3…, adds them and works out what is missing for the multiple of ten. (In some regional versions of Excel the argument separator is a semicolon instead of a comma.) For a complete code, you can paste the column into GeneraEtiquetas and let it validate and correct it.
Which errors it detects and which it doesn't
The check digit is very effective, but it is not infallible. It detects:
- Any single-digit error. If you change a 4 to a 7 in any position, the sum changes and the check digit no longer adds up. It is the most common typing mistake.
- Most swaps of two adjacent digits. For example,
12typed as21.
What it does not detect is the swap of two adjacent digits that differ by exactly 5 (0 and 5, 1 and 6, 2 and 7, 3 and 8, 4 and 9). The reason is mathematical: when they are swapped, the sum changes by 2 × (a − b), and if the difference is 5, that change is 10, which doesn't alter the check digit. A real example: 1234056789018 and 1234506789018 are two different valid EAN-13s with the same check digit, and they would be mixed up if someone swaps the 0 and the 5. By contrast, if in 1234126789016 the 1 and the 2 are swapped (giving 1234216789016), the check digit no longer adds up, because it would need to be an 8, and the error is detected.
It also doesn't detect errors that cancel each other out (two wrong digits that cancel the change in the sum), although they are rare. And, above all, the check digit doesn't guarantee that the code exists or that it is yours: a number with the right check digit may be unassigned or belong to another product. Only GS1 guarantees that.
Codes that don't use this digit
- Code 128 has its own check character (modulo 103), which the encoder adds and which isn't even printed in the human-readable text. You don't need to calculate it.
- Code 39 has no mandatory check digit (there is an optional variant, modulo 43).
- QR uses Reed-Solomon error correction, much more powerful: it can rebuild part of the drawing if it is damaged.
- ISBN-13 (books) uses exactly the same algorithm as EAN-13, because it is an EAN with a 978 or 979 prefix.
Common mistakes when calculating it (and how to avoid them)
- Excel deletes your leading zeros. A code like
036000291452becomes36000291452and is no longer valid. Format the column as Text before typing or pasting. - Counting the weights from the left in even-length formats. In EAN-8 and UPC-A, the first digit has weight 3, not 1. Always count from the right.
- Including the check digit in the sum when calculating. When calculating, only the body is used. The check digit is included only when validating.
- Mixing up 11, 12 and 13 digits. A UPC-A is typed with 11 digits plus the check digit; an EAN-13, with 12 plus the check digit. If you type 12 in a UPC-A, there is one digit too many.
How GeneraEtiquetas does it
Choose a numeric type (UPC-A, EAN-13, EAN-8 or ITF-14) in step 1 and type the code:
- If you type the body without the check digit, it calculates it and adds it, and tells you so.
- If you type the full code and the last digit doesn't add up, it tells you what it should be and offers to fix it with one click.
- In many-labels mode it flags every row with an error and you can fix them all at once.
- With the automatic series in numeric formats, it pads with zeros and adds the check digit to each code.
How we have checked that the calculation is correct is explained in How we verify measurements and codes.
Frequently asked questions
What happens if the check digit of my code is wrong?
The checkout scanner will reject the read (or, in some systems, give an error), because the last number doesn't match the previous ones. GeneraEtiquetas warns you before printing and tells you the correct digit.
Can I choose the check digit myself?
No. It is always calculated from the other digits; if you put another, the code won't be valid. All you can choose are the preceding digits, which in an official EAN are assigned by GS1.
Does the check digit guarantee that the code is unique?
No. It only checks that the number is well formed. A code with the right check digit may be unassigned or belong to another product. Worldwide uniqueness is guaranteed only by GS1.
Is it calculated the same in EAN-13 as in UPC-A?
Yes: it is the same algorithm (GS1 modulo 10). You number from the right, multiply by 3 and by 1 alternately, add up and work out what is missing for the multiple of ten. Only the length of the body changes (12 digits in EAN-13, 11 in UPC-A).
Why does my Excel give me a different code?
Most often Excel has removed the leading zeros (format the column as Text) or the weights are being counted from the wrong side. Paste the codes into GeneraEtiquetas and compare with the one it calculates.
More guides
Which barcode
Which to choose among EAN-13, UPC-A, Code 128, Code 39, ITF-14 and QR for your case: retail, inventory, cartons or links. Comparison with examples.
Minimum size
What size, blank margins and contrast a barcode needs to scan: module, quiet zones, printer resolution and real examples on label sheets.
Printer calibration
Step-by-step guide to stop labels from misaligning: 100% scale, test sheet, millimetre adjustment, driver settings and a troubleshooting table.
Price labels
Make and print price labels with a barcode: name, price, crossed-out sale price and Avery sheets. Free, and your data never leaves your browser.
Avery templates
Millimetre measurements for Avery 5160, L7160, 3474, L7651 and more. Generate a PDF with each label in its cell or define your own grid. Free.
Full generator
All barcode formats and labels in a single tool.
Most-used sheets: Avery 3474 · Avery L7162 · Avery 5162 / 8162 · Avery 3422 · Avery L7165 · Avery 5160 / 8160