How to generate test credit card numbers
- Choose a Card brand: Visa, Mastercard, American Express, Discover, JCB, Diners Club or UnionPay.
- Set Count from 1 to 100 and pick a Format: plain digits, grouped with spaces (4-6-5 for American Express), number with expiry and CVV, or JSON.
- Press Generate, then Copy. Expiry dates fall 1 to 5 years ahead, and the CVV has 3 digits (4 for American Express).
- For a payment sandbox, copy one of the Stripe sandbox test cards instead, because random numbers are not accepted there.
- Paste any number into Check a card number to see whether it passes the Luhn check and which brand prefix it matches.
How the numbers are made
Each number is a brand prefix, random digits and a final check digit. The prefixes and lengths follow the ranges listed on Wikipedia's payment card number page:
- Visa: starts with 4, 16 digits generated.
- Mastercard: 51 to 55 or 2221 to 2720, 16 digits.
- American Express: 34 or 37, 15 digits.
- Discover: 6011, 644 to 649 or 65, 16 digits.
- JCB: 3528 to 3589, 16 digits. UnionPay: 62, 16 digits.
- Diners Club: 300 to 305, 36, 38 or 39, 14 digits.
The check digit comes from the Luhn algorithm. Starting at the rightmost digit before the check digit, double every second digit, subtract 9 from any result above 9, add everything up, and the check digit is (10 minus the sum mod 10) mod 10. A full number passes when its total, with the check digit included, is a multiple of 10.
Worked example with the default checker input
The checker starts with 4242 4242 4242 4242. From the right, the doubled digits are the eight 4s, which become 8 each: 8 x 8 = 64. The eight 2s stay as they are: 8 x 2 = 16. The total is 80, a multiple of 10, so the tool says it passes and the prefix matches Visa. Change the last digit to 1 and the total becomes 79, so the checker reports that the last digit would have to be 2.
Limits and edge cases
Luhn only catches typing mistakes: every single wrong digit and most swapped neighbors, though not 09 and 90. It says nothing about whether an account exists, has funds or will be approved. A few real issuers sit outside the published prefix and length ranges, and not every UnionPay card uses Luhn, but the numbers made here always do. Use these numbers to test form validation and brand detection, and pair them with a fake billing address, a fake customer profile or JSON from the mock API generator.
Frequently asked questions
Are these credit card numbers real?
No. They are random numbers with a real brand prefix and a valid check digit, so they pass format checks. No bank issued them and no account is attached, so a real processor will decline them.
Will a generated number work in Stripe test mode?
No. Stripe test mode accepts only the card numbers Stripe publishes, such as 4242 4242 4242 4242. Any other number, even one that passes the Luhn check, is rejected. Use the Stripe sandbox list on this page.
What expiry date and CVC do I use with test cards?
Use any future expiry date, any 3-digit CVC (4 digits for American Express) and any postal code. With Stripe's test cards, the card number alone decides whether the payment succeeds or is declined.
Why does a number pass the Luhn check but still get declined?
The Luhn check only catches typing mistakes. Approval depends on the issuer having a matching open account with funds, which a generated number never has.
Sources: Stripe, Test your integration; Payment card number; Luhn algorithm; Baymard Institute, card number spacing patterns.