
Sometimes there are hidden patterns in numbers you might not immediately notice. One example of this is in barcodes, the sequences of digits we use to identify products.
Try it yourself – find an object with a 13-digit barcode. (If you are in the US, a 12-digit barcode will also work, if you imagine an extra 0 on the front of it.) Books won’t work, since they use a slightly different system, but magazines do, so you can use a copy of ¿ìè¶ÌÊÓÆµ. Add together the first, third, and fifth digits and so on, to get the sum of the odd-numbered digits; then, add up the even digits. If you triple the even sum, and then add it to the original odd sum, the total should be a multiple of 10, ending in 0.
Advertisement
This isn’t a coincidence: a barcode contains a checksum, ensuring that when it is scanned, it has been read in correctly. Most of the digits are there to communicate information. The first two are a country code (50 means it is a product produced in the UK). The next 10 digits are more specific information about the product and who produced it.
The purpose of the final digit is to detect errors or changes in the data, such as swapping two digits, or entering one incorrectly. This would give a checksum that isn’t a multiple of 10, allowing us to catch the error.
Barcode scanners use lasers to pick up the pattern of stripes, which encodes the same numbers. But these scanners are often cheap and can make errors, especially if the barcode is on a curved or shiny surface. So if you scan a barcode in a supermarket, it will read in the digits, compute the checksum and only beep if it is right – and until it gets a correct read, it won’t accept it.
All kinds of systems have checksums: ISBNs on books, which use a similar system based on multiples of 11; UK driver’s license numbers, which have two extra check digits at the end; and credit card numbers, meaning a website can tell you have entered it incorrectly before even checking with your bank. They all use variations of the same system, performing a simple calculation with the digits that confirms the number is valid.
It won’t eliminate errors – for barcodes, there is still a 1 in 10 chance the checksum will come out as a multiple of 10 even if there is an error – but it greatly reduces them. It also doesn’t tell you what the error is, so all you can do is try scanning the number again. But it saves time that would otherwise be wasted trying to process incorrect numbers, and it is an ingenious use of maths that makes the whole system more robust.
And if you were looking for a practical application, here is a great party trick: ask someone holding a bottle to read out all but one digit of the barcode, and with a bit of practice you can tell them the missing number. Maybe you’ll even earn yourself a free drink!
Katie Steckles is a mathematician, lecturer, YouTuber and author based in Manchester, UK. She is also adviser for New ¿ìè¶ÌÊÓÆµâ€™s puzzle column, BrainTwister. Follow her @stecks
For other projects visit newscientist.com/maker