Card Validation

Card validation is a process to check if a credit card is valid for online purchases or not. There are pre and post validation processes.
There are 4 sections of a credit card. Luhn Algorithm Check, Major Industry Identifier, Issuer identification number and Personal Account Number

Table of Contents

How to do Credit Card Validation

Credit card numbers are generated according to certain rules. It gives merchants a way to verify the validity of a card number before accepting the customer's payment.

The calculation to compare a credit card number with your checksum is known as the Luhn algorithm.

What do the Digits on a Credit Card Number Mean?

To understand the composition of a credit card number, we can break it down into four parts:

  • The 1st Digit: The first digit is the card network indicator. Some card networks use the first 2 digits as their identification as well.
    For example, Visa cards always start with a ‘4’ whereas Amex cards always start with a ‘3’ which is immediately followed by either a ‘7’ or a ‘4’.
  • 2nd to 6th Digits: The 2nd, 3rd, 4th, 5th and 6th digits are used to identify the card issuer e.g., a bank branch.
  • 6th to Second-to-Last Digit: All the digits, after the 6th up till the second-to-last one, are generated uniquely for every cardholder.
  • Last Digit: The last digit in any credit card number is called the ‘checksum’ or the ‘check digit’.
    This value is used to verify whether the rest of the numbers are correctly placed. This validation is done using the Luhn algorithm.

What are the Number Formats of Different Credit Card Networks?

While the general layouts of all the credit card networks are closely similar, there are some minor distinguishing differences.

It is worth noting that other than the card number format, the rest of the details i.e., the expiry date, CVV and accountholder name are all written the same way in all layouts.

Coming back to the point, there are four major credit card networks in the world: Visa, Mastercard, American Express and Discover.

1. Visa

Visa cards have two distinct features in their card numbers:

  • They always begin with ‘4’
  • They have 13 to 16 digits in total

These are some examples of standard Visa card numbers:

4956 6185 5002 8752

4081 9806 2935 3449

2. MasterCard

Mastercard cards can be identified by these two characteristics:

  • The starting digit is always ‘5’
  • They always have 16 numbers in total

Some examples of Mastercard card numbers:

5453 6809 6059 3325

5492 2479 2143 8645

3. Amex (American Express)

The number layout in Amex cards has these two qualities:

  • It is made up of 16 digits
  • It always starts with a ‘3’ which is followed by a ‘4’ or a ‘7’

Some examples of Amex cards are:

3718 5810 1319 293

3499 2979 0395 594

4. Discover

Discover card numbers can be identified by the following features:

  • They start with the numeral ‘6’
  • They have a total of 16 digits

Some examples of Discover cards are:

6011 2653 9018 9036

6011 8328 2589 7994

How to Manually Check the Validity of a Credit Card Number Using the Luhn Algorithm

It may sound complicated but running the Luhn algorithm on any set of numbers isn’t actually that hard.

You could do it in a couple of minutes using a pen and paper…if you wanted to.

To understand the working of the algorithm, let’s take a random card number as an example i.e.:

6011 8328 2589 7994

These are the steps that you need to follow to manually check the validity of any card number against the Luhn algorithm.

First Step

Starting from the right side of the string, take every alternating digit and multiply it by 2.

In this example, they would be:

6011 8328 2589 7994


If any number becomes more than 9 after being multiplied, add both of its digits together. For example, 6 x 2 = 12. Since 12 is more than 9, we add up both the digits: 1 + 2 = 3.

The new number, after applying this step, becomes:

   3021 7348 4579 5994

Second Step

Next up, add all the digits together.

3 + 0 + 2 + 1 + 7 + 3 + 4 + 8 + 4 + 5 + 7 + 9 + 5 + 9 + 9 +4

Third Step

If the sum of all these digits is a multiple of 10 i.e., it ends with 0, it will satisfy the Luhn algorithm.

3 + 0 + 2 + 1 + 7 + 3 + 4 + 8 + 4 + 5 + 7 + 9 + 5 + 9 + 9 +4 = 80

In this case, the answer is 80, which means that this number satisfies the Luhn algorithm.

The Formula for Generating the Checksum

In the example above, the credit card number was fully formed i.e., it had a checksum or a ‘check digit’ at the end.

However, if a card number does not have the checksum at the end, we can apply a formula on the other digits and compute it manually.

Take this number, for example:


This is an incomplete number since it does not have a check digit at the end. The combination of numerals other than the checksum is known as the payload.

First Step

The steps for the checksum computation are initially the same as the Luhn algorithm procedure.

Every alternating digit, starting from the right, has to be multiplied by 2. If the sum goes in excess of 9, the two digits will be added.

The resultant numbers will be:


Second Step

After the number has been generated according to the step above, add them all together.

In the case of this example, the sum will be 67.

Third Step

This is the formula that is applied to the sum of the values in order to generate the checksum:

((10 – x mod 10) mod 10) = x

In our example, the formula will become:

((10 – 67 mod 10) mod 10) = 3

‘3’ will be the checksum.

The importance of credit card validation

It is important to keep in mind that whenever fraudulent cards are used, the merchant loses. The customer of a stolen credit card is not hooked, and the credit card companies are generally not affected.

However, the merchant generally stays away from the product or service provided, as well as the resources necessary to discover the fraud and fight against the credit card company. And if too many fraudulent transactions occur, you may incur higher processing fees, expensive chargebacks, or even losing your merchant account and your ability to do business.

But you can mitigate these risks with the help of a little automation, and we can help you! Simply use our online card validator tool and our tool help you to combat fraud and maximize the sales of your credit cards.

Tips for credit card and PIN security

  • Sign your card as soon as you receive it.
  • Save your card as if it were cash.
  • Memorize your PIN. Never write it down
  • Be sure to receive your card from the vendor or waiter when you use it.
  • Shred the receipts that contain the full account number if you do not need to keep them.
  • Review your account statements as soon as you receive them to make sure all transactions are yours.
  • Make a list of your credit card numbers and customer service phone numbers and keep it in a closed place. If your purse or wallet is lost or stolen, this will make it easier for you to call to cancel the cards.

How many digits are in a Credit Card Number?

  • Visa and Visa Electron: 13 or 16
  • Mastercard: 16
  • Discover: 16
  • American Express: 15
  • Diner's Club: 14 (including enRoute, International, Blanche)
  • Maestro: 12 to 19 (multi-national Debit Card)
  • Laser: 16 to 19 (Ireland Debit Card)
  • Switch: 16, 18 or 19 (United Kingdom Debit Card)
  • Solo: 16, 18 or 19 (United Kingdom Debit Card)
  • JCB: 15 or 16 (Japan Credit Bureau)
  • China UnionPay: 16 (People's Republic of China)


Do we keep these credit card numbers?

Absolutely not! The credit card number entered in our validator was made using the validation rules. However, we do not store these credit cars for security reasons.