Eli5: How do they know if it is a valid card number?

328 views

When you are asked to input your card information online, how is it that some websites can automatically know if you input an invalid number and others cannot, before payment is processed?Example: as soon as I typed the last number of my card wrong, it went red and would not allow me to continue before I corrected it.

In: 340

8 Answers

Anonymous 0 Comments

There’s a pretty simple calculation you can do on a cc number to check if it’s an allowable number within the cc numbering system, and it doesn’t require access to the cc company to look anything up.

The rightmost digit is what’s known as a ‘checksum’. It’s the result of a calculation on the other digits as described [here](https://www.creditcardvalidator.org/articles/luhn-algorithm). Just google ‘credit card checksum’ for more sources.

Basically, you double every 2nd digit in the cc number starting from the end, subtract 9 from each if it’s greater than 9, add them all up, multiply the total by 9 and the last digit of the result is what was originally appended to the end of the cc number as the last digit on the right.

Different cc companies may use variation of this rule but this is the most common method. All cc numbers use some kind of checksum system when creating new account numbers.

If a customer gives you a cc number and it doesn’t pass the checksum test then you don’t have to bother checking any further. It’s invalid.

You are viewing 1 out of 8 answers, click here to view all answers.