Have you ever taken a moment to ponder those 16 digits on your credit or debit/ATM card, how they were chosen to be unique for your card? It’s actually more interesting — and ordered — than you might think.
Nick Berry, currently a data scientist at Facebook, on his blog Datagenetics recently put together a post explaining just how these numbers are generated.
First things first. The numbers appearing first in the sequence actually indicate what type of card it is. This list has all the “issuer identifier” numbers, but here are a few examples:
Mastercard: 51-, 52-, 53-, 54-, 55-
Discover: 6011, 65-
American Express: 34-, 37-
From there, the subsequent numbers, according to Berry, are determined by the issuer but the last digit is mathematically chosen based on all other numbers on for the card. It’s call the check digit.
Here’s more about the importance of this last digit:
You don’t select this last digit, it is deterministic. The exact mathematic formula for its generation was invented by Hans Peter Luhn, an engineer at IBM in 1954. Originally patented, the algorithm is now in the public domain and a Worldwide standard ISO/IEC 7812-1
Obviously, with just a single check digit, not all errors can be detected (there’s a one in ten chance of a random number having the correct check digit), but the Luhn algorithm is clever in that it detects any single error (getting a single digit wrong), such as swapping the 9 with a 6 in the above example. It also detects almost all* (*It will not detect the switching of 09 to 90 (or vice versa)) pair-wise switching of two adjacent numbers. These errors are typical common errors people make when transcribing card numbers, so the check digit does a good thing.
An added side benefit is that, as discussed above, there is only a one in ten chance that a randomly generated number has the correct check digit. This provides a small amount of protection from hackers or poorly educated crooks who might attempt to randomly generate and guess credit card numbers.
To actually generate the check digit, every number in the even position is multiplied by two (that means the number falling second, fourth, sixth, etc. would be multiplied). If this multiplication creates a two-digit number, like multiplying nine by two resulting in 18, then the two digits are added together to make a single digit number (1+8). Add all the results of the multiplication and digital roots together. Then add every number in an odd-digit position to this sum. Now, the check digit is whatever number is needed to get this total to be a multiple of 10.
Featured image via Shutterstock.com.