Barcode Ready
← Barcode Guides

How Do Barcodes Work? Bars, Modules and Scanners

A barcode works by encoding data as a pattern of dark bars and light spaces of different widths. A scanner shines light across the pattern, measures how long each bar and space lasts, and converts those widths back into digits or characters. The number it reads is then sent to a computer that looks up the product or record.

Bars, spaces and modules

Every 1D barcode is built from a small unit called a module, the width of the thinnest bar. All other bars and spaces are whole-number multiples of that module. In a UPC-A, each digit takes up exactly 7 modules, drawn as two bars and two spaces. The pattern for a 3 is different from the pattern for a 7, and the scanner recognizes each by the widths of its elements.

Because the data is in the relative widths, not in absolute size, a barcode can be printed larger or smaller and still decode, as long as the proportions stay the same. Stretching it in one direction breaks those proportions, which is why you should always scale a barcode evenly.

Guard patterns and check digits

Retail codes have special guard bars at the start, middle and end. They tell the scanner where the code begins, in which direction it is being read, and help it measure the module width. The scanner can then decode the digits between the guards.

The last digit is a check digit calculated from the others. After decoding, the scanner repeats the calculation. If it does not match, the read is rejected and the scanner tries again. This is why a damaged barcode usually beeps nothing rather than ringing up the wrong product.

The quiet zone

A barcode needs blank space on both sides, called the quiet zone. Without it, the scanner cannot tell where the barcode starts and ends. For UPC-A the quiet zone is at least 9 modules on each side. Putting text, borders or artwork inside that margin is a common reason barcodes fail. The UPC barcode generator adds the margin for you so you do not clip it when you place the image.

Laser scanners and camera scanners

Laser scanners sweep a beam across the barcode and measure the reflected light with a photodiode. Dark bars absorb light and white spaces reflect it, producing a waveform whose timing gives the widths. Laser scanners are fast and ideal for 1D codes, but they cannot read 2D codes.

Camera (imager) scanners capture a picture of the code and analyze it with software. This is how smartphones and modern handheld scanners work. Imagers read 1D and 2D codes, work from many angles and can read codes on screens, which laser scanners often cannot.

Decoding step by step

  1. The scanner illuminates the code and captures reflected light.
  2. It finds the quiet zones and guard bars to locate the code and its direction.
  3. It measures the width of each bar and space relative to the module size.
  4. It converts each group of widths into a digit or character using the symbology's table.
  5. It verifies the check digit.
  6. It sends the decoded text, like a keyboard would, to the application.

The barcode itself holds only an identifier. Prices, descriptions and stock levels live in a database. That is how a store can change a price without reprinting anything.

2D barcodes

2D codes such as QR codes and Data Matrix use a grid of square modules instead of bars. A QR code has three large square finder patterns in the corners, which let a camera detect orientation, and it adds error-correction data so it can be read even if part is damaged. The same ideas apply: modules, a quiet zone and a decoding step.

Why barcodes fail to scan

Quick checklist

Barcode Ready generates the barcode in your browser, so you can adjust size and download PNG or SVG without uploading the number.

Try it