Make a barcode
Type a number and the bars appear. Code 128 for anything you invent yourself, EAN-13 or UPC-A for a registered retail number.
How it works
A barcode is a number written in bar widths. Nothing else is in there: no product name, no price, no address. A scanner measures the pattern, hands the string to a till or a stock system, and that system looks up everything a person would recognise. Choosing the symbology is the whole decision, because it fixes what characters the string may contain and who will accept it.
Code 128 for anything you control
Code 128 encodes any printable ASCII character, which covers asset tags, shelf locations, serial numbers, batch codes and internal part numbers. Nobody has to register anything: you invent the string, print it, and your own scanner reads it back. The symbology has three character sets, and this page moves between them as it encodes, dropping into the numeric set wherever a long enough run of digits appears. That set packs two digits into one symbol, so a run of numbers costs roughly half the width it otherwise would.
EAN-13 and UPC-A are numbers you have to own
Retail codes work differently. The thirteen digits of an EAN-13 open with a GS1 prefix issued to a specific company, and the barcode is only the printed form of a number that already exists in a registry. Generating a plausible-looking one here does not make it yours. A supermarket will reject it, or worse, it will collide with somebody else's product at the till. For a shop you run yourself, or for internal stock control, that matters much less, and Code 128 is usually the saner pick anyway.
The check digit, and what happens when it disagrees
The last digit of an EAN-13 or UPC-A is arithmetic rather than data. Multiply the other digits alternately by three and by one, add the products, and the check digit is whatever brings that total up to a multiple of ten. Paste twelve digits and this page works the thirteenth out and appends it. Paste all thirteen and it verifies the last one; where the arithmetic disagrees it tells you which digit belongs there, instead of drawing a barcode that scans as a number nobody was ever assigned.
Bar width decides whether the thing scans
The narrowest bar, called the X-dimension, is the unit every other measurement derives from. Retail codes are specified at 0.33 mm and may be printed anywhere between 80 and 200 percent of that. Below roughly 0.26 mm, inexpensive laser scanners start to miss. Bars here are a whole number of pixels wide, so the printed size is exact: at three pixels per bar and 300 dpi one bar measures 0.254 mm, the practical floor. Four pixels gives 0.339 mm, which sits in the middle of the retail tolerance.
The blank margin is part of the symbol
A scanner finds a code by seeing clear space before the first bar. Code 128 wants ten bar widths on each side. EAN-13 wants eleven on the left and seven on the right, and the margin control here will not go below those figures. The classic failure is a label trimmed flush to the bars, or a code pasted hard against a box edge. It reads on the desk and fails on the line, because the scanner never finds a start pattern it can trust.
Height, and the temptation to truncate
Retail bars stand 22.85 mm tall by default, for a reason. A fixed checkout scanner sweeps a fan of laser lines across the package at unpredictable angles, and tall bars give every one of those lines a chance to cross the whole pattern. Shortening the bars to save label space still works for a handheld reader that a person aims, and gets steadily worse for anything else. If the code will pass over a glass plate at a till, leave the height where it is.
Questions
Can I invent an EAN-13 for a product I want to sell?
Not for general retail. The first digits belong to a GS1 prefix licensed to one company, and a number outside your own prefix either gets refused at the retailer's data check or collides with an existing product. Buying a prefix is the only legitimate route. For a market stall, a warehouse or a shop with its own till software, print a Code 128 instead and skip the registry entirely.
It says my check digit is wrong. Is my number wrong?
One of the thirteen digits is, though the arithmetic cannot say which. The check digit catches every single-digit mistake and about nine in ten transpositions, so a mismatch almost always means a typo somewhere in the number. Compare it against the source, or paste only the first twelve digits and let the thirteenth be calculated.
How big should I print it?
Work from bar width rather than overall size. Three pixels per bar printed at 300 dpi gives a 0.254 mm narrow bar, which is about as small as ordinary laser scanners tolerate. Four or five pixels is a safer target for retail, for thermal labels, and for anything that will be photocopied. Print a test at final size and scan it with the reader that will actually be used.
Why is my Code 128 so much wider than an EAN-13?
EAN-13 is fixed at 95 modules whatever the digits are. Code 128 spends eleven modules per character plus a start symbol, a check symbol and a thirteen-module stop pattern, so width grows with your data. Pure digit strings get packed two per symbol and stay compact; mixed letters and digits do not. Shortening the string is the only real lever.