How Barcodes Are Encoded

To understand how a barcode is encoded, it helps to separate two things: the number itself, which ends in a check digit, and the bars, which carry that number in a scanner-readable form. Both work the same way for EAN-13 and UPC-A.

The check digit

The last digit of every EAN-13 and UPC-A is calculated from the preceding digits. If a scanner misreads one bar, the sum won’t work out, so the scanner rejects the read instead of returning the wrong product. The check digit detects errors. It can’t correct them.

Using 0712345678911 as an example, where the final 1 is the check digit:

  1. Drop the check digit. Starting from the right, add every second digit: 1 + 8 + 6 + 4 + 2 + 7 = 28
  2. Multiply by three: 28 × 3 = 84
  3. Add the remaining digits: 0 + 1 + 3 + 5 + 7 + 9 = 25
  4. Add the results of steps 2 and 3: 84 + 25 = 109
  5. The check digit is whatever it takes to reach the next multiple of ten. 109 + 1 = 110, so the check digit is 1.

[Keep the existing check digit calculation image here.]

The same method works for a 12-digit UPC-A. Run it on 712345678911, the UPC-A version of the same number, and you get 1 again, because the leading zero adds nothing to the sum.

You don’t have to do this by hand. Our GTIN Validator checks any EAN, UPC or ITF-14 number in seconds.

How the bars encode the digits

EAN code

Each digit is drawn as two black bars and two white spaces. Their widths are what distinguish one digit from another. The scanner measures that pattern of widths, not the numerals printed underneath.

There are three encoding schemes, usually written as L, G and R:

  • EAN-13 uses R for the right-hand six digits, and a mixture of L and G for the left-hand six.
  • UPC-A uses L for the left-hand six digits and R for the right-hand six.

Because the left-hand half is encoded differently from the right-hand half, a scanner can tell which end it’s looking at. That’s why scanning a product upside down still works.

Why the 13th digit isn’t in the bars

An EAN-13 has 13 digits but only 12 digit patterns. The first digit isn’t drawn at all.

Instead, the pattern of L and G encoding across the left-hand six digits carries it. There are ten possible L/G patterns, one for each value the first digit can take, so the scanner reads which pattern was used and works out the first digit from it.

This is also why an EAN-13 and a UPC-A of the same number produce identical bars. When the first digit is zero, the pattern is all L, which is exactly what a UPC-A uses. The bars are the same drawing. Only the printed digits differ in position. More on EAN-13 vs UPC-A.


Buy retail barcodes. EAN-13 and UPC-A images are supplied with every number.