How Check Digits Work: GS1 Mod-10 Worked Examples

How is the last digit of a UPC or EAN barcode number calculated?

Short answer

The last digit of a UPC, EAN, GTIN-14 or SSCC is calculated from the others: weight the digits 3, 1, 3, 1 starting from the right, add them up, and take whatever brings the total to the next multiple of ten. It catches every single wrong digit and most swapped neighbors, but it can't tell you whether a number is assigned to you.

On this page
  1. The rule in three steps
  2. Worked example 1: a UPC-A (GTIN-12)
  3. Worked example 2: an EAN-13 (GTIN-13)
  4. Same math for GTIN-8, GTIN-14 and SSCC
  5. Why it catches most typing mistakes
  6. What it can't catch
  7. Next step

You type a UPC into a label template or a marketplace form, and it gets rejected as invalid even though you copied it carefully. A common reason is that the last digit doesn't agree with the others. That last digit is a check digit, and you can compute it by hand in about a minute.

This guide works through the math on a UPC-A and an EAN-13, then shows what kinds of mistakes it catches and which ones slip through.

The rule in three steps

GS1 uses one check digit method for every fixed-length numeric identifier that needs one. Section 7.9.1 of the GS1 General Specifications defines it, and GS1's manual calculation page shows the same steps:

  1. Take the number without its check digit. Starting with the rightmost digit, multiply the digits alternately by 3 and 1, so the rightmost digit gets 3, the next one 1, and so on.
  2. Add up all the results.
  3. Subtract that sum from the nearest multiple of ten that is equal to or higher than it. What's left, 0 through 9, is the check digit.

People call this mod-10 because step 3 only depends on the sum's last digit. If the sum already ends in 0, the check digit is 0.

Starting from the right is what lets the same rule work for 8-, 12-, 13-, 14- and 18-digit numbers. The digit next to the check digit always gets a 3, however long the number is.

Worked example 1: a UPC-A (GTIN-12)

Take the 11 digits 61414112345. They start with 614141, the U.P.C. Company Prefix that GS1 uses for examples in its own documentation. With 11 digits, the first one lands on a weight of 3:

PositionDigitWeightResult
16× 318
21× 11
34× 312
41× 11
54× 312
61× 11
71× 33
82× 12
93× 39
104× 14
115× 315
Sum78

The next multiple of ten is 80, and 80 − 78 = 2. The full UPC-A is 614141123452.

There's a faster way to get the same sum. Add the digits in the odd positions (6 + 4 + 4 + 1 + 3 + 5 = 23) and multiply by 3 to get 69. Then add the even positions (1 + 1 + 1 + 2 + 4 = 9). 69 + 9 = 78.

Worked example 2: an EAN-13 (GTIN-13)

Now take the 12 digits 952012345678. The 952 prefix is reserved by GS1 for demonstrations and examples, so this number isn't assigned to a real product. Because there are 12 digits, the weights flip: the first digit gets 1 and the twelfth gets 3.

PositionDigitWeightResult
19× 19
25× 315
32× 12
40× 30
51× 11
62× 36
73× 13
84× 312
95× 15
106× 318
117× 17
128× 324
Sum102

The next multiple of ten is 110, and 110 − 102 = 8. The full EAN-13 is 9520123456788.

To check a complete number, run the same weighting over all its digits, with the check digit itself weighted 1 as the rightmost digit. A valid number totals a multiple of ten: for 614141123452, that's 78 + 2 = 80. GS1 notes that barcode readers usually run this check automatically.

Same math for GTIN-8, GTIN-14 and SSCC

The method doesn't change with the key. GS1 says it's identical for all fixed-length numeric GS1 keys that carry a check digit, and its check digit calculator page lists only two keys that have none: the Component/Part Identifier and the Global Individual Asset Identifier.

KeyTotal digitsDigits weightedWeight on the first digit
GTIN-8 (EAN-8)873
GTIN-12 (UPC-A)12113
GTIN-13 (EAN-13)13121
GTIN-1414133
SSCC18173

Because the weights are anchored on the right, leading zeros never change the answer. The UPC-A 614141123452 written as a GTIN-13 is 0614141123452, and as a GTIN-14 it's 00614141123452. All three end in 2. If you want the background on how these formats relate, see what a GTIN is.

An indicator digit is different, because it isn't zero. To number a case of that product, GS1 places an indicator such as 1 in front of the first 12 digits of the GTIN-13 (061414112345). The 13 digits 1061414112345 sum to 81, so the check digit becomes 9: 10614141123459. GS1's General Specifications list the same result for this example.

Two related checks work differently. Price and weight fields inside some variable-measure barcodes get an extra GS1 check of their own. Code 128 and GS1-128 symbols carry a separate symbol check character in the bars, which doesn't appear in the printed digits. The Code 128 guide covers that one.

Why it catches most typing mistakes

Every single wrong digit is caught. Changing one digit by some amount moves the sum by that amount or by three times it. For any change from 1 to 9, neither is a multiple of ten. Mistype the fifth digit of 614141123452 as a 7 and you get 614171123452, which totals 89 and fails.

Most swapped neighbors are caught. Swapping two adjacent digits moves the sum by twice their difference. Swap the 3 and 4 in 614141123452 and you get 614141124352, which totals 82 and fails. A neighbor swap only goes unnoticed when the two digits differ by exactly 5.

What it can't catch

The check digit is a simple safety net, and it has holes:

  • Neighbors that differ by 5. Swap the leading 6 and 1 and you get 164141123452, which still totals 70 and passes. The same goes for any pair like 0 and 5, 2 and 7, 3 and 8, or 4 and 9. Out of the 90 possible swaps of two different neighboring digits, 10 slip through.
  • Swaps across one digit. Positions two apart share the same weight, so trading them never changes the sum. 416141123452, with the first and third digits swapped, passes too.
  • Two errors that cancel out. Two mistakes can shift the sum by a multiple of ten between them.
  • A valid number that's wrong for your product. A passing check digit only means the number is composed correctly. It doesn't show that the number was assigned to you, that it matches this item, or that no one else uses it. The UPC guide explains where valid numbers come from. This is general information, not legal advice about number licensing.

Next step

Run your number through the check digit calculator. It computes or validates the check digit for GTIN-8, GTIN-12, GTIN-13, GTIN-14 and 18-digit SSCCs, using the same math shown above. If you need to do this for a whole product list, a spreadsheet formula can apply the same 3-1 weighting to every row; the Excel and Google Sheets guide shows how.

Sources

  1. GS1: GS1 General Specifications Standard
  2. GS1: How to calculate a check digit manually
  3. GS1: Check digit calculator
  4. GS1 US: Check Digit Calculator

Written by Toma Tomov, editor of Plain Barcode.

How guides are researched and corrected: Editorial Policy. Spotted an error? Email [email protected].