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.
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:
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:
| Network | Starts with | Length |
|---|---|---|
| Visa | 4 | 13, 16 or 19 |
| Mastercard | 51 to 55, 2221 to 2720 | 16 |
| American Express | 34 or 37 | 15 |
| Discover | 6011, 644 to 649, 65 | 16 or 19 |
| RuPay | 60, 6521, 6522, 81, 82, 508 | 16 |
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.
Try our free tools
Put these tips into practice with 45+ free online tools - no signup, no login.
Browse Free Tools