The Math in Credit Card Security

We had a fun little discussion via email at the day-job. Someone changed the code on the combination lock and the discussion around combinations, permutations, cryptography and all things sneaky-math cranked up.

It reminded me of this neat fact I learned about credit card security.

Not all digits on a credit card are created equally!

A credit card is made up of 16 numbers. But only the first 15 are “random,” according to NRich Math. The last number – the 16th number – is the “check digit.” It’s calculated using a fancy formula using the first 15 digits.

This check digit helps a computer system quickly determine if a credit card number is fake. Now, it can’t confirm that it’s real – it just can help determine if it is fake.

The digit is created using a method called Codabar.

First, let’s define some things.

An odd digit is a digit in the credit card number that is in an odd position. For the photo of the card here, the number is:

5184 8204 5526 6423

And the odd digits are 5, 8, 8, 0, 5, 2, 6, 2

An even digit is a digit in the credit card number that is in an even position. For the photo of the card here, even digits are 1, 4, 2, 4, 5, 6, 4, 3

The check digit is the last digit – it gets calculated and isn’t considered in either odd or even position. It’s a super special digit.

The method is weird – and kinda fun!

Here’s what you do:

  1. Add up all the odd digits, or the digits in the odd positions: 5 + 8 + 8 + 0 + 5 + 2 + 6 + 2 = 36
  2. Double that number: 36 × 2 = 72. Save this number, 72, for later…
  3. Add the even digits together, or the digits in the even positions: 1 + 4 + 2 + 4 + 5 + 6 + 4 + 3 = 29. Save this number, 29, for later…
  4. (This is a freaky step.) Count the number of odd digits that are greater than 4. The odd digits are 5, 8, 8, 0, 5, 2, 6, 2. Of these, 5, 8, 8, 5 and 6 are bigger than 4. There are 5 of those total. Save this number, 5,  for this next step…
  5. Add up the results you saved from steps #2, #3 and #4. 72 + 29 + 5 = 106
  6. Take the answer from step #5 and figure out how many you need to add to get it to the next multiple of 10 (or the next number that ends in zero). The number after 106 that ends in zero is 110. So we need to add 4. 106 + 4 = 110. 4 is the super important number.
  7. That final super important number – well, that’s the check digit! That’s the last number that should be on the credit card – if it were a real card!
For the picture, the check digit, should be a 4. And it’s a 3. So I can tell instantly that this is a fake credit card number.

You can use this to teach your children!

Stuck in a waiting room with a 10-year-old? All you need is a pen, piece of paper and any credit card in your wallet.

Teach them the method and have them check all of your credit cards. Or tell them you can guess the last digit of any credit card number.

Either way, you’ve got an instant source of entertainment wrapped in a ball of education!

What do you think? Are you racing to your purse right now to check your cards? Share your thoughts in the comments.



This post may contain affiliate links. When you use them, you support us so we can continue to provide free content!

4 Responses to The Math in Credit Card Security

  1. The credit card trick posted here doesn’t work on any of my credit cards. I looked into and learned about the Luhn Mod 10 check method. It’s similar, but this article didn’t quite get it right.

    1) Replace each odd-positioned digit in your number with its double. If any doubling yields a 2-digit number, add those digits together to get a single-digit answer. (Ex: If you have an 8, then 2 * 8 = 16, so you will use 1+6, or 7.)

    2) Add up all 16 digits of your new “modified” credit card number.

    If your resulting sum is NOT evenly divisible by 10, you have a fraudulent credit card number.

    For the credit card pictured in the article, the last digit (check digit) would need to be a 7 to be valid, not a 4 like they stated.

    If you prefer the method explained in the article, just omit step 6 and 7. If your result from step 5 is divisible by 10, you have a valid card number.

    Why are the methods still so different? They aren’t. The article asks you in step 4 to add 1 for each number above 4 in an odd position. That’s the same as adding the digits of the double in my step 1. Because we are only interested in making sure the ONES place eventually gets set to zero, we can disregard the TENS place and convert back to a single digit.

    If you double 0, 1, 2, 3, or 4 you will get a single digit answer. This is the same in both methods.

    If you double 5, 6, 7, 8, or 9 you will get 10, 12, 14, 16, or 18. Adding the digits (like in my method) yields 1, 3, 5, 7, or 9. Adding a 1 for the occurance of such number (as in the article’s method) yields 11, 13, 15, 17, or 19. Either way, you get the same value for the ONES place, which is all that matters anyway.

    Kris

    • Thanks so much, Kris, for explaining this. I haven’t had a chance to look through your explanation and mine in great detail yet, though. I look forward to doing it – these things are so fascinating!

      Thanks for stopping by!

  2. Your method doesn’t work for AmericanExpress cards because they only have 15 numbers and not 16. You also said not to could the ‘check number’ in your math but you actually DID use the check number…just saying.
    But I used your method with several 16 number credit cards and it did work so nice way to figure this stuff out

Leave a reply