Skip to main content

Home / Blog / How Barcodes Work: CODE128, UPC and EAN Explained

How Barcodes Work: CODE128, UPC and EAN Explained

Barcodes are everywhere — on groceries, parcels, library books and hospital wristbands — yet few people know how they work. This guide explains how a scanner reads those black bars, what CODE128, UPC and EAN mean, and how to print a barcode that actually scans.

How a barcode actually works

A barcode is a way of writing numbers and letters so a machine can read them quickly. The black bars and white spaces are not random: their widths follow a strict pattern, and a scanner measures those widths to recover the original text. It is the same idea as writing, except the reader is a light sensor instead of an eye, and it reads hundreds of characters a second without typos.

When a scanner shines light across a barcode, the black bars absorb the light and the white spaces reflect it. The scanner turns that pattern of light and dark into electrical signals, measures the width of each bar and space, and matches the sequence against the rules of the barcode format. If the pattern is valid, the scanner outputs the text — usually a product code or a serial number — as if someone had typed it on a keyboard.

CODE128, UPC and EAN: which one do you need?

CODE128 is the flexible all-rounder. It can encode letters, digits and symbols, which makes it the usual choice for internal labels, warehouse shelves, asset tags and shipping labels, where the code might be a SKU such as SKU-2026-001 rather than a plain number. Most barcode scanners read CODE128, and it packs a lot of characters into a short strip.

UPC-A is the barcode you see on products in American shops. It holds exactly 12 digits: a company prefix, a product number and a check digit. EAN-13 is its international cousin, with 13 digits, and it is the standard on products sold in Europe and most of the rest of the world. If you are putting a product on a shop shelf, the retailer will tell you which of these you need, and you cannot invent one — the number has to be registered.

For anything that is not a retail product, CODE128 is almost always the right choice. It needs no registration, it accepts the text you already use, and it works with the same scanners. That is why the barcode generator on this site produces CODE128: it is the format most people actually need for labels and inventory.

What to check before you print a barcode

A barcode that scans on screen can still fail on paper, and the reasons are almost always the same. First, leave a quiet zone: a clear white margin on both sides of the bars, at least as wide as ten narrow bars. Scanners use that empty space to find where the code starts and ends, and text or borders touching the bars will confuse them.

Second, keep the contrast high. Black bars on white paper scan best; pale grey, coloured bars on a coloured background, or a barcode printed over a photograph are all asking for trouble. Third, do not shrink the code too far. A barcode printed smaller than about 25 millimetres wide is hard for many scanners to read, especially the cheap ones built into phones.

Finally, test-scan the printed label with the actual scanner or phone you will use, not just the one on your desk. Printers stretch images slightly, and a label that looks fine can be a few percent too wide or too narrow. One test scan before printing a hundred labels saves a hundred useless labels.

Common mistakes to avoid

The most common mistake is encoding the wrong data: a price instead of a product code, or a product name with a typo. A barcode is only as good as the text behind it, so check the characters before you generate it, and keep a record of which code belongs to which product.

Another mistake is reusing the same code for two different products, or changing a product without changing its code. Scanners do not know what a product is — they only know the number. If two products share a number, the till or the warehouse system cannot tell them apart, and stock counts go wrong in ways that are hard to trace.

Frequently asked questions

What is a CODE128 barcode?

CODE128 is a widely used barcode format that can encode letters, digits and symbols in a compact strip. It is commonly used on product labels, shipping labels and inventory tags.

Can I use any text in a barcode?

CODE128 accepts letters, digits and common symbols. UPC and EAN, by contrast, accept digits only and need a registered number for retail products.

Why won't my barcode scan?

The usual causes are a missing quiet zone, low contrast, printing too small, or a blurry copy. Print from the original file, keep black bars on white, and test-scan before printing in bulk.

Do I need to register a barcode number?

For retail products sold in shops you need a registered UPC or EAN number. For internal labels, inventory and shipping, a CODE128 barcode with your own SKU needs no registration.

Try the Barcode Generator on Daily Tools — free, no sign-up, and it runs in your browser.

Related: QR Code Generator tool.

Related: what a hash generator is.