Scanbot SDK has been acquired by Apryse! Learn more

Learn more
Skip to content

How do barcodes actually work?

We interact with barcodes every day, be it at the supermarket checkout or when opening a restaurant menu from a QR code. We know that their black bars or squares and the white spaces in between encode information that can be read by a laser scanner or camera. But what is happening under the hood? Let’s explore how barcode technology works in detail!

Kevin March 26, 2023 5 mins read
How do barcodes actually work

For this explanation, we’ll use the first barcode symbology ever to be scanned by a supermarket cashier, the Universal Product Code (UPC-A, to be exact). It uses an open standard, which means anyone can look up the technical details for free.

Let’s have a look at this example barcode:

How do barcodes actually work?

At first glance, it consists of black bars of different widths, with varying amounts of white space in between. But this is an optical illusion: There are actually 95 identical columns that can be either black (“1”) or white (“0”). Wider segments of the barcode are simply made up of multiple columns of the same color right next to each other.

Because the columns stand for ones and zeroes, barcode information is binary data – like all other digital information, no matter how complex. 

Now, we will try to read this. Starting from the left, let’s examine the first part of the barcode, which is slightly taller than the part in the middle. It represents the following binary data:

How do barcodes actually work?

By itself, this doesn’t tell us much. To make sense of these ones and zeros, we need to check the UPC standard. It tells us that “101” is used as a start and end code. Barcode scanners look for this pattern to determine where they should start reading the information.

1010100011

After that, each digit (0 to 9) is represented by seven columns. UPC-A doesn’t encode letters. So let’s take a look at what follows after the start code:

1010100011

By looking up in the barcode standard which digit this sequence of ones and zeros represents, we find out that this is a 4. We’ve identified the first digit of our code!

If we continue like this, we will eventually arrive at the middle section of the barcode, in which the bars are once again slightly longer than the rest. This sequence (01010 in binary) tells the barcode scanner that the second half of the barcode is coming up. 

This is important because the right side uses different sequences of ones and zeros to represent digits than the left side. The number of ones in a sequence is always even on the right side, whereas it is uneven on the left side. This way, the barcode scanner can detect if it is scanning the code upside down.

There’s another built-in mechanism that helps barcode scanners read the data correctly.

How do barcodes actually work?

In the UPC-A barcode example above, you can see that there is some white space above the 4 on the very left and the 8 on the very right. This “quiet zone” is also part of the barcode. It uses 9 white bars in a row (000000000) to better differentiate the main part of the barcode from its surroundings. 

Barcode quiet zones are an essential component of most barcode symbologies and should not be covered up, as this can lead to inaccurate scanning results.

In case you were wondering, the height of the barcode doesn’t really matter. Laser scanners project a thin horizontal beam of light onto the barcode to check which areas reflect the light and which don’t. Smartphones, which increasingly replace them, can do something similar with their camera sensors. 

While it’s always good to have a barcode tall enough to comfortably point a scanner or smartphone at, you can theoretically make it as high as you want. No matter if you scan the barcode example above or this comically enlarged one, the results will be the same:

How do barcodes actually work?

What about 2D barcodes?

The UPC symbology has since been succeeded by linear barcode standards with higher data density and more complex encoding mechanisms. Even more advanced are 2D barcodes like QR Code, Data Matrix, and Aztec. Explaining how they work in detail is a job for another article, but let’s have a quick intro.

For this, we’ll extract the binary data from a QR Code. We’ll do that by counting the black and white squares, which replace the lines used in 1D barcodes.

How do barcodes actually work?

We ignore the three big squares in the corners, as these constitute the finder pattern cameras use to locate the barcode. Instead, we start with the first small square in the bottom right corner, which is white and therefore a zero, and work our way up in a “Z” pattern. So one to left, then one diagonally up and right, then left again, and so on. When you hit the edge, you turn around, shift two to the left, and go back down.

How do barcodes actually work?
01001011011001011000101100…

If you make it all the way to the left, you’ve successfully “read” the barcode! 2D barcodes like this are full of additional data that give them a very high fault tolerance. Identifying what’s what is definitely possible, but time-consuming, so it’s best to let a machine handle the actual decoding.

Now that you know how barcodes work, are you interested in what types of barcodes there are? Or would you like to broaden your barcode-related vocabulary? Maybe you need to generate your own barcodes? In any case, we’ve got you covered.

We at Scanbot SDK develop data capture technology to make life easier for our clients around the world. If you’re interested in a high-end Barcode Scanner SDK, don’t hesitate to shoot us a message! We’d love to hear from you.

Related blog posts

Experience our demo apps

Barcode Icon Art

Barcode Scanner SDK

Scan 1D and 2D barcodes reliably in under 0.04s. Try features like Batch Scanning, Scan & Count, and our AR Overlays.

Launch Web Demo

Scan the code to launch the web demo on your phone.

Web QR Code

Also available to download from:

Document Icon Art

Document Scanner SDK

Scan documents quickly and accurately with our free demo app. Create crisp digital scans in seconds.

Launch Web Demo

Scan the code to launch the web demo on your phone.

Black and white QR code. Scan this code for quick access to information.

Also available to download from:

Data_capture Icon Art

Data Capture Modules

Try fast, accurate data capture with our demo app. Extract data from any document instantly – 100% secure.

Launch Web Demo

Scan the code to launch the web demo on your phone.

Black and white QR code. Scan this quick response code with your smartphone.

Also available to download from: