Credit Card Number Generator & Validator
Validate a credit card number with the Luhn algorithm and identify its issuer, or generate fake, Luhn-valid test numbers for Visa, MasterCard, American Express, Discover, JCB, Diners Club, Maestro and more.
Validate a credit card number
Result
Fake credit card numbers for all major brands
They are generated at random in your browser and only satisfy the Luhn checksum and the issuer's prefix and length rules, so they are accepted by form validation code. They are not linked to any account, have no balance and cannot be used to buy anything. Use them to test e-commerce checkouts, payment forms and validation routines.
Custom generator
How to validate a credit card number
Every payment card number ends with a check digit computed with the Luhn algorithm (also called "modulus 10" or "mod 10", described in ISO/IEC 7812-1). It was designed to catch accidental typing errors (a wrong digit, two adjacent digits swapped) before a transaction is even attempted. It is not a security feature: a number that passes the check is well formed, it is not necessarily attached to a real account.
The algorithm, step by step
- Drop the last digit of the number: this is the check digit you want to verify.
- Reverse the remaining digits.
- Multiply the digits in odd positions (1st, 3rd, 5th... of the reversed number) by 2.
- If a product is greater than 9, subtract 9 from it (equivalent to adding its two digits together).
- Add all the resulting digits together.
- The check digit is the amount that must be added to this sum to reach a multiple of 10:
(10 − sum mod 10) mod 10. If it equals the digit you dropped in step 1, the number is valid.
Worked example with 4556737586899855
| Original number | 4 | 5 | 5 | 6 | 7 | 3 | 7 | 5 | 8 | 6 | 8 | 9 | 9 | 8 | 5 | 5 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Drop the last digit | 4 | 5 | 5 | 6 | 7 | 3 | 7 | 5 | 8 | 6 | 8 | 9 | 9 | 8 | 5 | |
| Reverse the digits | 5 | 8 | 9 | 9 | 8 | 6 | 8 | 5 | 7 | 3 | 7 | 6 | 5 | 5 | 4 | |
| Multiply odd positions by 2 | 10 | 8 | 18 | 9 | 16 | 6 | 16 | 5 | 14 | 3 | 14 | 6 | 10 | 5 | 8 | |
| Subtract 9 from numbers over 9 | 1 | 8 | 9 | 9 | 7 | 6 | 7 | 5 | 5 | 3 | 5 | 6 | 1 | 5 | 8 | |
| Add all numbers | 1 + 8 + 9 + 9 + 7 + 6 + 7 + 5 + 5 + 3 + 5 + 6 + 1 + 5 + 8 = 85 | |||||||||||||||
| Mod 10 | 85 mod 10 = 5, so the check digit is 10 − 5 = 5, which matches the last digit of the number: 4556737586899855 is valid. | |||||||||||||||
A typical implementation walks the digits from right to left and doubles every second digit, which is the same computation without the explicit reversal:
function luhnCheck(number) {
const digits = number.replace(/\D/g, '');
let sum = 0, double = false;
for (let i = digits.length - 1; i >= 0; i--) {
let d = +digits[i];
if (double) { d *= 2; if (d > 9) d -= 9; }
sum += d;
double = !double;
}
return sum % 10 === 0;
}
Anatomy of a card number
- MII (Major Industry Identifier): the first digit identifies the industry of the issuer: 1-2 airlines, 3 travel and entertainment (American Express, Diners Club, JCB), 4-5 banking and financial (Visa, MasterCard), 6 merchandising and banking (Discover, UnionPay), 7 petroleum, 8 healthcare and telecommunications, 9 national assignment.
- IIN / BIN (Issuer Identification Number, Bank Identification Number): the first 6 digits (8 digits since the 2017 revision of ISO/IEC 7812) identify the issuing institution. The table below lists the ranges of the main networks.
- Account number: the digits between the IIN and the check digit, assigned by the issuer.
- Check digit: the last digit, computed with the Luhn algorithm.
List of credit card formats by issuer
Card numbers are between 12 and 19 digits long. The issuer can be recognised from the first digits (IIN range) combined with the length of the number. This is the table used by the validator and the generator above.
| Issuer | Starts with (IIN range) | Length |
|---|---|---|
| American Express | 34, 37 | 15 |
| Diners Club - Carte Blanche | 300-305 | 14 |
| Diners Club - International | 36 | 14 |
| Diners Club - USA & Canada | 54, 55 | 16 |
| Discover | 6011, 622126-622925, 644-649, 65 | 16-19 |
| InstaPayment | 637-639 | 16 |
| JCB | 3528-3589 | 16-19 |
| Maestro | 5018, 5020, 5038, 5893, 6304, 6759, 6761, 6762, 6763 | 16-19 |
| MasterCard | 51-55, 222100-272099 | 16 |
| Visa | 4 | 13, 16, 19 |
| Visa Electron | 4026, 417500, 4508, 4844, 4913, 4917 | 16 |
| UnionPay | 62 | 16-19 |
| Mir | 2200-2204 | 16 |
Notes: Diners Club cards issued in the USA and Canada are processed on the MasterCard network, which is why their 54/55 prefixes overlap with MasterCard. The 622126-622925 range is UnionPay cards accepted on the Discover network. UnionPay numbers are not always Luhn valid in the wild, although the ones generated here are. The ranges evolve over time (MasterCard added the 2221-2720 series in 2017): always rely on your payment provider for production decisions.