Albert Assaad
Oct 6 · 4 min read

What’s inside the Barcode?

Barcodes are everywhere, we encounter them on nearly every product that we see, have you ever wondered how it works?

There are many types of Barcodes Code 39, Code 128, UPC, EAN… all of them works the same manner but has different design and decompiled by the barcode scanners in different ways.

In this article, we’re gonna take an example of the EAN13 barcode.

EAN stands for ( European Article Number) and 13 cause it contains 13 numbers and it has the following format:

The above barcode when scanned it will generate the same text written below it “9780201379624”. The scanner emits red light, the sensor in it detects the reflected light and generates an analog signal with the varying voltage that represents the intensity (or lack of intensity) of the reflection. A converter changes the analog signal to a digital signal which is sent to the decoder.

How does the decoder work? it has an algorithm to transform those digital signals to an ASCII text that is sent to the computer:

What are the parts of the EAN13 barcodes:

1- First and Last 3 Lines:

As we can see in the above picture the first and the last 3 lines are 1 Black 1 White(which is the empty column) and 1 Black that means the black line represents a 1 in binary and the white line represents a 0. From those lines, the machine will determine the thickness of 1 and the thickness of the 0
Line (We will see an example shortly).The first 3 bits are known as Left-Hand Guard Pattern and the Last 3 bits are known as the Right-Hand Guard Pattern.

2- The Middle lines:

it’s called Center Guard Pattern which is composed of 5 bits 01010. This is a fixed pattern that always presents in the barcode. If the Scanner doesn’t find it, it will not acknowledge the EAN13 barcode.

3- The check Digit number:

it’s the last number on an EAN13 barcode, this number will permit checking if the barcode is eligible or not, it’s another form of error checking let’s see how it’s calculated:

Our barcode is composed of those numbers: 9780201379624 to examine how it works let's take the first 12 digits of the barcode 978020137962 we start by the last one and skip 1 number and add the next number : (2+9+3+0+0+7) multiply by 3 = 63 then we add the rest from the beginning and skip one number 63 +(9+8+2+1+7+6) =96, Now we substruct it from the next number from the result multiple of 10 which it 100–96 =4 and that’s it :)

How the numbers are drawn in the barcode?

As we explained above the barcode is divided by 101 LEFT HAND 01010 RIGHT HAND 101. The LEFT-HAND bits will start with a 0 and ends with a 1 contrary the RIGHT-HAND with start with a 1 and ends with a 0. Each number in the barcode has 2 encodings on the LEFT-HAND we will present them as Odd/Even and 1 encoding in the RIGHT-HAND see the following table:

On the LEFT-HAND the ODD or EVEN parity are chosen depending on the first number follow the below table:

So in our example the barcode is 9780201379624 first number is 9 so as per the above table the barcode must be encoded(Odd/Even/Even/Odd/Even/Odd) 7 as Odd 8 as Even 0 as Even 2 as Odd 0 as Even and 1 as Odd and the rest numbers(379624) will be encoded as the RIGHT-HAND encoding in the first table, the result will be 101 0111011 0001001 0100111 0010011 0100111 0011001 01010 1000010 1000100 1110100 1010000 1101100 1011100 101.

See below final barcode with the encoding for each number, notice that the fist number 9 will not be drawn in the barcode it will start with 101 and the decoding for the second number which is 7, when scanned the Handheld scanner will determine the first number from the pattern of the Left-Hand:

The numbers in the barcode are divided into 4 areas number system, manufacturer code, product code, and the check digit.

In our example, the number system consists the first 3 digits (sometimes it consists the first 2 digits) which is 978 means: International Standard Book Numbering (ISBN) below is the table of valid number system code:

The manufacturer code is 0201 each manufacturer has a unique code to identify his products.The product code is 37962 and the last is 4 the check digit which is determined by doing the calculation listed above.

That’s all about the EAN13 barcode, for any further clarification please write it in the comments.

The Startup

Medium's largest active publication, followed by +525K people. Follow to join our community.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade