What a check digit is and how it works
The last digit in EAN-13 or UPC-A isn't random — it's mathematically derived from the ones before it. Here's what it's for and why that's a good thing.
If you've ever noticed that the last digit on a product barcode seems to "not fit" the pattern, that's not a typo. It's a check digit — a mathematically calculated value used to verify that the rest of the code is correct.
What it's actually for
Imagine a till scanner in a shop misreading one bar of a code — say, because of a damaged sticker or a bad scanning angle. Without a check digit, the till would read an incorrect but still "valid-looking" code, and the wrong price could end up attached to the product.
With a check digit, the scanner recalculates after reading the code whether the last digit matches what it should be. If it doesn't, the code is rejected and a rescan is requested, instead of letting faulty data through.
How it's calculated (EAN-13 and UPC-A)
The process is the same for both formats, UPC-A simply has one fewer digit (it's technically EAN-13 with a hidden leading zero):
- Take the first 12 digits (for UPC-A, the first 11 plus a leading zero).
- Add up the digits in odd positions (1st, 3rd, 5th...) as they are.
- Multiply the digits in even positions (2nd, 4th, 6th...) by three.
- Add all the values together.
- The check digit is whatever number needs to be added to that sum to make it divisible by ten.
Example for the first 12 digits 590123412345: the sum of the multiplied and unmultiplied values comes out needing 7 more to reach the next multiple of ten — so the complete code is 5901234123457.
Why you can't just make one up
If you invented the last digit instead of calculating it, the code would look convincing — it would look like an ordinary EAN-13 — but no scanner would accept it as valid. At best, a till would reject it outright; at worst, you'd only discover the problem once the code came off the printer and wouldn't scan.
How our generator handles this
In the barcode generator you don't have to calculate the check digit yourself. Enter just the first 12 (EAN-13) or 11 (UPC-A) digits and the generator works out the last one for you. If you enter it yourself anyway and it doesn't match, the generator tells you clearly instead of silently producing a code that won't work.
What about CODE128?
CODE128 has its own, different checking mechanism (called a check symbol rather than a check digit), which is calculated and added automatically when the code is generated — so there's nothing to worry about for this format, it takes care of itself.