UseToolSuite UseToolSuite

Test Card Number Generator

Generate Luhn-valid dummy card numbers for testing checkouts, payment sandboxes, and form validation. Test data only — not for real transactions.

Luhn-valid test numbers Visa, Mastercard, Amex, Discover For testing only — no real funds Runs entirely in your browser

Test data only. These are not real card numbers. They are digit strings computed to satisfy the Luhn checksum so that payment forms accept them during development — no bank, no account and no funds sit behind any of them, and none can authorise a purchase. For end-to-end gateway testing use your provider's official sandbox cards.

Generated Test Data

Provider Card Number Expiry CVV
Copied!

What is the Luhn Algorithm?

Luhn is a check digit scheme — a way of reserving the last digit of a number to describe all the digits before it. Hans Peter Luhn patented it at IBM in the 1950s to catch the errors humans actually make when copying long numbers by hand: a mistyped digit, or two adjacent digits swapped. Both change the checksum, so both get rejected instantly without asking anyone. Card networks adopted it, and so did IMEI numbers and several national ID formats, which is why "mod 10" shows up far outside payments. It is worth being precise about what that buys you: Luhn proves a number is well-formed, not that it exists or has money behind it. It is a typo filter, not a security control, and it was never designed to resist anyone deliberately constructing a number.

This generator runs the check in reverse. It picks the issuer prefix for the network you chose, fills the middle with random digits, then computes the one final digit that makes the whole string satisfy the checksum. The result is a number your form's validation will accept and nothing else will.

Why do developers need this?

When building e-commerce websites or integrating payment gateways (like Stripe, PayPal, or Adyen), developers need to test their checkout flows. If they enter random numbers like "1234 5678", the frontend validation logic (or library like Formik/React-Hook-Form) will immediately throw an error because the number fails the local Luhn check, long before it even reaches the server. This tool produces numbers that satisfy that client-side check, so the request actually reaches the server and you can test the integration logic itself in your provider's sandbox.

How prefixes determine card networks

The first few digits of a credit card determine its Major Industry Identifier (MII) and Issuer Identification Number (IIN). For example, all Visa cards start with a 4. MasterCards typically start with 51-55. American Express cards start with 34 or 37, and Discover cards often start with 6011. The generated numbers strictly respect these standardized prefixes and length requirements (e.g., Amex is 15 digits, Visa is 16).

What these numbers are (and aren’t)

This generator produces Luhn-valid dummy card numbers for the legitimate, everyday developer task of testing checkout forms and payment integrations. Each number passes the mod-10 checksum and carries the correct issuer prefix (IIN/BIN) and length for the chosen network, so your form’s validation, formatting, and card-type detection all behave as they would for a real card. What they are not: connected to any bank, account, or funds. They cannot be used for a real transaction — there’s nothing behind them but math.

Network formats differ — test for that

Card structures are governed by ISO/IEC 7812, and the differences are exactly what your code must handle:

NetworkPrefixLengthCVV
Visa4163 digits
Mastercard51–55 / 2221–2720163 digits
Amex34, 37154 digits
Discover6011, 65163 digits

The Amex row is the one that breaks naive forms — 15 digits and a 4-digit CVV instead of the usual 16/3. Generating Amex test numbers lets you confirm your validation and input masks handle the irregular case.

Legitimate uses only

To be explicit: this tool exists for developers testing their own systems — validating form logic, exercising card-type detection, populating staging databases, and load-testing fraud heuristics. The numbers have no monetary value and can’t authorize a purchase. For end-to-end payment-flow testing, always use your gateway’s official sandbox test cards (Stripe, PayPal, etc. each publish theirs), since only those trigger the mock approval/decline responses.

How Luhn works, briefly

Walking the digits right to left, double every second digit (subtracting 9 if the result exceeds 9), sum everything, and a valid number’s total is a multiple of 10. That’s the entire check — which is why editing a single digit of a generated number breaks it: the final check digit is computed from all the others. For other realistic test data (names, emails, addresses) to accompany these, see the Mock JSON Data Generator.

Test Card Number Generator creates what you need on the spot — no account, no sign-up, no server round-trip. It's one of the free Generator Tools on UseToolSuite.

Last updated

How to Use This Tool

  1. 1

    Pick a card network

    Choose Visa, Mastercard, Amex, or Discover so the number starts with the right prefix and length.

  2. 2

    Generate

    A random number is produced that passes the Luhn check payment forms expect, along with a dummy expiry and CVV.

  3. 3

    Use it in your tests

    Drop the number into a checkout form, a staging gateway, or a mock database to test validation.

How helpful was this tool?

Click to rate

Embed this tool on your site

Paste this snippet into any HTML page or blog post to embed a live, fully working copy of Test Card Number Generator. Free for any use.

Key Concepts

Luhn check (mod 10)

The checksum every card number satisfies, used by forms to catch mistyped numbers instantly without going to the bank.

Card prefix (BIN/IIN)

The first few digits, which identify the network and issuer — 4 for Visa, 34/37 for Amex, and so on. They set the format of a valid test number.

CVV

The short security code on a card — 3 digits for most networks, 4 for American Express. The dummy value here is only to fill a test form.

Frequently Asked Questions

Can these numbers actually buy anything?

No. They only pass the format and checksum that forms validate — there is no bank, no balance, and no authorization behind them. A real payment processor will decline them. They exist purely to test that your form and validation logic behave correctly.

What is the Luhn check these pass?

A simple formula that every card number satisfies: double every second digit, add everything up, and the total is a multiple of 10. Payment forms use it to catch typos before contacting the bank, so valid test numbers must satisfy it too.

Why are Amex numbers a different length?

Card formats are set by an ISO standard. Visa and Mastercard use 16 digits with a 3-digit CVV; American Express uses 15 digits with a 4-digit CVV. Testing both makes sure your checkout is not hard-coded to 16 digits.

Why does this card pass validation but fail in Stripe's (or another gateway's) test mode?

Because there are two different checks, and these numbers only pass the first. A number generated here is Luhn-valid — it satisfies the mathematical checksum that front-end forms and basic validators use, so it passes 'is this a structurally plausible card number?' But a payment gateway's SANDBOX (Stripe, Braintree, Adyen, PayPal) recognizes its OWN specific hardcoded test numbers — like Stripe's 4242 4242 4242 4242 — which are wired into its mock authorization system to simulate approvals, declines, and specific error scenarios. A random Luhn-valid number isn't in that list, so the gateway's test environment declines it. The rule: use THESE numbers to test your own form validation and field handling; use the GATEWAY'S documented test cards to test the actual payment flow through their sandbox.

What is the Luhn check actually protecting against?

Accidental transcription errors, not fraud. The Luhn algorithm (also called mod 10) is a simple checksum that catches the common mistakes humans make typing a long number: a single mistyped digit, or two adjacent digits swapped (a transposition). When you enter a card number, the form runs Luhn to instantly reject obvious typos before sending anything to the payment processor — saving a round-trip and giving immediate feedback. What it does NOT do is verify the card exists, has funds, or belongs to anyone; it's purely a structural sanity check. That's why a Luhn-valid number is meaningless as 'a working card' — it just means the digits form a self-consistent sequence. Real authorization requires the issuing bank, which these test numbers have no connection to.

Troubleshooting & Technical Tips

A payment sandbox rejects the generated card

Processors like Stripe and Braintree only accept their own specific published test numbers in their sandboxes. Use those for gateway testing; use these generated numbers for your own form-validation and Luhn checks.

The number fails validation after I edited it

Changing any digit breaks the Luhn checksum, because the last digit is calculated from all the others. Generate a fresh number rather than editing one.

Related Tools