How do Barcodes work?
How it works: 15-second answer
Barcodes encode data as binary (0s and 1s) using black-and-white lines of varying thickness. A scanner reads these lines and converts them into a 95-digit sequence. The sequence starts and ends with "101" and includes a middle "01010" divider. The remaining digits are grouped into segments: the left side identifies the manufacturer, and the right side identifies the product.
How do Barcodes work?
Dropping some barcode facts first as an appetizer for you.
Over 6 billion barcodes are scanned every day globally.
91% of the people in the UK have scanned a barcode at least once in their lifetime.
In the U.S., about 89 million smartphone users scanned QR codes.
So naturally, I was super curious to know how it works. So here we go! Now I know how and so do you…
Step 1: Take a picture of the barcode you see at a store
Figure 1: Chicken soup’s bar code.
You will see black and white vertical lines of varying thickness as seen in Figure 1. Each white/black line can be x, 2x, 3x, or 4x thick.
And you’ll also find a set of numbers at the bottom, which we will return to later.
Step 2: Take a horizontal slice of the bar code and inspect the black-and-white gaps
Figure 2: Small horizontal slice of the bar code used in Figure 1.
Slice the bar code in Figure 1 horizontally and take the strip. You now have a series of black-and-white squares aligned linearly in a row.
Note: We can analyze the bar code further without slicing it horizontally. But it’s easier to follow the explanation seeing it as squares instead of long vertical rectangles.
Step 3: Convert the white and black gaps into 0s and 1s respectively. The longer the width, the more the 0s and 1s.
Figure 3: Barcode converted into a continuous series of 0s and 1s based on their thickness. The longer the black blocks, the more the 1s are based on their thickness. And likewise for the 0s.
Starting from left to right, convert the black and white squares to 1s and 0s respectively. The result is a series of 95 digits with just 0s and 1s as seen in Figure 3.
Step 4: Arrange the 0s and 1s into groups
We now have a 95-digit series composed of just 0s and 1s.
Starting from left to right, arrange the numbers into groups as follows.
Figure 4: Starting from the left, group the 95-digit number series from Figure 3.
Left-hand guard pattern: The first three digits in the sequence are always 101 - denoting the start of the barcode.
Left side digits: The next 42 digits are split into 6 groups of 7 digits each as seen in Figure 4. We will see what each of these groups represents in the next section
Center guard pattern: The next 5 digits are always 01010, which denotes the separation between the right and left side digits.
Right side digits: The next 42 digits are split into 6 groups of 7 digits each as seen in Figure 4.
Right-hand guard pattern: The last 3 digits in the sequence are also 101 - denoting the end of the barcode.
Step 5: Find the product code number using the left and right side digits
Take the 42 digits that we split into 6 groups on both the right and left sides of the barcode. Each of these 7-digit groups represents a number between 0-9. Their respective numbers are shown in Figure 5.
Mapping each of the left-side 7-digit groups from Figure 4 gives us the number 51000, which is the company code.
Similarly, the right side digits translate to 01251, which is the product code.
Figure 5: Each of the 7-digit left and right side digits represents a number between 0-9.
Thus, we can find out who the manufacturer is and what the product is from this barcode. Every item in a grocery store has a unique product code.
So, this is how each product and its manufacturers are uniquely identified.
Source: Code by Charles Petzold.