If you own a credit card, you will know that it contains a string of 16 digits where you have to key in when making an online purchase. At a glance, these numbers look random and there doesn’t seem to have pattern associated with it. The fact is, these number *do* follow a pattern and it is pretty simple to generate a series of valid credit card number. Let’s take a look at how credit card numbers work.

**Note**: A valid credit card number means that it can be validated by the algorithm used to encrypt the number. It doesn’t mean that you can use this number to make a purchase.

## Decrypting the Credit Card Numbers

There are 16 digits in the credit card number and it can be divided into three parts.

1. The first digit represents the major industry identifier (MII). It identify the institution/industry that issues the card. For example, number that starts with:

- 1 and 2 are issued by airlines.
- 3 is issued by travel and entertainment, such as American Express and Diners Club.
- 4 is issued by VISA
- 5 is issued by MasterCard
- 6 is issued by merchandising and banking.
- 7 is issued by petroleum companies.
- 8 is issued by telecommunications companies.
- 9 is issued by national assignment.

Together with the next 5 digits, the first 6 digits of the string of number form the Issuer Identification Numbers (IIN). This will tell you who is the exact institution that distribute this credit card. If you can follow the pattern, a bank issuing a VISA credit card will have the first digit as “4″ and the bank code for the next five digits. All VISA credit cards issued from this bank will have the same six beginning digits.

2. The 7th – 15th digits of the credit card number represent the customer account number. This is unique for each customer. It allows the bank to identify the owner of the card.

3. The last digit is a check digit that is used to verify the first fifteen digits. It makes use of the Luhn Algorithm (also known as Mod 10 algorithm). How it works is very simple:

- Write down your credit card number. Counting from the right, double the digit in the even position (2nd, 4th, 6th… 16th).
- If the doubled digit is more than 9, add up the number so it becomes a single digit. For example, if the doubled digit is
~~13~~14, add “1″ to “4″ so it becomes “5″. - Now, add up all the numbers. The resulting number should be divisible by 10.

For example:

- Take the credit card number 3782 8224 6310 005
- Starting from the right, double the digits on the even position, this will give us: 3 14 8 4 8 4 2 8 6 6 1 0 0 0 5
- Adding up the digits for the number that is more than 9: 3 5 8 4 8 4 2 8 6 6 1 0 0 0 5
- Add up all the digits: 3 + 5 + 8 + 4 + 8 + 4 + 2 + 8 + 6 + 6 + 1 + 5 = 60 which is divisible by 10

If you work backward, you can easily work out the last digit of the credit card number.

For example, assume that the last number is unknown, so we have 3782 8224 6310 00x

- Starting from the right, double the digits on the even position, this will give us: 3 14 8 4 8 4 2 8 6 6 1 0 0 0 x
- Adding up the digits for the number that is more than 9: 3 5 8 4 8 4 2 8 6 6 1 0 0 0 x
- Add up all the digits: 3 + 5 + 8 + 4 + 8 + 4 + 2 + 8 + 6 + 6 + 1 + x = 55 + x. The nearest number that is divisible by 10 is 60, so x has to be 5

## What is a CVV Number?

When you make an online purchase, other than the credit card number, the payment gateway will also ask you to enter a CVV number that is located at the back of the credit card. The CVV number is generated by encrypting the card number, expiry card and a secret encryption keys (which is unique for every issuing bank). This is a security feature and it is not easily crackable.

## Resources for obtaining valid credit card numbers

If you are a developer and need to test your payment gateway without using your actual credit card number, you can make use of Credit card numbers generator to obtain a series of valid credit card numbers. You can select the issuing bank and number of entries. Paypal also comes with a list of credit card numbers that you can use to test.

Now that you know the “secret” to your credit card numbers, you can go ahead and test it out with your credit cards.

Image credit: commerce bank card, Living on Credit Cards

Ernie says

One problem with your math… you can’t double a number and get an ODD number. 13? Really? Guess that’s why you are a writer and not a numbers guy. ;-) Good info otherwise.

Damien says

Oops… I didn’t realize that.

Sam Googlian says

I have tried that with my Visa card.

After doubling and adding up, it came out to be 42.

I suppose this is not what is meant by divisible by 10.

Also “If you work backward, you can easily work out the last digit of the credit card number.” is not clear to me. … This can be interpreted 100 different ways! Can you clarify?

Maybe you should have worked a full example to prove this case :)

Damien says

I have added an example in the article to illustrate the Mod 10 algorithm.

You should try again. It should work.

Sam Googlian says

Thank you!

I think there is a typo in the example …

“Take the credit card number 3782 8224 6310 005″

Isn’t this just 15 digits?

Or do I need a new pair of glasses? :)

Sorry if this will cause you recalculate the whole example!!!

Sam Googlian says

Oops!

I saw your comment further down “15 digits are common ….”

Nolan says

6.5 + 6.5 = 13. Oh…You must have been referring to numbers in the context of credit cards and not math in general. Don’t you just hate douche bag know-it-alls who think it’s their ethical obligation to make somebody feel stupid?

John Selden says

I think I see the problem. The mod-10 algorithm didn’t work on my card either (at first), but then I re-read your instructions. You said to double the numbers in the even positions “starting from the right,” but in your example you started from the left. When counted from the right, you should actually end up doubling the 1st, 3rd, 5th, etc. numbers when counted from the left. When I did it that way, it worked on my card.

John Selden says

Also, your sample credit card numbers should have 16 digits, not 15. The unknown “x” should be the 16th digit, not the 15th, and looks like it should be counted as the “first” digit when you are doing the doubling.

Damien says

15 digit credit card numbers are pretty common too and they are valid as well.

Tom Moore says

While it’s not exclusive, the first number of 6 is also used by Discover Card.

Damien says

Thanks for informing. I didn’t know that.