Test credit card numbers

Make test card numbers with a valid format for 7 card networks, and check any number with the Luhn algorithm. Free, no sign-up, and everything runs in your browser.

Card networks

Numbers to make, up to 1000

Output

Test card numbers

Making numbers...

Check a card number

Checks the format with the Luhn algorithm as you type. Nothing is sent anywhere.

What these test credit card numbers are for

This tool makes test credit card numbers: numbers with the right first digits, the right length and a correct check digit for Visa, Mastercard, American Express, Discover, JCB, Diners Club and UnionPay. Use them to test your own checkout form, input masks, card-type icons, validation messages, database fields and seed data without typing a real card.

The numbers are not real cards. They are random digits, not taken from any account, and they come with no real expiry date, security code or name, so they can't pay for anything. A random number can match a card that exists by chance, which is one more reason to use these numbers only in your own tests. A payment provider will decline them, also in its sandbox, because each sandbox accepts only its own list of test numbers. Adyen, for example, says its test card numbers work only on its test platform and not on others.4 So use this tool for everything in front of the payment request, and use your provider's published test cards for the payment itself.

Everything runs in your browser. The numbers come from the browser's secure random generator, and nothing you generate or check is sent anywhere.

How to use the generator

  1. Select one or more card networks. With more than one, the list takes turns between them.
  2. Set How many numbers you need, up to 1,000.
  3. Choose the output: plain text with one number per line, CSV, or JSON for fixtures and seed scripts.
  4. Turn on Add an expiry date and security code if your form needs all three fields. The date is a random month in the future and the code is 3 digits, or 4 for American Express.
  5. Select Copy all or Download. Generate again makes a new set.

To test a number, paste it into Check a card number. The checker shows if it passes the Luhn check, which network the first digits belong to, and the digit count. If the number fails, it tells you which check digit the other digits need, which usually points to a typo.

How the Luhn check works

The last digit of a card number is a check digit. It is computed from all the other digits with a method that Hans P. Luhn filed a patent for in 1954, where a single check digit is added at the right-hand end of a number so that a machine can verify it.2

To check a number by hand:

  1. Start at the last digit and move left. Double every second digit.
  2. If a doubled digit is more than 9, take off 9.
  3. Add all the digits together. If the total ends in 0, the number passes.

For 4242 4242 4242 4242, the doubled digits are the eight 4s, which become 8, and the eight 2s stay as they are: 64 + 16 = 80, so it passes. Change the last digit to 1 and the total is 79, so it fails. Stripe uses exactly that number, 4242 4242 4242 4241, as its test card for an "incorrect number" decline.1

The check catches a single wrong digit and most swaps of two neighboring digits. It is not security: anyone can compute a check digit, so a pass says only that the number is well formed.

Test numbers vs your payment provider's test cards

Use both, for different jobs:

  • Numbers from this tool fit client-side work: does the form accept 15 digits for American Express, does the card icon change, does your validation library reject a bad check digit, does a long UnionPay number fit in the column.
  • Provider test cards fit the payment flow. Stripe's test mode has cards such as 4242 4242 4242 4242 that work with any future expiry date and any 3-digit security code, and other numbers that simulate declines and errors.1 PayPal's sandbox has its own list and its own generator, and asks for a future expiry date and a 3-digit security code, or 4 digits for American Express.3

Never test with a real card, your own included. Stripe tells developers not to use real card details and notes that its Services Agreement prohibits testing in live mode with real payment method details.1

When you build the form itself, set the autocomplete values cc-number, cc-exp and cc-csc on the fields so that browsers can fill in a saved card.5 If your test plan also needs fake API keys or coupon codes, the random string generator makes those. Run the full payment flow with a small group of beta testers before launch day, because a broken checkout costs more than any other bug.

Frequently asked questions

Sources

  1. Stripe Docs: Testing

  2. Google Patents: US2950048A, Computer for verifying numbers (H. P. Luhn, filed 1954)

  3. PayPal Developer: Card testing

  4. Adyen Docs: Test card numbers

  5. MDN Web Docs: autocomplete HTML attribute