How Barcodes Work: How Black Bars and White Spaces Lead to Product Information

In this blog post, we’ll explore how a barcode scanner reads the differences in brightness and width of black bars and white spaces to decode data, and how the product identification number obtained in this way is linked to the product name and price information at the checkout counter.

 

When a barcode is scanned, where do the product name and price come from?

When a barcode is scanned at the checkout, the product name and price appear on the screen. While it may seem as though all this information is contained within those tiny stripes, what’s actually encoded in a typical retail barcode is a number that identifies the product. When the scanner decodes the pattern and transmits the number, the point-of-sale (POS) system at the checkout retrieves the product name and price associated with that number from the database and displays them.
To understand this process, you need to distinguish between a barcode and a product identification number. A barcode is a pattern that represents data in a machine-readable format, while a product identification number is the data that the pattern represents. The same number can be printed as human-readable digits or represented as a pattern of bars and spaces that a scanner can read.
The EAN-13 and UPC-A barcodes commonly seen in retail stores are used to represent the GTIN (Global Trade Item Number), an internationally recognized number for distinguishing products. The GTIN serves as the standard for identifying products and retrieving related information. Therefore, while reading the barcode pattern and retrieving product information are interconnected, they are distinct processes.
Understanding this difference helps explain why the price of the same product may vary when scanned at different stores. This is because, even if the product identification number is the same, the price registered in each store’s sales system may differ. When changing the selling price of a product, there is no need to reprint the barcode; simply modify the price information linked to that number. However, a different method applies to products sold by weight, where the barcode contains both price and weight information.

 

How does a scanner distinguish between black bars and white spaces?

Laser-based barcode scanners shine light onto the barcode and detect the intensity of the light that bounces back. Black bars reflect relatively little of the light emitted by the scanner, while white spaces reflect a lot. The light sensor converts this difference into an electrical signal.
As the laser beam travels across the barcode, the intensity of light received by the sensor varies depending on the arrangement of the bars and spaces. The duration of the signal also changes as it passes over narrow and wide sections. The scanner analyzes these changes to identify the boundaries between the bars and spaces, as well as the relative widths of each section.
Here, the white space between the bars is not simply an unprinted area left blank. It is an element that, together with the black bars, represents the data. If only the width of the black sections is read or the white sections are ignored, the entire pattern cannot be interpreted correctly. The blank margins reserved at both ends of the barcode are also necessary. This area, called the “quiet zone,” helps distinguish the barcode from surrounding text or patterns. If the spaces between the bars form the data pattern, the margins at both ends serve to frame that pattern, making it easier to recognize.
Scanners that use image sensors capture the barcode as an image and then analyze the differences in brightness and the pattern. Although the method of collecting information differs from that of laser scanners, they share the common principle of distinguishing between light and dark areas and decoding their arrangement according to set rules.
Barcodes do not necessarily have to be black and white. However, just because these two colors are clearly distinguishable to the human eye does not mean a scanner can read them well. There must be a sufficient difference in reflectance between the bars and the background under the light used by the scanner. Black bars on a white background are an ideal combination for ensuring this contrast, and factors such as precise width and sharp printing quality—in addition to color—also affect readability.

 

How do black-and-white patterns become numbers and digital data?

The intensity of light detected by a sensor can vary continuously. A signal that takes on continuous values within a certain range is called an analog signal. A digital system represents values in discrete steps. A scanner converts light into an electrical signal, processes it, and transforms it into a form that can distinguish and decode the pattern of bars and spaces.
When processing data, computers primarily use binary representation, which consists of 0s and 1s. While the decimal system used in everyday life represents numbers with ten digits from 0 to 9, the binary system uses only 0s and 1s. For example, the decimal number 139 is represented in binary as 10001011. This corresponds to 128 + 8 + 2 + 1, so although the notation differs, the value is the same.
However, a product barcode is not simply a pattern created by converting the entire product number into binary and drawing it as is. Each type of barcode has its own “encoding rules” for representing data as a pattern. Scanners interpret the widths and arrangements of the bars and spaces, as well as patterns indicating the start and end, according to these rules to reconstruct numbers or characters.
For example, the bars and spaces in EAN-series barcodes consist of widths that are 1x, 2x, 3x, and 4x the base width. Numbers are represented by grouping bars and spaces of varying thicknesses according to specific rules. Therefore, the simple correspondence of “black equals 0 and white equals 1” is insufficient to fully explain the meaning of a barcode. In addition to distinguishing between light and dark areas, it is crucial to interpret their widths and arrangements according to specific rules.
There are also devices that verify whether the read values conform to these rules. The last digit of a 13-digit product number represented by EAN-13 is a “check digit” calculated from the preceding digits. Scanners can compare the result calculated from the scanned numbers with this value to filter out some reading errors. However, even if the check digit matches, this does not rule out all errors or guarantee that the number is correctly linked to the actual product.
Once the decoded number is transmitted to the sales system, the product information is retrieved. At the checkout counter, the process of the scanner reading the number from the pattern and the computer using that number to find the product name and price occurs in rapid succession.

 

Do all barcodes contain only product identification numbers?

While standard retail EAN and UPC barcodes primarily contain product identification numbers, this description does not apply to all barcodes. This is because the data contained in a barcode varies depending on the standard used and its purpose.
For example, products whose selling price varies based on weight may use a numbering system that includes price or weight information. In such cases, the barcode provides not only the number used to look up the product but also the data necessary to process the selling price or weight of that particular package. The specific structure varies depending on the applicable standard and the point-of-sale system.
The GS1-128 barcode, used in logistics and distribution management, can represent additional information—such as lot numbers or expiration dates—along with the product identification number. A lot number is a code used to group and identify products belonging to the same production batch. Since identifying a specific product and determining which production batch it belongs to are two separate tasks, information beyond the product identification number is required to manage production and distribution history.
Two-dimensional barcodes, such as QR codes and GS1 DataMatrix, arrange information both horizontally and vertically. They can generally store more data in a smaller area than one-dimensional barcodes, which represent data using bars and spaces in a single direction. GS1 DataMatrix can store a product identification number along with lot numbers, expiration dates, and other information.
However, the actual printing area required varies depending on the amount of data, the specifications, and the printing and scanning conditions.
Just because it’s a two-dimensional barcode doesn’t mean it automatically contains all the product information. The necessary data can be encoded directly within the code, or it can contain an identification number or a web address that links to information in an external system. Ultimately, the information provided by the barcode depends on what has been encoded within it and what information the linked system provides.
The black bars and white spaces you see at the checkout counter are markings designed to make the data machine-readable. A scanner decodes these markings, and the point-of-sale system links the retrieved number to the product information. While they may appear to the naked eye as simple stripes, behind the scenes, technology that detects differences in light, rules for representing data, and systems for managing product information all work together.

 

About the author

Cam Tien

I love things that are gentle and cute. I love dogs, cats, and flowers because they make me happy. I also enjoy eating and traveling to discover new things. Besides that, I like to lie back, take in the scenery, and relax to enjoy life.