A barcode is a number written so a scanner can read it, and the number is not arbitrary. An EAN-13 — the thirteen-digit code on almost everything sold in Europe, Asia and Latin America — is three fields joined together, with a checksum on the end.
The prefix is not a country of origin
This is the one worth knowing, because a whole genre of phone app is built on getting it wrong. GS1 answers it themselves, in one line: “the GS1 Prefix does not show the country of origin”.
The first digits identify the GS1 member organisation that issued the company its number. Those organisations are mostly national, which is why the prefix looks like a country code and why it gets reported as one. It is not one.
A company registered in one country routinely sells products manufactured in another — that is what most consumer goods are. The prefix tells you where the number came from. It says nothing whatsoever about where the factory is, what is in the box, or who owns the brand today.
Two prefixes are genuinely informative rather than national. 978 and 979 mean the item is a book: the rest of the number is its ISBN. 977 means a periodical, carrying an ISSN. And 200 to 299 is reserved for shops to use internally — the number a supermarket prints on a bag of loose apples it weighed itself. Those never leave the shop, which is why two different shops can use the same one.
Where the company ends and the product begins
You cannot tell by looking, and this surprises people.
GS1 issues company prefixes of different lengths — a firm expecting to number a handful of products gets a long prefix and few digits left for items; a firm numbering tens of thousands gets a short one. So in the middle nine digits, the split between "which company" and "which product" is different for every company, and there is no marker in the number saying where it falls.
Which also means the number is not a description. Nothing in it encodes the price, the weight, the colour or the flavour. It is a key. Everything else lives in a database somewhere, which is why the same barcode scans as different prices in two different shops.
One consequence that catches new sellers: every variant needs its own number. A 500-gram bag and a 1-kilogram bag of the same coffee are two different trade items and take two different codes. So do two colours of the same shirt.
How the check digit works
The last digit is not chosen. It is calculated from the twelve before it, so a scanner can verify its own read rather than trusting it.
Take the digits from the left and multiply them alternately by one and by three. Add the results. The check digit is whatever gets that total up to the next multiple of ten. Working it through for 590123412345:
- Digits in the odd positions — 5, 0, 2, 4, 2, 4 — add up to 17.
- Digits in the even positions — 9, 1, 3, 1, 3, 5 — add up to 22, and multiplied by three that is 66.
- 17 + 66 = 83. The next multiple of ten is 90, so the check digit is 7.
The whole code is 5901234123457. A scanner redoes this on every read, and a code that fails is rejected rather than guessed at — which is why a barcode printed with the wrong last digit does not scan at all, despite looking perfect. The generator here calculates it for you, and tells you when a number you paste in has the wrong one.
UPC-A, EAN-8, and the rest
UPC-A is the twelve-digit version used in the United States and Canada. It is the same system: put a zero in front of a UPC-A and you have a valid EAN-13, and the bars are identical. A European scanner reading an American product is doing exactly that.
EAN-8 is the short one, for packets with no room for a full code — chewing gum, small cosmetics. Fewer digits means fewer available numbers, so they are rationed.
Code 128 is a different animal: it carries letters as well as digits, belongs to nobody, and needs no registration. If you are labelling your own stock, equipment or shelves, that is the one you want, and you can start this afternoon.
Can you invent a number?
You can draw one, and it will scan. Whether you should depends entirely on what it is for.
For a packaging mock-up, a photograph, a film prop or a test of your own scanner, an invented number is completely fine and nobody is harmed. For a product going on a shelf it is not: the number may already belong to somebody else's item, and a retailer's system will treat it as that item — wrong price, wrong stock, wrong product on the receipt. Numbers for real retail come from GS1, and they are not free.
The in-store range, 200 to 299, exists for exactly the internal case, and using it inside your own shop or warehouse is what it is there for.
Barcodes and QR codes are not the same idea
A barcode holds a key that means something to a database. A QR code holds the data itself — a whole web address, a Wi-Fi password, a contact card — which is why one is a few centimetres of stripes and the other is a grid. If what you want is for a phone camera to do something, you want a QR code, and our guide to what is inside one covers what that means for safety.