Illustration showing how the Luhn algorithm calculates and validates a credit card check digit

The Luhn algorithm was developed by Hans Peter Luhn and IBM in 1954. It is also known as the Luhn Check or Mod Check.

The Luhn algorithm is used in two ways.

  1. Preparing a given number according to the Luhn algorithm (with the check digit value)
  2. Validating a given number according to the Luhn algorithm

Check Digit Calculation

The check digit value is a value calculated based on mod 10 of the sum of the values other than the check digit itself. The algorithm works as follows:

  • The rightmost digit is the check digit. Starting from the check digit, we multiply the 1st, 3rd, 5th... digits by 2. (The 2nd, 4th, 6th... digits remain unchanged.)
  • If the sum of the values is greater than 9, we add their digits together to find the sum of the digits.
  • Finally, all the resulting digits are added together.
  • The sum of the digits is multiplied by 9.
  • The last digit of the resulting number is the check digit value.

Example

Card Number
Card no37144963539843X
Step 1 - Multiply the values by 2
Multiply by 231418418665691646X
Step 2 - Add the resulting values
Add the Values35184966569746X
Step 3 - Add all the values

3 + 5 + 1 + 8 + 4 + 9 + 6 + 6 + 5 + 6 + 9 + 7 + 4 + 6 = 79

Step 4 - Multiply by 9

79 x 9 = 711

Result

Check Digit Value = 1.

You can use the tool at the link below to calculate the check digit value.

http://www.datageneratortools.com/card/calculator

Check Digit Validation

You can see how a given number is validated according to the Luhn algorithm in the image below.

Step-by-step diagram illustrating Luhn algorithm validation of a card number
  • Starting from the rightmost check digit and moving left, we multiply the 1st, 3rd, 5th... digits by 2.
  • If the sum of the values is greater than 9, we add their digits together to find the sum of the digits.
  • Finally, all the resulting digits are added together.
  • If the total sum is a multiple of 10, the card number is valid. If it is not a multiple of 10, the number is invalid.

Example

Card number
Card No371449635398431
Step 1 - Multiply the values by 2
Multiply the Values314184186656916 46 1
Step 2 - Add the Values
Add the Values351849665697461
Step 3 - Add All the Values

3 + 5 + 1 + 8 + 4 + 9 + 6 + 6 + 5 + 6 + 9 + 7 + 4 + 6 + 1= 80

Step 4 - According to Mod 10 (80/10=8, divides evenly.)

80 % 10 = 0

Result:

The card number is Valid.

If you want to validate a card number, you can use the link below.

http://www.datageneratortools.com/card/validator