


The concept of check digits has been around for a long time. There are also systems that are expanded to deal with errors in text and not just numbers. These offer all the benefits of Luhn (detecting any single digit error), but also are able to detect any pair-wise adjacent transpositions of digits. These are the Verhoeff algorithm (1969) and the Damm algorithm (2004). Here are a selection of other common numbers have have check digits baked in (not all using Luhns Algorithm there are a few other common encoding systems in use):Īutomobile VIN numbers, Barcodes, ISBN numbers on books and magazines, Australian Tax Numbers, Hungarian Social Security Numbers, American bank routing codes …įor those interested in learning more, there are a couple of more complicated check digit algorithms than Luhn. Other usesĪdding a check digit is a very common practice to ensure that numbers are well-formed and have not fallen foul to a simply transcribing error, or unimaginative fraud.

Performing a client-side smoke-test to make sure things are well-formed before transmitting to the server is a good way to reduce load on your server. The script on the page is purely a client-side test to confirm the check digit is correct. Type a number into the box below and click the button to test:ĭon't worry the numbers you type in are not being sent anywhere (if you are paranoid, you can view the source of the page to confirm). What number should be added to string to make a sum that, when divided by 10, gives no remainder.) Try it for yourself!
#Credit card checksum mod#
(This is the same thing as asking what value the check-digit would need to be to make the sum mod 10 equal to zero. So the check-digit for this fictitious number is 3. In our case, we’d need to add 3 to make 70. The check-digit is what number needs to be added to this total to make the next multiple of 10.

This will result in a total (in our example =67). To this total, we then add every odd-position digit. If the result is a two digit number, then add these digits together to make a single digit (this is called the digital root). To calculate the check digit, multiply every even-position digit (when counted from the right) in the number by two. The Luhn algorithm uses modulo-10 mathematics. The Luhn algorithm is based around the principle of modulo arithmetic and digital roots. * It will not detect the switching of 09 to 90 (or vice versa) The Luhn Algorithm This provides a small amount of protection from hackers or poorly educated crooks who might attempt to randomly generate and guess credit card numbers. These errors are typical common errors people make when transcribing card numbers, so the check digit does a good thing.Īn 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. It also detects almost all* pair-wise switching of two adjacent numbers. 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. Originally patented, the algorithm is now in the public domain and a Worldwide standard ISO/IEC 7812-1 The exact mathematic formula for its generation was invented by Hans Peter Luhn, an engineer at IBM in 1954. You don’t select this last digit, it is deterministic. In a typical sixteen digit credit card number, the first fifteen digits are determined by the issuing bank, but the last digit, called the check digit, is mathematically determined based on all the other digits. To try and minimize this, credit card numbers contain a check digit. Humans often make mistakes in transferal. All of this transmission can cause errors, especially considering that humans are involved. (Here you can find a more complete list of Issue Identifier Numbers)Ĭredit card numbers are often typed in, input, transferred and quoted. To the left is a (non-exhaustive) list of the some of the common card prefixes.Ĭards can be identified by their first few digits (try it out now, pull a few cards out of your wallet and look them up). Some cards are Visa, some Mastercard, some are American Express … Issuer The first few characters of the card number describe the type of card. For obvious reasons, just any sixteen digits will not work, they follow pattern. These digits are the unique account number for the card. These, typically, have sixteen digits on the front. Most of us carry credit cards and ATM cards.
