Skip to content
OEWER Tools
How It Works

How a Barcode Scanner Reads the Bars on a Product

5 min readBy OEWER Team

A barcode scanner does not read numbers. It measures how much light bounces back from bars and gaps, then turns the widths into digits. Here is the whole chain, step by step.

In this article
  1. Light in, light out
  2. Turning widths into digits
  3. The check digit catches mistakes
  4. Other kinds of scanner
  5. From bars to a price
  6. Why a scan sometimes fails
  7. Sources

A barcode scanner reads a pattern of light and dark, not the digits printed underneath. Dark bars send back little light and pale gaps send back a lot, so a sensor sees a stream of bright and dim moments. Electronics measure how long each one lasts, and the widths are translated into the digits of a product code. This article follows that chain from the red beam to the checkout screen.

Light in, light out

The common handheld or counter-top laser scanner contains a laser diode. According to the scanner maker Scanbot, the diode usually emits red light at a wavelength of about 650 nanometres. A mirror then sweeps the beam back and forth across the code so that it draws a thin line over the bars.

The surface of the label does the encoding work. In the words of the same source, black lines absorb more light and reflect less than white ones. A light sensor inside the scanner, called a photodiode, turns the amount of returning light into an electrical signal. Bright gaps produce a high signal and dark bars produce a low one.

Wikipedia's article on barcode readers adds detail on the optics. In a laser scanner the beam often lands on a rotating wheel of mirror facets, which sweeps the line at roughly 200 to 1,200 times a second in most scanners. The reflected light travels back through the same mirror system and an optical filter before it reaches the sensor, which helps it ignore room lighting.

Turning widths into digits

The electronics do not care how bright a bar is, only how wide it is. The scanner times each dark and light stretch and compares it with the others. A bar twice as wide as the narrowest one takes twice as long to cross. The result is a list of widths, which software compares with the rules of the barcode type.

The most familiar type on shop goods is the UPC-A. Wikipedia's article on the Universal Product Code explains that it holds 12 digits. The first identifies a number system, the middle ten identify the maker and product, and the last is a check digit. Each digit is drawn with two bars and two gaps that together span seven equal units, called modules. A full symbol is 95 modules wide.

  • Start and end guards: a thin bar, gap, bar pattern that marks the edges and tells the scanner the timing
  • Middle guard: a five-module pattern that splits the code into a left half and a right half
  • Digit patterns: seven modules each, made of two bars and two gaps
  • Quiet zone: blank space of at least nine modules on each side

The left half and right half use different patterns for the same digit. Because of this, the scanner can tell whether it swept the code left to right or upside down and can simply reverse the data.

The check digit catches mistakes

A smudge or a tear can make a bar look wider or narrower than it is. To catch such errors, the last digit is calculated from the other eleven. Digits in odd positions are multiplied by three, those in even positions are added as they are, and the check digit is chosen so that the total is a multiple of ten. Wikipedia works through an example in which the first eleven digits are 03600029145; the sum is 58, so the check digit is 2.

If the scanner's own calculation does not match the printed check digit, it rejects the read and tries again, which is why a scan that fails gives no half-correct answer. The same source says this method detects every single-digit error and about 89 percent of swapped neighbouring digits, so it is a strong safeguard but not a perfect one.

Other kinds of scanner

Laser scanners are not the only design. A pen-type reader has a light source and a photodiode at its tip, and the user drags it across the code. A CCD reader has a row of hundreds of tiny light sensors, each measuring the light in front of it, so it reads the whole line at once without moving parts. Camera-based readers capture a full two-dimensional image and use image processing to find and decode the code, which lets them handle several codes in one picture.

Scanbot notes that laser scanners have a low error rate and can read at a distance, but they read only one-dimensional codes, cannot read inverted codes and cannot read several codes at once. Camera-based readers, including the one in a phone, are the usual choice for two-dimensional codes such as QR codes.

From bars to a price

Once the digits are decoded, the scanner sends them to the till as plain data. The code itself does not contain a price. It only identifies the product, and the shop's computer looks up the current price, which is why prices can change without any new labels.

The first product scanned at a checkout this way, according to Wikipedia, was a ten-pack of Wrigley's Juicy Fruit gum at a Marsh supermarket in Troy, Ohio, on 26 June 1974. The register rang up 67 cents.

Why a scan sometimes fails

Everything above depends on clean contrast and clear widths. Patent literature on scanners describes how mirror-like glare can overwhelm the signal, and sources agree that damaged, faded or low-contrast labels are harder to read. A crease through the code, a glossy wrapper or a very worn label can each blur the widths enough that the check digit fails. Holding the product at a slightly different angle changes how the light bounces and often fixes it.

This article is general information about how scanners work. Exact wavelengths, scan rates and features differ between models, so the manual for a particular scanner is the best guide for that device.

Sources

This article was written with AI assistance. How we research and check our articles.

Share

Email

Keep reading