Table of Contents

Online shopping has become an indispensable part of our daily lives. We use our credit and debit cards so frequently for shopping that we can recite the card information by heart. But how are the bank and credit card numbers we often use for our purchases generated? In this article, we will answer the questions: What is the Luhn Algorithm and its purpose?

dört adet kredi kartı ve bir kilit sisteminin bulunduğu fotoğraf

Discovery of the Luhn Algorithm

The Luhn algorithm, also known as mod 10, was discovered by Hans Peter Luhn, who worked at IBM in 1954 when bank cards were not yet a part of our lives.

The Luhn Algorithm was designed not to protect card information from malicious individuals but to safeguard against user errors. Thanks to the Luhn algorithm, if you enter 9792060000000009 instead of 9792060000000007 as your card number, the system will likely give you an invalid card error.

Many credit and debit cards have 16 digits and are located on the front of the card. The first digit to distinguish card organizations is 4 for Visa cards, 5 for MasterCard, 3 for American Express, and 9 for Troy cards. In all these cards, the last digit of the number sequence on the card is the check digit. This check digit, generated using the Luhn Algorithm, is used to verify the validity of a credit card number.

How to Perform Card Validation with the Luhn Algorithm?

Let’s verify the validity of the credit card number 4847 3529 8926 3094 using the Luhn algorithm as an example:

First, let’s match the corresponding values of the credit card number in the range of 0-15.

Starting from the right, take the values corresponding to odd numbers in the range of 0-15. (For example, the digit corresponding to 15 is 4)

4 + 0 + 6 + 9 + 9 + 5 + 7 + 8 = 48

List the values corresponding to even numbers in the range of 0-15 starting from the right, then multiply each by 2. If the multiplication results in a two-digit number, add the digits together. (For example, the digit corresponding to 14 is 9)

9 3 2 8 2 3 4 4 -> We listed the even-digit values starting from the right.

18 6 4 16 4 6 8 8 -> We multiplied each number by 2.

1+8 = 9, 1+6 = 7 -> We added the two-digit numbers together.

Now, let’s add these numbers together:

9 + 6 + 4 + 7 + 4 + 6 + 8 + 8 = 52

In the final step, we add the values corresponding to odd numbers to the values corresponding to even numbers, and if the result is evenly divisible by 10, we can say that this is a valid card.

48 + 52 = 100, and since 100 is evenly divisible by 10, this card number is valid.

birinde kredi kartı bulunan iki insan eli ile bir laptop bulunan görsel

For more detailed information and a Github code example, you can visit the link here.

Through our article written by our experienced payment team, you can access fundamental information about payment systems.

If you have further questions, you can also contact us at [email protected].

    Kişisel verileriniz İnternet Sitesi Aydınlatma Metni kapsamında işlenmektedir.

      Your personal data is processed within the scope of the Clarification Text on Our Website.