Search topics and sections

A barcode is a pattern of dark and light marks that a machine reads with light to get data.

The data is usually a number that identifies a product, a package, or a document. In a shop, a scanner reads the barcode on an item, and a computer uses the number to look up the item's price.[1]

There are two main kinds:[2]

  • Linear (1D) barcodes are a row of side-by-side bars and spaces of different widths.
  • Two-dimensional (2D) barcodes, such as the QR code, are a grid of squares, dots, or other shapes that holds more data in a smaller area.

How a barcode works

A scanner reads a barcode in four steps:[1]

  1. The scanner shines light on the barcode.
  2. Dark bars absorb the light and light spaces reflect it.
  3. A photodiode (a light sensor that turns light into an electrical current) in the scanner turns the reflected light into an electrical signal.
  4. A small processor turns that signal into digits.

In a shop, the barcode itself usually holds only an identity number, not the price. The scanner sends the number to the store's computer, which finds the price in its records.[1]

How a shop barcode scan finds a pricePhotodiodeDark barsabsorb lightLight spacesreflect lightBarcode holds onlythe ID, not the priceElectricalsignalDecoder(processor)IDnumberStore computerPrice shownRegisterID numberID numberPrice
A scanner shines light on a barcode, and a photodiode detects the light reflected from the light spaces. A processor turns the signal into an ID number, and the store computer looks up the price for that number, because the barcode itself holds only the ID.

Linear and 2D barcodes

Barcodes differ in how they lay out data. A linear (one-dimensional, or 1D) barcode stores data only across its width, while a 2D barcode stores data both across and down.[3] Because 2D codes use both directions, they hold more data than 1D codes while staying smaller.[2]

Common linear codes include:

  • UPC-A, a 12-digit retail code.[4]
  • EAN-13, a 13-digit retail code.[4]
  • Code 39, which holds letters as well as digits.[5]
  • Code 128, which holds letters and digits while keeping the barcode dense.[6]
  • GS1-128, which can carry extra fields, such as batch numbers and expiration dates.[7]
Type Layout Typical capacity Examples
Linear (1D) One row of bars and spaces of varying widths Up to 48 characters for GS1-128[7] UPC-A, EAN-13, Code 39, Code 128
Stacked 2D Several rows of linear bar patterns piled on top of each other Up to 1,850 text characters or 2,710 digits for PDF417[8] PDF417
Matrix 2D A grid of square cells, dots, or other shapes Up to 7,089 digits for a QR code[9] QR code, Data Matrix
Linear and two-dimensional barcodes Linear (1D) Stacked 2D Matrix 2D Data runs across only Rows of bar patterns e.g. PDF417 Grid of cells e.g. QR code, Data Matrix Data runs across and down
Three kinds of barcode. A linear barcode stores data in one row of bars that is read across, a stacked barcode such as PDF417 piles several rows of bar patterns, and a matrix code such as a QR code stores data in a grid of square cells read across and down.

Symbologies

A symbology is a set of rules for turning characters into bars and spaces, or into cells in a grid. Each symbology sets:

  • which characters it can hold
  • how long the code can be
  • how it catches errors

Many symbologies are published as ISO/IEC standards, issued together by the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC). Examples are Code 128 (ISO/IEC 15417), Data Matrix (ISO/IEC 16022), and PDF417 (ISO/IEC 15438).[5]

Symbology Kind Notes
UPC-A Linear 12 digits; used on retail goods worldwide and widely in North America[4]
EAN-13 Linear 13 digits; used on retail goods around the world and works with UPC[10][4]
Code 39 Linear First barcode able to hold letters as well as digits; developed in 1974 by David Allais and Ray Stevens of Intermec[5]
Code 128 Linear Introduced in 1981; holds letters and digits without giving up density[5][6]; its GS1-128 form adds fields for data such as batch numbers and expiration dates[7]
ITF-14 Linear For outer cartons and cases that are not scanned at a checkout[4]
GS1 DataBar Linear Family of small codes for items such as fresh foods; approved in 1999[10]
PDF417 Stacked 2D Used on driver's licenses, boarding passes, and package labels[11]
Data Matrix Matrix 2D Comes in square and rectangular versions[4]; GS1 DataMatrix, approved in 2004, was the first 2D barcode adopted by GS1[10]
QR code Matrix 2D Made by Denso Wave in Japan in 1994[3]

Parts of a UPC-A barcode

The Universal Product Code (UPC-A) shows the parts that most linear barcodes share.

Its widths are measured in modules. A module, also called the X-dimension, is the width of the narrowest bar or space.[12]

A guard pattern is a special arrangement of bars and spaces that marks the start, center, or end of the code. Reading from left to right, a UPC-A symbol has these parts:[1]

  1. A quiet zone of 9 blank modules.
  2. A start guard pattern of 3 modules, which tells the scanner that data is coming.
  3. Six digits, each 7 modules wide (42 modules in all).
  4. A center guard pattern of 5 modules that splits the two halves.
  5. Six more digits (42 modules). The last is the check digit, an extra digit calculated from the other digits to catch errors.
  6. An end guard pattern of 3 modules.
  7. A second quiet zone of 9 modules.

The quiet zones are needed for the barcode to scan properly, so nothing may be printed in them.[13]

Between the two quiet zones, the symbol is 3+42+5+42+3=953 + 42 + 5 + 42 + 3 = 95 modules wide.

Each digit is drawn as two bars and two spaces that together fill 7 modules. Every digit has one pattern for the left half and a different one for the right half, which lets a scanner read the code in either direction.[1]

Anatomy of a UPC-A barcode95 modulesstart guard 3center guard 5check digitend guard 3quiet zone9 modulesleft 6 digits, 42 modulesright 6 digits, 42 modulesquiet zone9 modules0102030405060708090100110one digit = 7 modules: 2 bars + 2 spacesdigit 000011011234567spacebarspacebar
Layout of a UPC-A barcode: a 9-module quiet zone sits on each side of 95 coded modules. These form start, center, and end guards around two 6-digit halves of 42 modules each, and the last digit is the check digit. The close-up shows the left-half digit 0 as 7 modules with the pattern 0001101.

The 12 digits are a Global Trade Item Number in its 12-digit form, GTIN-12, represented in the UPC barcode.[14][4] The first eleven digits identify the company and the product, and the twelfth is the check digit.[15]

Check digits

A check digit is an extra digit computed from the other digits, so that a misread or mistyped number can be caught.[16]

The GS1 rule

GS1 numbers such as the GTIN find the check digit from a weighted sum, in these steps:[14]

  1. Start at the digit next to the check digit and move left.
  2. Multiply the digits by 3, 1, 3, 1, and so on.
  3. Add the products to get a sum SS.
  4. Take the check digit as the amount needed to bring SS up to the next multiple of 10, or 0 if SS is already a multiple of 10.

As a formula, step 4 is:

c=(10−(S mod 10)) mod 10c = \big(10 - (S \bmod 10)\big) \bmod 10

Here cc is the check digit, SS is the weighted sum of the data digits, and S mod 10S \bmod 10 is the remainder when SS is divided by 10. The outer  mod 10\bmod 10 makes c=0c = 0 when SS is already a multiple of ten.

A worked example

GS1 gives this example for a 13-digit GTIN with data digits 629104150021.[14]

Digit 6 2 9 1 0 4 1 5 0 0 2 1
Weight 1 3 1 3 1 3 1 3 1 3 1 3
Product 6 6 9 3 0 12 1 15 0 0 2 3

The products add to S=57S = 57. The next multiple of ten is 60, so the check digit is 60−57=360 - 57 = 3, and the full number is 6291041500213.[14]

Which errors it catches

For a 12-digit UPC d1d2⋯d12d_1 d_2 \cdots d_{12}, where d12d_{12} is the check digit, a valid number meets this condition:[15]

3d1+d2+3d3+d4+⋯+3d11+d12≡0(mod10)3d_1 + d_2 + 3d_3 + d_4 + \cdots + 3d_{11} + d_{12} \equiv 0 \pmod{10}

The symbol ≡0(mod10)\equiv 0 \pmod{10} means the left side leaves remainder 0 when divided by 10.

A factor of a number is a number that divides it evenly, so the factors of 10 are 1, 2, 5, and 10. A method like this catches every single-digit error exactly when each weight shares no factor with 10 other than 1, which holds for weights 3 and 1.[15] So the UPC rule catches every single wrong digit.[17]

Swapping two neighboring digits aa and bb changes the sum by 2(a−b)2(a-b). That change is a multiple of 10 only when aa and bb differ by 5, so the UPC rule catches every swap of neighboring digits except those where ∣a−b∣=5|a - b| = 5, such as 1 and 6.[17]

2D barcodes and error correction

A 2D code must solve a harder problem than a linear one, because the scanner first has to find the code and work out how it is turned. QR codes solve this with position detection patterns, or finder patterns: special marks at three corners that help a scanner locate the code and tell which way it is turned.[3]

Finder patterns

A line drawn through the center of a QR finder pattern crosses dark, light, dark, light, and dark areas in the width ratio 1:1:3:1:1.[3]

The QR code's developers at Denso Wave chose this ratio after studying printed matter such as leaflets, magazines, and cartons. They found it was the ratio that appeared least often there.[3] This makes it unlikely that nearby print is mistaken for a code.

Anatomy of a version 1 QR code1:1:3:1:1Finder patternData and errorcorrection codewordsQuiet zone21 × 21 modules (version 1)
A version 1 QR code has 21 × 21 modules, with a finder pattern in three corners and a light quiet zone around the whole symbol. A line through the middle of a finder pattern crosses dark, light, dark, light and dark segments in the ratio 1:1:3:1:11:1:3:1:1, which a scanner uses to locate the code.

Size and capacity

QR codes come in 40 sizes, called versions. Version 1 is 21 by 21 modules, and each later version adds 4 modules per side, up to 177 by 177 modules for version 40.[18]

A bit is a single 0 or 1, and a byte is a group of 8 bits. The largest QR code holds up to:[9]

  • 7,089 numeric digits
  • 4,296 characters made mainly from letters and digits
  • 2,953 bytes of binary data (raw 0s and 1s, not limited to text characters)
  • 1,817 kanji, the characters used in Japanese writing

Reed-Solomon error correction

Unlike a check digit, which only detects errors, QR codes can rebuild missing data. They add a Reed-Solomon code to the data, so a code that is dirty or partly damaged can still be read.[19]

Data is grouped into codewords, which are groups of 8 bits that each carry either data or error-correction information.[19]

The user picks one of four error correction levels:[9]

Level Share of codewords that can be restored
L About 7%
M About 15%
Q About 25%
H About 30%

Higher levels make the code larger for the same data. Level M is the one most often chosen.[19]

Reed-Solomon codes need twice as many extra codewords as the number of codewords to be corrected. For example, 100 data codewords plus 100 Reed-Solomon codewords can correct 50 codewords, which is 25% of the total and matches level Q.[19]

Reading barcodes

A barcode reader or scanner works in one of two main ways:[20]

  • It sweeps a laser beam across the code.
  • It takes a picture of the code.
Laser barcode scanner compared with an image-based scannerLaser scannerLaser diodeRotating mirrorPhotodiodeBar widths along one lineReads 1D codes onlyImage-based scannerImage sensorLensCaptures a whole pictureReads 1D and 2D codes at any angle
A laser scanner sweeps one beam across a linear barcode and reads the reflected light with a photodiode, so it measures bar and space widths along a single line. An image-based scanner uses a lens and an image sensor to capture a picture of the whole code, so it can read both 1D and 2D codes at any angle.

Laser scanners

A laser scanner uses a red laser diode (a small part that produces a laser beam) and a rotating mirror to sweep a beam across the barcode.[21] It measures the widths of the dark bars and light spaces along that single line.[20]

Its limits are:[20]

  • It reads only linear barcodes, because it sees only one line.
  • It struggles with damaged codes.
  • It struggles with codes on shiny surfaces.

Lasers still do well in two cases:[21]

  • The code is very close to the reader.
  • The distance between the code and the reader varies a lot.

Image-based scanners

An image-based scanner (imager) captures a whole picture of the code with an image sensor and decodes it with software.[20]

Because it sees the entire code, an imager can:[20]

  • read both linear and 2D barcodes
  • read codes at any angle
  • handle torn or smudged codes better than a laser scanner

Other uses of imaging include:

  • Reading many codes at once. One commercial tool can scan up to 100 1D or 2D barcodes on a package or pallet in one step.[22]
  • Phone scanning. Smartphone cameras read codes the same way, and QR codes are now regularly scanned with mobile devices.[4]

History

The first patent

The barcode began with Norman Joseph Woodland and Bernard Silver. The key steps were:

  • 1948 to 1949: While staying in Miami Beach, Woodland drew lines in the sand with his fingers, an idea that came from Morse code.[23]
  • 20 October 1949: Woodland and Silver filed a patent.[24]
  • 7 October 1952: The patent was granted as US Patent 2,612,994, "Classifying Apparatus and Method."[24]
  • 1961: They sold the patent to Philco for $15,000.[25]

Each line in the patent's pattern had a fixed place. A filled place stood for 1 and an empty place for 0, so the lines spelled a binary number (a number written using only 0s and 1s).[24]

A straight-line pattern had to be lined up with the scanner, so the inventors bent it into circles with the same center. This "bull's-eye" could be read from any direction.[24]

The patent's example sorted cans and packages on a conveyor (a moving belt that carries items) into price categories.[24]

Woodland and Silver bull's-eye barcodeScan lineReads the samefrom any direction
The bull's-eye barcode patented by Woodland and Silver in 1952 uses dark and light rings with the same center. Any scan line through the center crosses the same sequence of rings, so the code reads the same from any direction.

The Universal Product Code

Retail scanning became practical only after the laser and cheaper computers arrived.[26] The main events were:

  • 1972: Kroger ran the first test of retail barcode scanners, working with RCA on a checkout stand that used Woodland's bull's-eye design.[26]
  • 3 April 1973: A committee of the U.S. grocery industry chose a linear barcode as the Universal Product Code.[23]
  • Design: IBM's George J. Laurer designed the chosen code, based on Woodland's model and with much input from Woodland, who then worked at IBM.[23]
  • 26 June 1974: At 8:01 a.m., a 10-pack of Wrigley's Juicy Fruit gum became the first UPC-marked item scanned at a store, in a Marsh supermarket in Troy, Ohio.[23]

Spread and standards

Scanning spread slowly at first, and by the end of the 1970s only 1 percent of grocery stores had started using scanners.[26] By 1989, 17,180 U.S. grocery stores had scanning systems, 62% of the national total.[5]

Key later steps include:

  • 1974: Code 39, the first symbology to hold letters and digits.[5]
  • 1977: The European Article Numbering Association (EAN) forms in Brussels, with a barcode compatible with the UPC.[10]
  • 1981: Code 128, by Ted Williams, introduced by Computer Identics.[5]
  • 1994: Denso Wave releases the QR code, developed by a team led by Masahiro Hara.[3]
  • 2000: The QR code becomes an ISO standard, ISO/IEC 18004.[9]
  • 2004: GS1 DataMatrix becomes the first 2D barcode adopted by GS1.[10]
  • 2005: The U.S. Uniform Code Council and EAN merge to form GS1.[10]
Timeline of barcode history, 1949 to 2005 Patent filed1949 1952Patent granted Kroger scanner test1972 1973UPC chosen First UPC scan1974 1974Code 39 EAN formed1977 1981Code 128 QR code1994 2000QR code ISO standard GS1 DataMatrix2004 2005GS1 formed
Key barcode events from the patent filing in 1949 to the formation of GS1 in 2005, spaced according to the number of years between them. The events from 1972 to 1977 sit close together, from Kroger's scanner test in 1972 to the first UPC scan in 1974 and the forming of EAN in 1977.

By 2023, GS1 reported that over 1 billion products carried its barcodes and that they were scanned billions of times every day.[10]

Uses and limits

Barcodes let organizations identify and track items automatically as they move from maker to user.[2] Major uses include:

Field Use
Retail UPC and EAN codes at the point of sale[4]
Logistics GS1-128 labels that identify cases and pallets and carry data such as batch numbers and dates[7]
Healthcare GS1 DataMatrix codes that identify and trace medical products, including medical devices[27]
Documents PDF417 on identity cards and boarding passes[11]
Consumer links QR codes that carry web addresses, including GS1 Digital Link codes that connect a product to online information[10]

GS1 is working with industry to move toward 2D barcodes that hold more data.[2] It aims for checkout scanners worldwide to read 2D codes by the end of 2027.[10]

A barcode must be in the scanner's line of sight to be read. RFID tags need no line of sight and do not need to be scanned by hand.[28]

References

  1. Anatomy of a Bar Code, The New York Times, 1998.
  2. GS1 Barcodes, GS1.
  3. QR Code development story, DENSO WAVE.
  4. Types of Barcodes, GS1 US.
  5. The History of Automatic Identification, David Allais, ID Systems (Stony Brook University Libraries).
  6. Code 128, Seagull Scientific Barcode Guide.
  7. What is a GS1-128 barcode?, GS1 US.
  8. PDF417 Introduction, TEC-IT.
  9. QR Code Standardization, DENSO WAVE.
  10. GS1 Historical Timeline, GS1, 2025.
  11. PDF417, Seagull Scientific Barcode Guide.
  12. How big should a point-of-sale barcode be?, GS1 UK.
  13. What is a Quiet Zone?, GS1 UK, 2024.
  14. How to calculate a check digit manually, GS1.
  15. Additional Exercises: Detecting Errors, Thomas W. Judson, Abstract Algebra: Theory and Applications.
  16. What is a check digit?, GS1 UK.
  17. The Efficiency of Catching Errors: Check Digit Schemes and How They Work, Sacred Heart University.
  18. Information capacity and versions of the QR Code, DENSO WAVE.
  19. Error Correction Feature, DENSO WAVE.
  20. What Are the Different Types of Industrial Barcode Scanners?, Cognex.
  21. Choosing the right code reader: Laser versus vision, Balluff.
  22. SimulScan: Multi Barcode and Document Capture Software, Zebra Technologies.
  23. GS1 Brief History: Celebrating 45 Years of the Barcode Scan, GS1 US, 2019.
  24. US2612994A: Classifying apparatus and method, N. J. Woodland and B. Silver, US Patent Office, 1952.
  25. Guide to the N. Joseph Woodland Papers, Smithsonian National Museum of American History.
  26. Pack of chewing gum becomes first-ever item scanned with a UPC barcode, HISTORY.com, 2025.
  27. GS1 DataMatrix for the identification of medical products, GS1.
  28. Standards: RFID, GS1 Canada.

Figure