Fascinating is the only word I can think of to describe the following design in credit cards that I had no idea existed. I would almost guarantee that very few of my readers would know either!

      You’re at the checkout screen after an online shopping spree, ready to enter your credit card. You type it in and instantly see a red error message: “Please enter a valid credit card number.” Annoyed, you scan back through each digit and spot the culprit: you tapped the “6” key where a “5” belonged. Typo corrected; purchase complete. But how did the website detect your error so quickly? Does the online platform keep a master list of every valid credit card number to compare your entry against? Did it ping your bank in a split second? The explanation is much cleverer.

      All mainstream credit card numbers obey a mathematical trick designed to catch the most common typos. It’s called the Luhn algorithm, named after IBM researcher Hans Peter Luhn, who patented it in 1960. Similar error-checking schemes lurk in many of the numbers you encounter daily: barcodes, package tracking numbers, bank account numbers and even ISBNs on books.

      Look at a credit card from your wallet, and you’ll find it contains more structure than at first glance suggests. The anatomy of a credit card number includes four main parts. To demonstrate, I’ll use my personal Visa.

      The first digit is the major industry identifier. Visas always start with a 4, and Discovers always start with a 6. The next five to seven digits pinpoint the bank or institution that issued the card. What remains (sans the final digit) is your specific account number within that bank. The final digit, sometimes called the “check digit” has nothing to do with financial institutions. Issuers tack it on so that the whole card number will satisfy a specific mathematical test. – the Luhn algorithm. Here’s how the algorithm works:

  1. Write out all but the last digit of the card number.
  2. Double every other number starting at the right.
  3. Sum the resulting digits (not the numbers), E.g. if you doubled a 7 to become a 14 in step 2, this will become 1+4=5 in this step.
  4. Add the check digit to the sum. If the result is not a multiple of 10, then the credit card is invalid.

      I’ll show the Luhn algorithm in action on my Visa, but you should try it with your credit card, too.

      The number crunching culminates in 75, which is not a multiple of 10. So this cannot be my real credit card number; I must have mistyped it.

      Credit card issuers first assign the account numbers and then compute steps one through three of the Luhn algorithm to determine the appropriate check digit. In this case, the card number should have ended in a 3 because 67+3=70, a multiple of 10.

      This particular dance of digits has come to dominate credit card verification because of its simplicity and powerful set of features. If you mess up any single digit when entering your card number, the Luhn algorithm will detect it. I you accidently swap adjacent card digits while inputting, it will detect that, too (with the exception of flipping 09 to 90, or vice versa).

      Dutch mathematician Jacobus Verhoeff reported in 1969 that two errors – mistyping a single digit and swapping two neighboring digits of one’s card number – account for nearly 90% of all human input errors in practice.

      Importantly, passing Luhn’s algorithm does not guarantee a valid credit card number. However, failing it guarantees an invalid credit card number. The algorithm puts up the first line of defense that less common typos and savvy fraudsters can slip through. Thos cases get caught by the more resource-intensive card-validation services.

      How does Luhn’s algorithm know when your fingers fumble? Every digit in a credit card number contributes a one-digit number to the final sum in the algorithm. If the digit sits in a position that does not get doubled, then it just contributes itself to the sum. But even if a digit sits in a doubled position, summing the individual digits of the resulting two-digit number always yields a one-digit number again.

      Next time a checkout page flashes that annoying error message, you will definitely remember this blog!!! You may also remember that a simple piece of math just saved a little time and money for everyone involved.

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

For security, use of hCaptcha is required which is subject to their Privacy Policy and Terms of Use.

I agree to these terms.

Scroll to Top