Test Credit Card Generator

Generate fake, Luhn-valid Visa, Mastercard, Amex and Discover numbers with the right prefix and length, plus a future expiry and CVV for form testing.

The interactive tool loads here when JavaScript runs.

About this tool

What is the Test Credit Card Generator?

This generator makes fake card numbers for testing forms and validation code. Pick Visa, Mastercard, American Express or Discover and click Generate Test Card to get a number with that brand's real prefix and length, a valid Luhn check digit, a random expiry one to five years ahead and a CVV of the right length (four digits for Amex, three for the rest).

These numbers are for testing only. They are not issued to any account, they carry no money, and a live payment processor will decline them. Their job is to get past client-side checks so you can test how your form, formatter or card-type detection behaves.

Numbers are generated in your browser and are not stored or sent anywhere. A short list of the well-known published test numbers is shown under the generator for quick reference.

  • Visa, Mastercard (51-55 and 2-series), Amex and Discover
  • Correct prefixes and lengths with a Luhn check digit
  • Future expiry date and brand-correct CVV length
  • Click-to-copy number, expiry and CVV
  • Generated locally; nothing is stored
Read the guide: Test Credit Card Generator Guide: Complete Payment Testing for Developers

Updated

How to use the Test Credit Card Generator

  1. Choose a brand in the Card Type menu.
  2. Click Generate Test Card.
  3. Click the number, expiry or CVV on the card preview to copy that field, or use Copy Number, Copy Expiry and Copy CVV.
  4. Paste the values into the form you are testing.

Worked examples

Working out a Luhn check digit

Input

Partial number 7992739871

Output

Check digit 3, full number 79927398713

Doubling every second digit from the right and summing gives 67; adding 3 makes 70, a multiple of 10. This is the textbook example used to explain the algorithm.

Amex grouping

Input

American Express

Output

3782 822463 10005 (4-6-5)

Amex prints 15 digits in groups of 4, 6 and 5; the generator formats them that way, while 16-digit cards use four groups of four.

Background and insight

A card number (PAN) has three parts under ISO/IEC 7812: an issuer identification number (IIN, the first six or eight digits), an account number, and a final check digit. The leading digits identify the network. Visa starts with 4. Mastercard uses 51 to 55 and, since 2017, 2221 to 2720. American Express uses 34 and 37 with 15 digits. Discover uses 6011, 644 to 649 and 65. The generator picks from those ranges, so brand-detection code sees realistic prefixes.

The check digit comes from the Luhn algorithm, patented by IBM scientist Hans Peter Luhn in 1960. Starting from the rightmost digit, double every second digit, subtract 9 from any result over 9, and add everything up. The total must be a multiple of 10. Luhn catches every single-digit typo and most adjacent swaps, which is why card forms run it before contacting the server, but it is not a security feature: anyone can compute a valid check digit.

For anything beyond form validation, use your payment provider's sandbox and its own documented test numbers. Stripe, Braintree and Adyen each publish numbers that trigger specific outcomes such as declines, 3-D Secure challenges or insufficient funds.

Common use cases

  • Checkout form QA

    Check that input masks, length limits and Luhn validation accept good numbers and reject typos.

  • Card brand detection

    Confirm your UI shows the right logo for 2-series Mastercard and 34-prefix Amex numbers, which older regexes miss.

  • Demo and staging data

    Fill demo screenshots and seeded accounts with numbers that look real but cannot be charged.

  • Teaching validation

    Show how a Luhn check digit works with numbers you can generate on the spot.

Tips and limitations

  • These numbers will be declined by real processors and by most sandboxes too. For end-to-end payment tests, use the provider's own test card list.
  • Never test with a real card number, including your own. Card data in logs or test databases brings PCI DSS scope with it.
  • Expiry dates are always in the future, and the CVV is random. Most sandboxes accept any future expiry and any CVV of the right length.
  • Some Mastercard and Discover ranges are shared with co-branded or regional networks, so a BIN lookup service may report a different issuer for a generated number.

Sources and further reading

  1. ISO/IEC 7812-1:2017 Identification cards: Identification of issuers, Part 1: Numbering system, International Organization for Standardization. The IIN and PAN structure
  2. US2950048A: Computer for verifying numbers, Google Patents. Hans Peter Luhn's patent for the check-digit method
  3. Test card numbers, Stripe. Sandbox numbers that trigger declines and 3-D Secure

Frequently asked questions

Are these test credit card numbers real?

No. They follow the format rules (prefix, length and Luhn check digit) but are not issued to any account, have no money behind them, and will be declined by a live processor. They are fake numbers for testing form validation and UI logic only.

Can I use a generated card number to buy something?

No. A purchase needs an account that a bank has issued, and authorisation checks the number, expiry and CVV against that account. These numbers have no account, so every real payment attempt fails. Using fake card details to obtain goods is also fraud.

Which test card numbers work in Stripe?

Use the numbers in Stripe's own testing documentation, such as 4242 4242 4242 4242 with any future expiry and any CVC. Stripe's test mode only recognises its published numbers, so randomly generated ones will be declined even though they pass Luhn.

How does the Luhn check work on a card number?

From the rightmost digit, double every second digit, subtract 9 from results above 9, and add all the digits. If the total is a multiple of 10 the number passes. It catches single-digit typos and most swapped pairs, but it offers no security.

What prefixes do Mastercard numbers start with?

Mastercard numbers start with 51 to 55 or, since 2017, with 2221 to 2720. Both are 16 digits long. Card-type detection that only checks for a leading 5 will miss the 2-series range, which is why the generator produces both.

Why does an Amex number have 15 digits and a 4-digit code?

American Express uses 15-digit numbers starting with 34 or 37, grouped 4-6-5, and prints a four-digit card identification number on the front instead of a three-digit code on the back. Forms that hard-code 16 digits and a 3-digit CVV reject valid Amex cards.

Is there an in-depth guide to the Test Credit Card Generator?

Yes. “Test Credit Card Generator Guide: Complete Payment Testing for Developers” covers the background, how it works, common pitfalls and worked examples. Read the full guide.