How Barcodes Work: The Science Behind the Scan
Understand the technology behind barcodes — how data is encoded in bars and spaces, how scanners read them, and why different barcode formats exist.

A barcode is a machine-readable optical representation of data, consisting of parallel lines (1D barcodes) or a matrix of squares (2D barcodes) that encode numeric or alphanumeric information. Scanners decode barcodes by measuring reflected light patterns — a process that takes 10-50 milliseconds per scan. Since the first commercial barcode scan in 1974, barcodes have become the foundation of global commerce, with over 10 billion scanned daily at retail checkout alone, according to GS1. Here's how the technology actually works.
The Origin
In 1952, Norman Joseph Woodland and Bernard Silver patented a "Classifying Apparatus and Method," the first barcode concept. Woodland's inspiration came from Morse code: he extended dots and dashes downward into thin and thick lines drawn in beach sand. The idea was elegant, but the technology to print and scan barcodes reliably wouldn't exist for another two decades.
The first commercial barcode scan happened on June 26, 1974, when a pack of Wrigley's Juicy Fruit gum was scanned at a Marsh supermarket in Troy, Ohio. That pack of gum now sits in the Smithsonian Institution.
How 1D Barcode Encoding Works
A one-dimensional barcode encodes data in a single row of parallel bars and spaces. Each digit or character maps to a specific pattern of wide and narrow elements (or precise-width modules, depending on the format).
Bars, Spaces, and Modules
The fundamental unit is the module — the narrowest bar or space in the barcode. Everything else is measured in multiples of this unit. In UPC-A, each digit occupies exactly 7 modules arranged as 2 bars and 2 spaces of varying widths. In Code 39, each character uses 5 bars and 4 spaces, where 3 of the 9 elements are wide and the rest are narrow.
The specific mapping from data to bar patterns is called the symbology. Different symbologies make different trade-offs:
- Binary width encoding (Code 39, Codabar): Elements are either wide or narrow. Simple to print and scan, but lower density.
- Multi-width encoding (Code 128, UPC-A): Elements can be 1, 2, 3, or 4 modules wide. More precise printing required, but higher data density.
- Interleaved encoding (ITF-14): Digit pairs share the same space — one digit encoded in bars, the next in the spaces between them. Compact for numeric data.
Guard Patterns and Structure
Every 1D barcode includes structural elements beyond the data:
Start and stop patterns frame the barcode, telling the scanner where data begins and ends. Each symbology has unique start/stop patterns that also identify which format is being scanned — this is how scanners auto-discriminate between Code 128 and Code 39 without manual configuration.
Quiet zones are mandatory blank spaces before the start pattern and after the stop pattern. Without adequate quiet zones, the scanner can't distinguish the barcode from surrounding graphics. Insufficient quiet zones are the most common cause of scanning failures in production environments.
Check digits provide mathematical verification. The scanner reads the data, performs a calculation (modulo 10 for UPC/EAN, modulo 103 for Code 128), and compares the result to the encoded check digit. A mismatch means the scan is rejected, preventing corrupted data from entering your system.
How Scanners Read 1D Barcodes
Laser Scanners
A laser scanner emits a thin beam of red light that sweeps across the barcode. As the beam moves from left to right (or right to left, since most 1D barcodes scan bidirectionally):
- Black bars absorb the laser light
- White spaces reflect it back to a photodiode sensor
- The sensor converts the light/dark pattern into an analog electrical signal
- An analog-to-digital converter translates the signal into a digital waveform
- Decoding software measures the widths of bars and spaces in the waveform
- The software matches these widths against known symbology patterns to identify each character
The entire process takes 10-50 milliseconds. A retail checkout scanner performs this sweep hundreds of times per second, which is why barcodes seem to scan "instantly" even if you pass them through quickly.
Camera-Based Scanners (Imagers)
Modern scanners, including smartphones and our web-based scanner, use cameras instead of lasers:
- The camera captures an image (or video frame) of the barcode
- Image processing algorithms locate the barcode within the frame by detecting the high-contrast bar pattern
- The software straightens and normalizes the barcode image to correct for perspective and rotation
- A scan line is digitally "drawn" across the barcode image
- The same width-measurement and pattern-matching algorithms decode the data
Camera scanners offer advantages: they read 2D barcodes (which laser scanners cannot), work at various angles, and can capture multiple barcodes in a single frame. The trade-off is that image processing requires more computational power than laser reflection measurement.
| Feature | Laser Scanner | Camera-Based (Imager) |
|---|---|---|
| How it reads | Sweeps laser beam across bars | Captures full image of barcode |
| 1D barcodes | Yes | Yes |
| 2D barcodes (QR, Data Matrix) | No | Yes |
| Scan distance | Up to 30+ feet (long range) | Typically 1-15 feet |
| Speed | Very fast for 1D | Fast for both 1D and 2D |
| Damaged barcode handling | Limited | Better (image processing) |
| Cost | $50-200 | $100-400 |
| Best for | Retail checkout, single-format | Warehouse, multi-format scanning |
How 2D Barcode Encoding Works
Two-dimensional barcodes encode data in a grid of modules arranged in both horizontal and vertical directions. This two-directional encoding allows far higher data capacity.
Matrix Codes (QR Code, Data Matrix)
Matrix barcodes use a grid of square modules — each module is either dark or light, representing a binary 1 or 0. Data is encoded by reading the grid in a specific pattern defined by the symbology.
QR codes use three finder patterns (the large squares in three corners) for position detection, timing patterns for grid alignment, and format/version information to tell the scanner the code's size and error correction level. Data flows through the grid in a two-module-wide zigzag pattern from bottom-right to top-left.
Data Matrix uses an L-shaped finder pattern along two edges (the "solid" edges) and alternating modules along the other two edges (the "timing" edges). Data is encoded in codewords distributed throughout the grid.
Stacked Barcodes (PDF417)
PDF417 takes a different approach: it stacks multiple rows of linear barcode patterns. Each row is a miniature 1D barcode, and the rows are stacked vertically. This achieves 2D capacity while maintaining compatibility with linear scanning concepts.
Error Correction: Why Damaged Barcodes Still Scan
1D barcodes offer minimal error protection — a check digit catches some errors, but a damaged bar typically means a failed scan or, worse, a misread.
2D barcodes use Reed-Solomon error correction, a mathematical technique that adds redundant data to the barcode. This redundancy enables the scanner to reconstruct corrupted or missing data.
QR codes offer four error correction levels:
| Level | Recovery Capacity | Best For |
|---|---|---|
| L (Low) | ~7% | Clean environments, maximum data capacity |
| M (Medium) | ~15% | General use (default) |
| Q (Quartile) | ~25% | Industrial, outdoor |
| H (High) | ~30% | Harsh environments, logos overlaid on code |
This is why QR codes can have logos placed in the center — the error correction reconstructs the obscured data. It's also why partially scratched or dirty QR codes still scan when a 1D barcode in the same condition would fail.
Why Different Formats Exist
Each barcode format was designed for specific constraints:
Data type: UPC-A encodes 12 digits. Code 128 encodes the full ASCII character set. QR codes encode text, URLs, and binary data. The format matches the data requirement.
Physical space: EAN-8 fits on tiny packaging. Data Matrix marks surgical instruments. ITF-14 prints on corrugated cardboard. Each format is optimized for its physical environment.
Scanning infrastructure: Retail uses UPC-A/EAN-13 because the global POS infrastructure expects them. Logistics uses GS1-128 because warehouse systems parse its Application Identifiers. Format adoption follows infrastructure.
Error tolerance: A blood bank barcode (Codabar) must never misread — self-checking symbology prevents substitution errors. A boarding pass (Aztec Code) must survive screen glare and printing artifacts — error correction handles it.
For a detailed comparison of all barcode types, see our guides on 1D vs 2D barcodes and barcode vs QR code.
Try It Yourself
Scan any barcode with our free online barcode scanner to see the decoded data, barcode format identification, and country of origin for product barcodes. It works with every format discussed in this guide — from a simple UPC-A on a grocery product to a Data Matrix on a pharmaceutical package.