UPC EAN Information

EAN-13 Bar Code

The EAN-13 bar code is used to encode a product GTIN-13 number into a machine readable form.

In this document I will describe in detail how the EAN-13 bar code works. I’ll do this by taking a real example of a GTIN-13 code. A product’s GTIN-13 is the item number that underlies the bar code that the product carries. The EAN-13 bar code is simply a machine-readable way to represent the underlying product number.

The product that I have chosen for the example is a 220ml bottle of my favourite Encona West Indian Original Hot Pepper Sauce.

The GTIN-13 for this product is 5012389000903. Count up the digits, you’ll find there are 13.

Here’s a photograph of the actual product bar code from the back of the bottle.

EAN bar code

There you can see the EAN-13 bar code. As well as the characteristic series of black and white stripes that the store checkout scanner can read, you can see a human readable version that is the GTIN-13 article number that I listed above.

We are going to take the GTIN and build the bar code from it, bit by bit. It’ll get very detailed, but it’s not too difficult.

Before we take the numbers and encode them into the bar code, we’ll look at the basic framework of a EAN-13 bar code to see where everything fits and get to grips with some basic principles of the EAN-13.

Like most things to do with computers, everything eventually comes down to zeros and ones. The EAN-13 is no exception. The black bars and the white spaces between the bars translate to a combination of zeros and ones. In what follows, instead of talking about black bars and white spaces, I shall just call them black bars and white bars.

You will notice that the black and white bars are of varying widths. There are four different widths for both black and white.

Principle 1: The thinnest bar is called the module or x-width.

The next thickest is twice the thickness of the first - two modules. The width of the third thickest is three modules, and the widest is four modules.

The whole EAN bar code is a set number of modules wide. That number turns out to be 95.

Principle 2: A thin black bar is a one (1) and a thin white bar is a zero (0).

EAN bar code

Those three groups of bars create the framework for the rest of the EAN-13 bar code. They are not part of the GTIN, but as far as the workings of the EAN-13 bar code system are concerned they are the fundamental structure of the bar code and provide the container for the GTIN number itself.

As part of the EAN-13 bar code, each of the bars of the framework have the values noted in Principle 2. The left and right parts are both a black bar, a white bar and a black bar, so both have binary values of 101. The centre bars, while they look the same as the outer bars, are in fact white, black, white, black and white, which is 01010. You need to be aware that there is a white bar to left and a white bar to the right of what you can see. All of the bars so far described are bars of the thinnest variety, so are one module wide. That is three modules on the left, five in the middle and three on the right, making a total of 11 modules.

That means of the total of 95 modules, there is room left for 84 modules – 42 in the first large space and 42 in the second. There are six GTIN-13 digits in the first space and six in the second. Each GTIN-13 digit needs 7 modules of space in which to encode it. 7 modules each for 12 digits uses up exactly the 84 modules of space. But wait! The GTIN-13 number comprises 13 digits, and we only have room for 12. The reason for this is that the first of the thirteen characters of the GTIN number is not encoded in the same way as the following twelve. It doesn’t actually appear as black and white bars - it’s encoded in a different way. We’ll see how that happens in a while and is also what makes the EAN-13 a close relation to the American system of UPC. First I will explain how the final 6 characters of the GTIN are encoded – they’re the easiest to understand and that will give us a good foundation on which to understand the slightly more complex encoding of the first 7 characters.

If you guessed that the final six characters are encoded into the space between the middle bars and the final bars, then you guessed correctly. Below is a table that shows the encoding regime for the final 6 characters.

EAN-13 Encoding For The Final 6 Characters
GTIN Character Binary Code
0 1110010
1 1100110
2 1101100
3 1000010
4 1011100
5 1001110
6 1010000
7 1000100
8 1001000
9 1110100

Table 1: Encoding the last six characters of a GTIN-13

Each binary digit (each 0 and 1) creates a one module width stripe in the EAN-13 bar code. Each 0 makes the thinnest white bar and each 1 makes the thinnest black bar. Two or more one module bars of the same colour right next to each other just create a thicker bar, of two or more modules wide.

I want you to notice the following important details about the encoding for the final 6 GTIN number characters.

  • Each binary code begins with a 1
  • Each binary code is 7 binary digits in length
  • The binary codes are arranged so that each code has exactly four groups of 1s and 0s – Black, White, Black, White of varying widths

So let’s take the final 6 digits of our EAN number and encode them using the table.

Our 6 digits are 000903

0 is 1110010
0 is 1110010
0 is 1110010
9 is 1110100
0 is 1110010
3 is 1000010

Join them all together one after the other and we get:

111001011100101110010111010011100101000010

When we turn our 1s into black blobs and our 0s into white blobs we get:

EAN bar code

Now if we show that again as proper bar code bars it looks as we might expect.

EAN bar code

When we fit that into the EAN-13 bar code framework, this is what it looks like.

EAN bar code

That’s the right-hand bit done. That wasn’t too difficult, was it? We’re nearly done!

Just the left part to do. But that is a bit more difficult. We need two different encoding schemes for the characters in the first part of the EAN-13 bar code. Lets look at those. We call them Scheme A and Scheme B.

EAN13 Encoding Characters 2 to 7
GTIN Character Binary Code - Scheme A Binary Code - Scheme B
0 0001101 0100111
1 0011001 0110011
2 0010011 0011011
3 0111101 0100001
4 0100011 0011101
5 0110001 0111001
6 0101111 0000101
7 0111011 0010001
8 0110111 0001001
9 0001011 0010111

Table 2: Encoding characters two to seven of a GTIN-13

If you compare the Scheme A binary codes with the codes from the previous table for the final six characters that we have just completed, you will notice that each 1 is now a 0 and each 0 is now a 1. Similarly, if you compare Scheme B binary codes with the codes from the previous table for the final six characters, you will notice that they are flipped, right to left.

Each remaining character in the GTIN number, apart from the first one, is encoded from one of the two schemes, A or B. Which scheme to use for which character is determined by a further table. It is the choice of which scheme is used for each of characters 2 to 7 that encodes the value of the first character of an EAN-13 bar code.

EAN-13 Encoding Schemes for Characters 2 to 7
Value of char 1 Scheme for char 2 Scheme for char 3 Scheme for char 4 Scheme for char 5 Scheme for char 6 Scheme for char 7
0 A A A A A A
1 A A B A B B
2 A A B B A B
3 A A B B B A
4 A B A A B B
5 A B B A A B
6 A B B B A A
7 A B A B A B
8 A B A B B A
9 A B B A B A

Table 3: Encoding schemes for characters two to seven of a GTIN-13

Now we have all of the information we need to be able to encode characters 1 to 7 of the GTIN. Our GTIN-13, remember, is:

5012389000903

We have already encoded the last six characters. The first seven characters are:

5012389

We need to look down the first column of Table 3 to find the first character, the 5, and look along that row to see how we encode the remaining six of the seven.

The row for GTINs that begin with a 5 tell us to encode characters 2 to 7 with schemes A, B, B, A, A and B respectively.

Referring back to Table 2, we marry up the second to seventh characters with the appropriate scheme to find the encodes.

Characters 2 to 7: 012389

Scheme to use: ABBAAB

0 (character 2) uses Scheme A so its binary code is 0001101.
1 (character 3) uses Scheme B so its binary code is 0110011.
2 (character 4) uses Scheme B so its binary code is 0011011.
3 (character 5) uses Scheme A so its binary code is 0111101.
8 (character 6) uses Scheme A so its binary code is 0110111.
9 (character 7) uses Scheme B so its binary code is 0010111.

Join the binary codes all together one after the other to make:

000110101100110011011011110101101110010111

Making the 0s white blobs and the 1s black blobs gives the pattern:

EAN bar code

That pattern as bar code bars looks like this:

EAN bar code

You will notice that this part of the EAN-13 bar code begins with a white bar. I am showing it against a tinted background in order for it to be seen. Normally a bar code is printed on a white or near-white background, enabling the white bars simply be the background.

Lets see these bars in the context of the whole bar code framework.

EAN bar code

Now there is just the human readable numbers to add to the bottom of the EAN-13 bar code and it’s all done.

EAN bar code

EAN-13 Bar Code Specifications

There are some specifications about sizes that you need to be aware of.

Standard dimensions are given for various EAN-13 bar code factors. There should be a quiet zone or light margin with nothing printed in it to the left and right of the EAN-13 bar code. This is so that the bar code scanner and the bar code software is able to determine where the EAN-13 bar code begins and ends. The recommended minimum sizes for the quiet zones, in dimensions of the modules that we have used throughout, are 11 modules for the left quiet zone and 7 modules for the right quiet zone.

The dimensions shown below are for a nominal size of EAN-13 bar code. This is referred to as the 100% magnification. The nominal module or x-width size is 0.33 millimetres. Instances of the EAN-13 bar code may be used down to 80% and up to 200% of the nominal size.

EAN bar code