How Credit Card Numbers Work

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:

  1. Write down your credit card number. Counting from the right, double the digit in the even position (2nd, 4th, 6th… 16th).
  2. 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”.
  3. 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

credit-card-numbers-amex

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

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Damien Oh Avatar

Read next

ARPANET sent its first message on 29 October 1969 from a lab at UCLA to a machine at Stanford, and the message was supposed to read ‘LOGIN’ — but the system crashed after the L and the O, meaning the first word ever transmitted over the network that became the internet was, by accident, ‘LO’.
In 1995, Microsoft shipped a cartoon-house interface called Bob, led by Melinda French, who married Bill Gates while it was in development — it demanded twice the memory of a typical home PC, sold roughly 30,000 copies, and was dead within a year, leaving behind the font Comic Sans and the animated assistant that became Clippy.
The Greenland shark grows about one centimetre a year, does not reach sexual maturity until around age 150, and a specimen carbon-dated by Danish researchers in 2016 was estimated to be at least 272 years old, meaning it was already swimming the North Atlantic when Mozart was composing symphonies.
When Apple shipped iOS 12 in June 2018, a small feature called Screen Time slipped onto every iPhone with a counter nobody had quite prepared for — a tally of pickups — and within a day Tim Cook was telling CNN the number of times he picked up his own phone was simply too many
When NASA lost contact with the IMAGE satellite in 2005, an amateur radio operator in Canada named Scott Tilley picked up its signal in January 2018 while hunting for a classified spy satellite, and the spacecraft turned out to be still spinning, still powered, and still trying to phone home after 13 years of silence.
The original iPhone Steve Jobs unveiled in January 2007 could not record video, could not copy and paste text, could not run a single third-party app, and could only reach the internet over 2G — and Jobs spent ninety minutes on stage at Macworld arguing, one missing feature at a time, that every absence was actually a design decision.
In 1965, Joe Sutter’s Boeing team began shaping the 747 around a future they thought would belong to supersonic jets, lifting the cockpit onto a hump so the nose could open for cargo once the giant subsonic passenger plane had outlived its brief moment
Apple’s original 1984 Macintosh keyboard had no arrow keys, no function keys, and no numeric pad because Steve Jobs wanted users to reach for the mouse first. Then Apple quietly sold the missing keys as an accessory.