Skip to content
Buy me a coffee
Validators

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

Spaces and dashes are ignored. The number is checked in your browser with the Luhn algorithm and is never sent to a server.
Try:
Ctrl + Enter

Fake credit card numbers for all major brands

These numbers DO NOT work. They are for testing only.

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

Falls back to the default when the issuer does not use that length.
The result appears in the panel above

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

  1. Drop the last digit of the number: this is the check digit you want to verify.
  2. Reverse the remaining digits.
  3. Multiply the digits in odd positions (1st, 3rd, 5th... of the reversed number) by 2.
  4. If a product is greater than 9, subtract 9 from it (equivalent to adding its two digits together).
  5. Add all the resulting digits together.
  6. 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 number4556737586899855
Drop the last digit455673758689985
Reverse the digits589986857376554
Multiply odd positions by 21081891661651431461058
Subtract 9 from numbers over 9189976755356158
Add all numbers1 + 8 + 9 + 9 + 7 + 6 + 7 + 5 + 5 + 3 + 5 + 6 + 1 + 5 + 8 = 85
Mod 1085 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.

IssuerStarts with (IIN range)Length
American Express34, 3715
Diners Club - Carte Blanche300-30514
Diners Club - International3614
Diners Club - USA & Canada54, 5516
Discover6011, 622126-622925, 644-649, 6516-19
InstaPayment637-63916
JCB3528-358916-19
Maestro5018, 5020, 5038, 5893, 6304, 6759, 6761, 6762, 676316-19
MasterCard51-55, 222100-27209916
Visa413, 16, 19
Visa Electron4026, 417500, 4508, 4844, 4913, 491716
UnionPay6216-19
Mir2200-220416

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.