How Barcodes Work: Bars, Check Digits and Barcode Types
A barcode is really a number written in stripes, and a scanner only cares about the relative widths. Learn how a scanner reads one, how EAN, UPC and Code 128 differ, how to work out a check digit and what makes a printed code fail.
Barcodes are so ordinary that it is easy to forget how clever they are. A row of black stripes lets a shop till, a warehouse or a parcel depot identify an item in a fraction of a second, with far fewer errors than typing the number by hand. The idea dates back to a US patent from the early 1950s, but it took lasers and cheap computers to make it practical, and the first supermarket scan of a product came in 1974.
How a scanner reads stripes
A scanner shines light across the code and measures how much bounces back. Dark bars absorb light and pale spaces reflect it, so the result is a signal that goes up and down. Only the relative widths matter. The scanner works out the width of the thinnest element, called a module, and compares everything else to it. That is why a barcode can be printed large or small and be read from different distances.
Every format has fixed start and stop patterns, which tell the scanner where the data begins and which way round it is. A code can be scanned upside down because the decoder recognizes the patterns and reverses the reading. The clear white area on either side, the quiet zone, tells the scanner where the code begins and ends.
A standard barcode is called one-dimensional because all of the information runs along its width. The height of the bars only gives the laser or camera more room to find a clean line through any damage. QR codes are two-dimensional and hold much more data in the same area, but the simple linear codes are still everywhere because so many scanners and systems expect them.
The main types and what they are for
Barcode formats fall into two families. Some hold only a fixed number of digits, and those are used for standardized numbering. Others can hold variable text and are used for labels of your own.
- EAN-13 and UPC-A identify retail products. A UPC-A number is the same as an EAN-13 number with a leading zero, which is why tills around the world can read both. EAN-13 has 95 modules: 3 for the start, 42 for the left half, 5 for the center, 42 for the right half and 3 for the end. Each digit takes 7 modules.
- EAN-8 is a shorter retail code for packages too small to carry the full version.
- ITF-14 marks outer cartons. It encodes digits in pairs, one in the bars and one in the spaces, and tolerates being printed directly on rough corrugated card.
- Code 128 can hold letters, digits and symbols. Each character takes 11 modules, and a built-in checksum catches read errors. It is compact, which makes it a favorite for shipping and inventory labels.
- Code 39 is older and simpler. It holds capital letters, digits and a few symbols, and every character has nine elements, three of them wide. It takes more room than Code 128 for the same content, but many older systems still require it.
Worked example: calculating a check digit
The last digit of an EAN or UPC number is not part of the identity at all. It is calculated from the other digits so that a scanner can detect misreads. Take the 11-digit UPC body 03600029145:
- Write the digits from right to left: 5, 4, 1, 9, 2, 0, 0, 0, 6, 3, 0.
- Multiply them by 3, 1, 3, 1 and so on: 15, 4, 3, 9, 6, 0, 0, 0, 18, 3, 0.
- Add them up: 58.
- The next multiple of 10 is 60, so the check digit is 60 − 58 = 2.
The full code is 036000291452. The Barcode Generator gives the same result: leave out the last digit and it adds 2 for you.
The same rule works at any length. The EAN-8 body 9638507 gets the check digit 4, the EAN-13 body 400638133393 gets 1, and the ITF-14 body 1234567890123 gets 1.
What a check digit can and cannot catch
The check digit always catches a single wrong digit, because changing one digit always changes the total by an amount that is not a multiple of 10. It also catches most cases of two neighboring digits being swapped. The exception is a pair whose digits differ by exactly 5, such as 7 and 2. Swapping them changes the total by a multiple of 10 (3 × 7 + 2 = 23, while 3 × 2 + 7 = 13), so the last digit of the total stays the same and the error goes unnoticed. Credit card numbers use a similar idea called the Luhn algorithm, with different weights and different blind spots.
How to use the generator
Pick the format based on where the code will be used, not on how it looks. For a product in a shop, you need EAN or UPC with a registered number. For a stockroom shelf or asset tag, Code 128 is usually the best choice. In the Barcode Generator, enter the value, set the bar width and height, and press Generate. Download SVG if the code is going to print, since it stays sharp at any size.
Printing codes that scan
Most failed barcodes are print problems, not data problems:
- Keep contrast high. Black on white is safest. Scanners commonly use red light, so red bars on a white label look like empty space, while dark blue or black bars work much better.
- Protect the quiet zone. As a rule of thumb, leave clear space on each side of about ten times the width of the thinnest bar. The Barcode Generator leaves 11 bar widths of white on each side, so keep that margin when you place the code in a label design and keep text, borders and fold lines away.
- Do not shrink too far. Thin bars blur together, especially on low-resolution label printers. A retail EAN-13 is about 37 mm wide at its nominal size, and GS1 publishes the allowed range for retail use, so check current specifications if you are printing packaging.
- Do not stretch PNG images. Scaling by a fraction changes bar widths unevenly. Scale by whole numbers or use SVG.
- Test before the full run. Scan a real print with the actual scanner, and try a phone app as a second check.
FAQ
What do the first digits of a product barcode mean?
They are a GS1 prefix, which shows the GS1 member organization that issued the number. A prefix does not reveal the country where a product was made. Many products are manufactured in one place and registered through a company in another.
Can a barcode hold a web link?
Code 128 can technically hold a short address, but a linear code gets very wide as it grows, and phones do not treat it as a link in the same way. A QR code is the better choice for a link.
Can I make up my own barcode numbers?
For your own stockroom, yes. Any internal numbering works with Code 128 or Code 39. For retail sale, retailers expect a number registered to your company, and inventing one could clash with a real product already in their system.
Why does a scanner read the code but return the wrong characters?
The barcode is often fine and the issue is the scanner's setup. Many scanners act like a keyboard, so a keyboard layout that differs from the scanner's settings can turn characters into other ones. Scanners may also have certain formats turned off by default, so a code will not read at all until you enable that format.
Related tools
Related guides
How QR Codes Work and How to Make One That Scans
A QR code is a grid of black and white squares that holds a link, text or Wi-Fi login and still works when part of it is damaged. Learn what the patterns mean, how size and error correction interact and how to print one that scans every time.
How Password Strength Checkers Work (and What They Miss)
Two 12-character passwords with the same mix of characters can differ by a factor of hundreds of quadrillions. See how strength checkers spot patterns, how to read the score and what no checker can know.
What Is CGPA? Scales, Calculation and Converting to a Percentage
CGPA sums up your whole academic record in one number, but the same figure means different things on a 4, 5 or 10-point scale. See how it is calculated, how it moves and why percentage conversions differ.
How to Scan a QR Code Safely, With or Without a Phone
A QR code can hide any link, and you only see it after you scan. Learn how to scan from a camera or a screenshot, read what a code really contains, spot a fake one and fix a scan that fails.