Skip to content
ScanHatch

Barcodes

What Is a Barcode and How Does It Work?

By ScanHatch · Published · 4 min read

A barcode is a way of writing a number or short piece of text so that a machine can read it quickly and without mistakes. The classic stripes are a linear or 1D barcode; square codes such as QR codes are 2D barcodes. This guide covers how the stripes carry data and how scanners read them.

A short history

The idea was patented in the United States in 1952 by Norman Woodland and Bernard Silver, as a bullseye of rings. It became practical once lasers and computers were cheap enough: the grocery industry adopted the Universal Product Code (UPC) in 1973, and the first retail scan of a UPC was a pack of chewing gum in an Ohio supermarket in June 1974. Europe's EAN system followed a few years later.

How bars and spaces carry data

A linear barcode is read as a sequence of dark bars and light spaces of different widths. The narrowest possible element is one module, and its printed width is called the X-dimension, for example 0.33 mm for a standard-size EAN-13.

Each format, or symbology, has its own rules for turning characters into patterns. In EAN-13, each digit is 7 modules wide, made of two bars and two spaces. In Code 39, each character is nine elements, three of them wide. The scanner measures the relative widths and looks the patterns up.

Around the data, every linear barcode has:

  • Start and stop patterns (or guard bars in EAN/UPC), which tell the scanner where the code begins and ends and which way round it is.
  • Quiet zones: blank margins at both ends that the scanner uses to find the start. Text or graphics printed into the quiet zone is one of the most common reasons barcodes fail.
  • Usually a check digit or check character, calculated from the data, so the scanner can detect a misread. See barcode check digits explained.
  • Often a human-readable line of text underneath, so people can type the number if the scan fails.

How scanners read barcodes

Types of barcode scanner
ScannerHow it worksReads
Laser scannerSweeps a red laser line across the code and measures reflected lightLinear barcodes only
Linear imagerCaptures a single line of the image with a light sensorLinear barcodes only
Area imager (camera)Takes a picture and decodes it in software, like a phoneLinear and 2D codes, in any orientation

Laser and linear scanners need to cross all the bars in one sweep, which is why the barcode must be roughly lined up with the beam, and why shorter bars are harder to hit. Camera-based scanners find the code anywhere in the image; phones, and ScanHatch's barcode scanner, work this way.

Because laser scanners use red light, red bars reflect it like the background and become invisible. Barcodes should use dark bars (black, dark blue or dark green) on a light background.

What a barcode number means

A barcode usually contains only an identifier. A product barcode holds a GTIN (Global Trade Item Number), not the product's name or price. The till looks the number up in the shop's database. The same barcode can have a different price in different shops, and scanning a barcode with a phone app only tells you more if the app has its own product database.

Common linear formats

Widely used linear barcodes
FormatDataTypical use
EAN-13 and UPC-A13 or 12 digitsRetail products
EAN-8 and UPC-E8 digitsSmall retail packs
Code 128Any standard textShipping labels, inventory, asset tags
Code 39Capitals, digits, a few symbolsIndustrial and legacy systems
ITF-1414 digitsShipping cartons
CodabarDigits and a few symbolsLibraries and older systems

2D barcodes

2D barcodes store data both across and down. Stacked codes such as PDF417 are rows of linear barcode piled on top of each other. Matrix codes such as QR codes, Data Matrix and Aztec are grids of square modules. They hold far more data, include strong error correction, and need camera-based scanners. QR code vs barcode compares the two families.

Making and checking barcodes

The Barcode Generator creates all of these formats as print-ready vector files, calculating check digits where the format has them. To check a number without generating anything, use the Barcode Validator. Generating a barcode only draws the symbol: numbers for retail products still have to come from GS1.

Frequently asked questions

Does a barcode contain the price?

No. Product barcodes contain an identifier. The price is looked up in the shop's own system.

Why do some barcodes have numbers under them?

So a person can type the number in if the barcode won't scan.

Can any scanner read any barcode?

No. Laser scanners read only linear barcodes, and scanners are often configured to accept only certain formats.

  • Barcodes

    QR Code vs Barcode: Which Should You Use?

    How QR codes and traditional barcodes differ in capacity, error correction and scanning, and which to use for products, shipping, inventory and marketing.

    · 3 min read

  • Barcodes

    EAN-13 vs UPC-A: What's the Difference?

    How EAN-13 and UPC-A relate, why a UPC-A is an EAN-13 starting with 0, where each is used, how to convert them, and which to put on your product.

    · 3 min read