How do barcodes work?

The ubiquitous shopping label tells more of a story than you might think. Jake Port explains.

Marcus Lindstrom/Getty Images

These days you likely never give a second thought to the black and white lines and numbers on the labels of virtually all the goods we ever buy.

We are of course speaking about the unassuming barcode, a piece of modern numerical witchcraft that allows a computer to tell the difference between a lemon and a lime.

So let's break it down to understand exactly what everything means and why the barcode is a foundation of modern shopping.

The barcode is read using a laser that scans along the length of the sequence, reflecting more light where the label is white and less where it is black. This is where the computer starts to decipher the mess.

Since computers only understanding the world as 0s or 1s the white sections are read as 0s and the black sections are 1s.

Now things get a little more complicated. So to keep it as simple as possible we will follow the laser as it goes along the barcode, starting on the left and finishing on the right.

Cosmos Magazine

The first thing the laser will hit is what is known as the “left guard”. Think of it as the first checkpoint, the starting line, of the barcode.

This section is broken into three smaller bars, each read as a 1 or 0. This tells the reader that this is the start of the barcode and that it can keep reading along.

Following the left guard comes another five numbers that are further broken down into seven smaller bars each.

These are read in the same way as everything else – black is 1 and white is 0 – and represent the manufacturer's code. Each company has its own unique five numbers – Campbell’s soup, for instance, use 51000.

Each number from 0 to 9 is represented by its own unique combination of white and black bars. For instance, 0110001 represents 5 and 1100110 represents 1. While this may sound confusing it’s just so that the computer can understand the number it’s reading. The amazing part of this system is that the codes on the left side start with 1 and the right side codes start with a 0.

The code for the left is also the opposite of the right, so that a 0 on the left is a 1 on the right. Why is this amazing? Well, it allows the computer to know which way it's reading, and therefore if the barcode is upside down or the right way up, allowing it to be processed correctly.

This means that a user doesn’t have to have the barcode the right way up, and prevents it being misread so that someone buying a calculator doesn’t get charged for a laptop.

Next comes another checkpoint called the “centre guard” that marks the middle point of the reading frame. It's represented by two black lines with a white line in the middle. Once the laser has passed this point it starts reading the code for the next five digits, computing the numbers in exactly the same way as before, but with codes mirroring the left side.

For instance, a 5 is coded as 0110001 on the left side but as 1001110 on the right. These five numbers are the product code, with each set of five indicating a unique item.

This allows the scanner to tell if the item being scanned is a chair, a magazine or a packet of medication.

Once the five numbers have been read comes one last number known as the "modulo check character".

This is the last chance the reader has to make sure everything is as it should be. The number is calculated using a mathematical equation (see below) so if the number does not match the rest of the sequence, it is not processed and comes up as an error.

Lastly comes the “right guard” which has the same three numbers as the left guard and signals the final checkpoint of the barcode.

(Total of odd positions) X 3 + (Total of even side) – nearest number divisible by 10.


(0+1+0+0+2+1) X 3 = 12

(5+0+0+1+5) = 11

11+12 = 23

23 – 30 (the nearest value divisible by 10) = 7 which we see on the barcode above at the end.

The entire barcode has now been read, identifying the scanned item to the computer as a particular product, displaying its price and notifying the company that it has been sold. All of this happens in a fraction of a second – by the time you hear the beep it’s already done.

There is, however, another number at the very start of the barcode that is not read. It sits outside of the lines and identifies the type of barcode it is using a 0, 2, 3 or 5. A 0 denotes a normal item such as a pen, a 2 is for a weighed item such as fruit, 3 is for pharmacy and a 5 is for a coupon.

So the next time you go shopping and pick up that piece of clothing or whatever takes your fancy, maybe look twice at the barcode – you might see a little more going on than you did before.

Explore #barcode
Contrib jakeport.jpg?ixlib=rails 2.1
Jake Port contributes to the Cosmos explainer series.
Latest Stories
MoreMore Articles