How Do You Know if a Credit Card Number is Valid?

As a followup to my recent post about what your credit card number means, I wanted to throw out a bit more credit card trivia and talk about how you can tell if a credit card number is valid.

As you may or may not aware, most credit card numbers are generated based on something known as the Luhn algorithm. It thus stands to reason that a credit card number is valid if (and only if) it satisfies the “Luhn check” (a.k.a., the Mod 10 check), which is a simple mathematical test that involves manipulating the credit card number, adding it up, and checking to see if it’s evenly divisible by ten.

Testing credit card numbers

Here’s how to apply the Luhn check to test whether or not a credit card number is valid:

  • Step 1a. For a card number with an even number of digits (e.g., Visa or MasterCard), double alternating digits starting with the first digit in the sequence.
  • Step 1b. For a card with an odd number of digits (e.g., American Express), double alternating digits starting with the second digit in the sequence.
  • Step 2. If the doubling resulted in a number with two digits, add them together to get a single digit number
  • Step 3. Now go back to the original credit number and replace the digits that you doubled with the new value — either the doubled value, or the doubled value with the digits added together — and add it all up.
  • Step 4. Check to see if the sum is evenly divisible by 10 (you can simply look to see whether or not it ends with a zero).

If the card number does not pass this check, then it is not a valid number. If, on the other hand, it does pass, then it may be a valid number with valid credit report.

Checking validity: an example

Those steps are a bit convoluted, so here’s a real world example… The following credit card image comes from the CitiCards homepage for their Platinum Select MasterCard. The number on the card is 5424 1801 2345 6789. For starters, the fact that the number starts with a “5” indicates that it’s a MasterCard (as does the little MasterCard symbol on the card).

Since there are sixteen digits, we’ll start by doubling the 1st, 3rd, etc. digits and then summing as outlined above. I’ve highlighted the doubled (and in some cases summed) values in parentheses, below. I’ve also underlined the check digit.

(1+0) + 4 + (4) + 4 + (2) + 8 + (0) + 1 + (4) + 3 + (8) + 5 + (1+2) + 7 + (1+6) + 9

This totals up to 70, which is evenly divisible by 10. In other words, this is a potentially valid credit card number, though I’m sure it doesn’t correspond to a real account number. If it does, then L. Walker (the name on the card) probably isn’t too happy about his/her credit card number being spread around like this.

Comment Policy: We love comments! However, the comments below are not provided or commissioned by this site or its advertisers. Comments have not been reviewed, approved or otherwise endorsed by this site or its advertisers. It is not this site or its advertisers' responsibility to ensure all comments and/or questions are answered.

22 Responses to “How Do You Know if a Credit Card Number is Valid?”

  1. Anonymous

    Hi Nickel!

    You are almost done! The issue is that you have calculated the whole card’s number, with the last check digit included, in this case the digit 9, which added up the sum to be 70.

    Let’s do a control and verify the authenticity of this card to see if it is valid or not, it all depends on the last digit, the check digit number 9.

    Okay, our mission is to handle the last digit 9. We will have two alternatives to deal with it:

    a) either that we have the total number as you computed 5424 1801 2345 6789:

    (1+0) + 4 + (4) + 4 + (2) + 8 + (0) + 1 + (4) + 3 + (8) + 5 + (1+2) + 7 + (1+6) + 9
    Sum = 70 ( in this case with the last single check digit 9)

    b) Or let’s assume that the digit 9 was missing: 5424 1801 2345 678 x
    Sum = x + 61

    In both cases, we need to confirm the value of x. We achieve this with the aid of Luhn algorithm or Luhn formula:

    The check digit (x) is obtained by computing the sum of digits then computing 9 times that value modulo 10 (in equation form, (67 ? 9 mod 10)).

    In algorithm form:

    1. Sum of digits:

    (1+0) + 4 + (4) + 4 + (2) + 8 + (0) + 1 + (4) + 3 + (8) + 5 + (1+2) + 7 + (1+6) x + 61

    2. Multiply by 9 = 61 * 9 = (549)
    The last digit, 9, is the single check digit. Thus, x=9.

    (Alternative method) The check digit (x) is obtained by computing the sum of digits then subtracting the units digit from 10 (61 = Units digit 1; 10 − 1 = check digit 9).

    In algorithm form:
    1. Compute the sum of the digits (61).
    2. Take the units digit (1).
    3. Subtract the units digit from 10.
    4. The result (9) is the check digit.
    In case the sum of digits ends in 0, 0 is the check digit.

    Finally, the card’s number looks to be valid, but the card itself remains difficult to confirm its authenticity.

  2. Anonymous

    The amount of scammers asking for card numbers in the comments is hilarious, and the SEO spam from “kazakhstan almaty” just doesn’t fit.

    Dear SEO spammer, you should’ve asked for a credit card number to illegally use in your post. It would make it fit in better.

  3. Anonymous

    First of all I want to say wonderful blog! I had a quick question that I’d like to ask if you do not mind. I was curious to find out how you center yourself and clear your head before writing. I’ve had a difficult time clearing my mind
    in getting my thoughts out there. I do enjoy writing but it just seems like the first 10 to 15
    minutes are usually wasted just trying to figure out how to begin.

    Any suggestions or hints? Cheers!

  4. Nickel

    Gregg: You are indeed correct, and I’m apparently lame when it comes to working a calculator. The example is laid out properly, but I added it up wrong. I’ve fixed it. Thanks!

  5. Anonymous

    The card given in the example, 5424 1801 2345 6789, adds up to 70, not 67. Supposedly, this means it could be a valid card. If this really is the example given on the CitiBank site as an “invalid” card it raises questions about their accuracy.

  6. Anonymous

    For some example cards that are valid you can try:


    These are purely test cards that are given out by Visa and Mastercard for merchants to test their credit card frontends. For a more complicated test, the expiration on those is 12/49, their CV value is 999, the address is ‘123’ (since really only the numbers in an address matter) and the zip code is 12345.

    As a follow up to what you said yesterday, MasterCard is only 5099-5499, with 55 being Maestro. Above that its a mix of private label and Wright Express if memory serves me right.

    Discover actually processes for Diners Club International, JCB (Japan Credit Bureau), and CUPS (China Union Pay). Discover is a subset in 6011 and their new range of 6440-6599. Diners Club is 3000-3095, 3600-3699, and 3800-3899. JCB is a subset of 35, while CUPS is a subset of 62.

    That’s why AMEX has 34 and 37.

    With VISA and MC also identify what type of card you have by the BIN (Bank Identification Number), which are the first 6 digits. So merchants can identify what rate they’re going to be charged for that transaction and whether they should attempt to get the customer to enter their Debit PIN (which is cheaper for the merchant). AMEX on the other hand does not do this, which is why, for example when you shop at Walmart with an AMEX, you must always enter your zip code. Zip code information along with the purchase is known as Level 2 and must be included for certain card types. Since the merchant doesn’t know based on the BIN with AMEX, the only safe move is to always ask for it.

  7. Anonymous


    Like MikeS said, very cool series of articles. I did a search and there are actually tools that will run this validation automatically, like the one at:
    (For disclosure, I have nothing to do with that site).

    In keeping with the spirit of liking finance and random trivia, I added your post to my roundup of links for the week 🙂

Leave a Reply