Developer Tools 6 min read

How Credit Card Numbers Are Validated: The Luhn Algorithm

Every card number carries a built-in checksum. Learn how the Luhn algorithm works, how card networks are identified and what validation can and cannot tell you.

Imaginex AI Team
November 27, 2026

The Last Digit Is a Checksum

The final digit of a card number is calculated from the others with the Luhn (mod 10) algorithm. It catches almost every single-digit typo and most swapped neighbouring digits, so checkout forms can reject mistakes before contacting the bank.

Luhn Step by Step

Take 4111 1111 1111 1111:

  • Starting from the right, double every second digit.
  • If doubling gives a number above 9, subtract 9.
  • Add all the digits together.
  • If the total is a multiple of 10, the number is valid.
  • For this number the total is 30, so it passes. Change any single digit and the check fails.

    Identifying the Card Network

    The first digits (the issuer identification number) and the length reveal the network:

    NetworkStarts withLength
    Visa413, 16 or 19
    Mastercard51 to 55, 2221 to 272016
    American Express34 or 3715
    Discover6011, 644 to 649, 6516 or 19
    RuPay60, 6521, 6522, 81, 82, 50816

    What Validation Cannot Tell You

    A number that passes Luhn is only well formed. It does not prove the card exists, is active, has funds or belongs to the person typing it. Real authorisation always happens with the payment gateway.

    Test It

    Paste test numbers into the [Credit Card Validator](/tools/credit-card-validator). It runs entirely in your browser, but you should still only use test numbers such as 4111 1111 1111 1111.

    Summary

    The Luhn checksum is a cheap first line of defence against typos, and the prefix and length tell you the network. Use both in your forms, then let the payment provider do the real verification.

    Tags
    Luhn algorithmcredit cardpaymentsvalidation

    Try our free tools

    Put these tips into practice with 45+ free online tools - no signup, no login.

    Browse Free Tools