UPC EAN Information

How To Read A UPC-A

A UPC-A is used to decode a product UPC-A bar code into the data it contains - the GTIN-12 product code.

In this document I will go into some detail about how a UPC-A bar code works, what the black and white stripes mean.

UPC-A Barcode Reader

We are going to take a UPC-A barcode and be a human UPC-A barcode scanner and read the UPC-A barcode, traversing the system of black and white bars and decoding them into the valid UPC-A number. This will give a good understanding of how the bar code is constructed and how to take it to bits.

UPC-A bar code

Figure 1: The UPC-A Bar Code To Be Read and Decoded

Of course, we can see from the human readable component of the bar code that the product code is 055270839959, but we are going to read and interpret the light and dark bars. Before we get to the data as bars it is necessary to understand the basic structure or framework on which the bar code is built. There are guard bars each side of the data bars. They are shown in Figure 2 below.

UPC-A barcode - left and right guard bars

Figure 2: UPC-A Left and Right Guard Bars

The left and right guard bars are also know respectively as start and stop bars because they signify the begining and end of the bar code. They do not form part of the product code data that is encoded in the bar code but they provide a framework to contain that data.

As well as left and right guard bars, there is also a centre guard bar. Figure 3 below shows the centre guard bar.

UPC-A bar code - centre guard bar

Figure 3: UPC-A Centre Guard Bar

The centre guard bar looks like the start and stop bars, but it isn’t. The left and right guard bars each comprises three thin bars of dark, light and dark, whereas the centre guard is five thin bars of light, dark, light, dark and light. The centre guard shown in Figure 3 separates the product code data bars into two sections. The left hand data bars shown in Figure 4 below encode the product code data that comprises the first six characters of the 12 that go to make up the GTIN-12 product code.

UPC-A bar code - left data bars

Figure 4: UPC-A Left Data Bars Encoding First Six Product Code Characters

Similarly, the right data bars encode the data comprising the second six charaters of the GTIN-12. They are shown in Figure 5 below.

UPC-A bar code - right data bars

Figure 5: UPC-A Right Data Bars Encoding Final Six Product Code Characters

One of the reasons that the right and left data bars are contained in separate sections is because a different encoding scheme is used for the left and right data. Bar code scanners need to be able to read a bar code in any orientation. The differing coding schemes, explained below, ensure that the data is read correctly whether the bar code is scanned right way up when it can be read start-to-finish or upside down and read from finish-to-start.

How the Data Bars Are Constructed

In preparation for scanning the bar code, we need to understand some detail about the way a UPC-A bar code is constructed of unit-size modules. When a UPC-A bar code is printed on a product it can be any size within a certain minimum and maximum. This means that the bar code scanner cannot rely on the bars being a certain size to determine what the bar sizes mean in terms of the procuct code values they represent. So instead of being a certain width in standard units such as millimeters, a UPC-A bar code is measured in its own system of measurement known as a module. A UPC-A bar code from beginning of left start bar to end of stop bar is defined as 95 modules wide.

The left start guard bar consists of three one-module bars of dark/light/dark. The right stop guard bar is the same. The centre guard bar is five one-module bars of light/dark/light/dark/light. That leaves (95 - 3 - 3 - 5 = 84) modules for the two data sections. Each data section then is 42 modules wide.

Figure 6 below shows the bar code as two sections for the data bars, with the left half divided into 6 characters, and the right half divided into 6 characters.

UPC-A bar code - left and right data sections of six characters each

Figure 6: UPC-A Six Product Code Characters In The Left Data Section and Six In The Right

Each character contains two light bars and two dark bars, but the combined width of the four bars always equals seven module widths. In Figure 7 below you see each characater divided into seven single module segments. Some of the bars - the ones wider than a single module - are effectivelly split by these single module widths.

UPC-A bar code - each character divides into seven modules

Figure 7: UPC-Each Character Divided Into Single Module Segments

Notice that each character in the left data section begins with a light coloured bar and ends with a dark bar, while in the right data section it’s the opposite way around - each character starts with a dark bar and ends with a light one.

In terms of decoding the meaning of the bars, each module width is equal to one binary digit. Each character is seven modules wide, so each character is represented by seven binary digits. I say “represented by” specifically. Each string of seven binary digits does not equate to its normal binary value, but is simply a code value - to get from binary digits to character value, we look up the binary in a table which then gives the character value for that binary value.

It’ll all become clear as we read the bars for each character and do the look-up. Table 1 gives the look-up table for the left half data.

UPC-A Decoding Characters 1 to 6
Binary Code GTIN Character
0001011 9
0001101 0
0010011 2
0011001 1
0100011 4
0101111 6
0110001 5
0110111 8
0111011 7
0111101 3

Table 1: Decoding left-hand six characters of a GTIN-12

Reading the Left Data Section

Take the seven modules from the first charater in the left data section. Figure 8 below shows the bars of the first character magnified in order to clearly see the colour of each module.

UPC-A bar code - first character bars magnified

Figure 8: UPC-A The Bars of the First Character Magnified

Looking at the colour of each module in turn, they are light, light, light, dark, dark, light, dark. Converting to binary, where light is zero and dark is one, this gives 0001101. Looking up that value in Table 1 above gives a GTIN character of 0.

UPC-A bar code - the bars of characters 2 to 6 magnified

Figure 9: UPC-A The Bars of Characters 2 to 6 Magnified

Repeating that process for the remaining five characters of the six taken from the left data section and shown in Figure 9 above is as follows:

Character 2 - light/dark/dark/light/light/light/dark = 0110001 = 5

Character 3 - light/dark/dark/light/light/light/dark = 0110001 = 5

Character 4 - light/light/dark/light/light/dark/dark = 0010011 = 2

Character 5 - light/dark/dark/dark/light/dark/dark = 0111011 = 7

Character 6 - light/light/light/dark/dark/light/dark = 0001101 = 0

The first six characters of the GTIN-12 are 055270. Because we are humans and only pretending to be a bar code reader we can cheat by checking what we have so far with the human-readable form of the number from Figure 1 at the top of the page. We see there that the first six characters of the code are 055270, which is the same as we just found by being a bar code reader and interpreting the data bars.

Reading the Right Data Section

Reading the second six characters is the same as reading the first six, except that a different table is used to translate from binary code to data. Table 2 below shows the decoding for the second six characters of the UPC-A bars.

UPC-A Decoding Characters 7 to 12
1000010 3
1000100 7
1001000 8
1001110 5
1010000 6
1011100 4
1100110 1
1101100 2
1110010 0
1110100 9

Table 2: Decoding right-hand six characters of a GTIN-12

Below in Figure 10 are the second set of data bars extracted from the complete bar code.

UPC-A bar code - the bars of characters 7 to 12 magnified

Figure 10: UPC-A The Bars of Characters 7 to 12 Magnified

Repeating the process for the second six characters of the barcode that are in the right data section and shown in Figure 10 above is as follows:

Character 1 - dark/light/light/dark/light/light/light = 1001000 = 8

Character 2 - dark/light/light/light/light/dark/light = 1000010 = 3

Character 3 - dark/dark/dark/light/dark/light/light = 1110100 = 9

Character 4 - dark/dark/dark/light/dark/light/light = 1110100 = 9

Character 5 - dark/light/light/dark/dark/dark/light = 1001110 = 5

Character 6 - dark/dark/dark/light/dark/light/light = 1110100 = 9

The second six characters of the GTIN-12 are 839959. Checking those with the human-readable form of the number from Figure 1 at the top of the page, we see there that the second six characters of the code are 839959, which is the same as we just found by being a bar code reader and interpreting the data bars.

Now we can put the two halves together to complete the task. The left half was 055270. We concatenate that with the second half 839959 that we just decoded to get the decoded GTIN-12 product id 055270839959.