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

When Sony shipped the first Walkman in 1979, chairman Akio Morita insisted on a second headphone jack and a “hotline” talk button, convinced it would be rude for one person to listen to music alone — and within a few years buyers had ignored the sociable features so completely that Sony quietly dropped them
Russia still custom-builds the Soyuz return seats for ISS crew members using plaster casts taken weeks before launch, because astronauts grow as much as five centimetres taller during a long-duration stay and a seat moulded to their Earth-shaped spine would no longer fit the body that comes home
The “CrackBerry” nickname stuck for a reason — and the variable-reward psychology that hooked early-2000s executives on their BlackBerrys is the exact same machinery now running every push notification on every smartphone in your pocket
In 1843, Ada Lovelace described a brass-and-punched-card engine that could act on symbols as well as numbers, even composing music if harmony could be reduced to rules, inside seven translator’s notes three times longer than the paper itself
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