Test data only. Local fixtures do not issue cards, verify accounts or provide payment authorization. Use them only in authorized tests. Why?
5 test cards
- Generated fields are not uploaded
- Randomly generated in your browser
- Every number passes the Luhn check
Test the edges of both Mastercard ranges
The tool starts on Mastercard and generates 16-digit numbers from the 51–55 and
2221–2720 ranges. A random batch can contain either range; it does not guarantee both
ranges or any boundary value. Use the fixed fixtures below to catch off-by-one errors,
then use fresh generated values to broaden your tests.
This page’s test target is range classification. The Mastercard format guide covers the network background; the examples here make eight boundary decisions reproducible.
Mastercard number format
For this local check, the input must be a 16-digit string. The first two digits must be 51 through 55, or the first four must be 2221 through 2720, including both endpoints. Cybersource’s identification reference lists the corresponding six-digit ranges as 510000–559999 and 222100–272099. This check identifies a shape; a real issuer lookup and payment authorization are separate.
The boundary tests it has to pass
Every number in this fixture set has a valid Luhn checksum. Even the four inputs outside the Mastercard ranges pass Luhn, so the classifier cannot accidentally pass the test by rejecting them for an unrelated checksum error.
| Card number | Boundary | Mastercard shape? |
|---|---|---|
| 2220000000000000 | below 2 series | Reject |
| 2221000000000009 | first 2 series | Accept |
| 2720000000000005 | last 2 series | Accept |
| 2721000000000004 | above 2 series | Reject |
| 5000000000000009 | below 5 series | Reject |
| 5100000000000008 | first 5 series | Accept |
| 5500000000000004 | last 5 series | Accept |
| 5600000000000003 | above 5 series | Reject |
The negative rows mean not in these Mastercard ranges. They do not claim that the number is assigned to another network or that an account exists. Keep those assertions out of a range test.
Run the range regression
Save the eight boundary fixtures and the runnable range checks in one directory:
node --test mastercard-boundaries.test.mjs
The file tests each endpoint, verifies every fixture’s checksum, and rejects incomplete or wrong-length inputs. Its classification function and case loop are shown below; imports and the fixture loader are in the download.
function isMastercardShape(number) {
if (typeof number !== 'string' || !/^\d{16}$/.test(number)) return false;
const firstTwo = Number(number.slice(0, 2));
const firstFour = Number(number.slice(0, 4));
return (firstTwo >= 51 && firstTwo <= 55) ||
(firstFour >= 2221 && firstFour <= 2720);
}
// A check digit must not hide an off-by-one error in the range check.
for (const row of fixture.cases) {
test(row.id, () => {
assert.equal(isMastercardShape(row.number), row.expectedMastercard);
});
}Replace isMastercardShape with your application’s complete-number classifier to run the
same fixtures against your code. The arithmetic on four digits avoids converting an entire
card number into a JavaScript numeric value.
Interpret a failed case
- 2221 and 2720 both fail: look for an older classifier that recognizes only
51–55. - 2221 fails but a middle 2-series value passes: check whether the lower bound uses
>instead of>=. - 2721 passes: look for an upper bound that is too wide, such as treating all
27as Mastercard. - 50 or 56 passes: a leading
5alone is too broad. Do not let a broad Maestro fallback decide a Mastercard-specific assertion.
The brand-detection guide explains how multiple network patterns interact. These tests deliberately isolate one network so a failure has one clear cause.
Test typing separately from completed input
A user typing 2, then 22, then 222 has not entered a complete card number. Keep the
field in an incomplete state rather than showing a final “invalid card” error on each
keystroke. Once the first four digits reach 2221, the UI can show a Mastercard candidate;
that still does not establish length, checksum or account validity.
Exercise 222 → 2220 → 2221 and 2720 → 2721, then backspace. Check both the brand icon and
validation message. The downloadable classifier intentionally returns false for incomplete
numbers; it is not an as-you-type state machine. Your form should distinguish “incomplete”
from “complete but rejected” before calling it.
Combine range and checksum tests without confusing them
After the range regression passes, generate a Mastercard here and change only its final digit. The mutated number should still match the Mastercard shape but fail Luhn. This is a second, independent assertion, available in the local card validator. Do not replace the range fixtures with random output: a large batch can still miss exactly the endpoint that broke.
For a saved test, record the number as a string, the expected range classification and the expected checksum result. You do not need a CVV or expiry to exercise this classifier.
Official Mastercard test numbers
A gateway may supply both 5-series and 2-series fixtures: for example, Stripe’s testing reference publishes a Mastercard 2-series case. That is useful for a processor integration, but it does not test every boundary in your own range logic. Gateway responses are simulated; these locally constructed fixtures are not registered sandbox credentials.
Use the provider test-card reference for that next layer. For defects that concern length or lost digits, use the Visa input tests; for a security-code field that behaves incorrectly after a brand switch, use the Amex form tests.