The LUHN formula, also known as the modulus 10 algorithm, was created in the late 1960s. Shortly thereafter, credit card companies started using it. Because the algorithm is in the public domain, it can be used by anyone. Currently it's used by credit card companies, libraries, pharmacies, many motor vehicle divisions, various banks throughout the world, as well as the Canadian Social Insurance Number (SIN). Almost any institution that needs a unique account or identification numbers use the LUHN algorithm.
Let's use the following numbers to work through the math:
2323-2005-7766-3554
First remove any non numeric characters, and reverse the string.
4553667750023232
Start with the second digit, double every other number.
4105661271450043434
Take the sum of every digit.
4+1+0+5+6+6+1+2+7+1+4+5+0+0+4+3+4+3+4=60
Divide the total by 10, if the remainder is 0 then the number is valid.
60 / 10 = 6 remainder 0, therefore 2323-2005-7766-3554 is valid
Now that we have the basic formula, credit card companies take it a step further and apply the following rules
Card Type | Prefix(es) | Length(s) |
MasterCard | 51-55 | 16 |
Visa | 4 | 13 or 16 |
American Express | 34 or 37 | 15 |
Discover | 6011 | 16 |
Diners Club / Carte Blanche | 300-305, 36, or 38 | 14 |