The four parts of a card number
A payment card number — officially the primary account number or PAN — is defined by the international standard ISO/IEC 7812. It is between 8 and 19 digits long, although almost every card in use has 15, 16 or 19 digits. Every PAN is made of four parts:
- Major Industry Identifier (MII) — the first digit. It names the industry of the issuer: 4 and 5 are banking and finance, 3 is travel and entertainment, 6 is merchandising and banking.
- Issuer Identification Number (IIN) — the first six or eight digits, also called the BIN (bank identification number). It identifies the card network and the bank that issued the card, and often the card type (credit, debit, prepaid), level and country. Since 2022 the standard uses 8-digit IINs, so systems should no longer assume 6.
- Account identifier — the digits between the IIN and the last digit, chosen by the issuer for the individual card. It is not your bank account number.
- Check digit — the last digit, calculated from all the others with the Luhn algorithm. It lets a form catch typos before the payment is sent.
Card number format by brand
The prefix (IIN range) tells you the brand, and the brand tells you the allowed lengths, the usual grouping and the type of security code:
| Brand | Starts with | Length | Grouping | Security code |
|---|---|---|---|---|
| Visa | 4 | 13, 16, 19 | 4-4-4-4 | CVV2 · 3 digits, back |
| Mastercard | 51–55, 2221–2720 | 16 | 4-4-4-4 | CVC2 · 3 digits, back |
| American Express | 34, 37 | 15 | 4-6-5 | CID · 4 digits, front |
| Discover | 6011, 644–649, 65 | 16–19 | 4-4-4-4 | CID · 3 digits, back |
| JCB | 3528–3589 | 16–19 | 4-4-4-4 | CAV2 · 3 digits, back |
| Diners Club | 300–305, 36, 38–39 | 14–19 | 4-6-4 (14 digits) | 3 digits, back |
| UnionPay | 62 | 16–19 | 4-4-4-4 | CVN2 · 3 digits, back |
| Maestro | 5018, 5020, 5038, 5893, 6304, 6759, 6761–6763 | 12–19 | varies (4-4-4-4 for 16) | 3 digits, back (optional on some) |
Other domestic schemes follow the same rules with their own prefixes, for example Mir in Russia (2200–2204) and RuPay in India (mostly 60, 65, 81, 82 and 508). Ranges overlap in places: 622126–622925 is both UnionPay and Discover, and some Maestro ranges sit inside the 5 and 6 ranges. Check the more specific prefix first.
JCB credit card number format
JCB numbers start with 3528 to 3589 and have 16 digits, grouped 4-4-4-4 like 3530 1113 3330 0000 (a Braintree test number). The scheme allows up to 19 digits. The last digit is a Luhn check digit and the three-digit security code, called CAV2, is on the back. Because JCB numbers begin with 35, a validator that treats every number starting with 3 as American Express (15 digits, 4-digit code) rejects them — one of the most common card validation bugs. In the US, JCB cards are processed on the Discover network.
Validation patterns (regex)
These regular expressions check the prefix and length of a number with spaces and dashes removed. Use them together with the Luhn check:
| Brand | Pattern |
|---|---|
| Visa | ^4[0-9]{12}(?:[0-9]{3}){0,2}$ |
| Mastercard | ^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$ |
| American Express | ^3[47][0-9]{13}$ |
| Discover | ^(?:6011|64[4-9][0-9]|65[0-9]{2})[0-9]{12,15}$ |
| JCB | ^35(?:2[89]|[3-8][0-9])[0-9]{12,15}$ |
| Diners Club | ^3(?:0[0-5]|[689][0-9])[0-9]{11,16}$ |
| UnionPay | ^62[0-9]{14,17}$ |
| Maestro | ^(?:5018|5020|5038|5893|6304|6759|676[1-3])[0-9]{8,15}$ |
Spacing and display rules
- Display in groups. 16-digit cards are printed in four groups of four. American Express uses 4-6-5 (
3782 822463 10005) and 14-digit Diners Club cards 4-6-4. Grouping helps people compare what they typed with the card. - Accept any spacing. Let users type spaces or dashes and remove them before validating. Don’t block paste.
- Store digits only, never with formatting — and only if you are allowed to store card numbers at all. Most sites let the payment gateway store them and keep a token instead.
- Mask when displaying. PCI DSS allows at most the BIN and the last four digits to be shown, for example
4111 11•• •••• 1111. Receipts usually show only the last four. - Use the right input attributes.
inputmode="numeric"shows a number keypad on phones andautocomplete="cc-number"lets the browser fill the card in.
Expiry date format
The expiry date is printed as MM/YY, for example 08/29. The card is valid until the last day of that month. Payment APIs usually take the month and a four-digit year as separate fields, so your form should convert 08/29 to month 8 and year 2029. Reject months outside 01–12 and dates in the past, and allow dates up to about 20 years ahead.
CVV, CVC and CID formats
The card security code has a different name for each brand but the same purpose: proving that the person paying has the physical card. It is not derived from the card number by any public formula.
- 3 digits on the back for Visa (CVV2), Mastercard (CVC2), Discover (CID), JCB (CAV2), UnionPay (CVN2) and Diners Club.
- 4 digits on the front for American Express (CID), above the card number.
- Some Maestro and debit cards have no code at all, so a form should not always require one.
PCI DSS forbids merchants from storing the security code after authorization, even encrypted. In test data, a random code of the right length is all you need.
Major Industry Identifier values
| First digit | Industry |
|---|---|
| 0 | ISO/TC 68 and other industry assignments |
| 1 | Airlines |
| 2 | Airlines, financial and future industry assignments (Mastercard 2-series) |
| 3 | Travel and entertainment (American Express, Diners Club, JCB) |
| 4 | Banking and financial (Visa) |
| 5 | Banking and financial (Mastercard, Maestro) |
| 6 | Merchandising and banking (Discover, UnionPay, Maestro) |
| 7 | Petroleum and other future industry assignments |
| 8 | Healthcare, telecommunications and other future industry assignments |
| 9 | Assignment by national standards bodies |
Frequently asked questions
How many digits does a credit card number have?
Usually 16. American Express uses 15, most Diners Club cards 14, and Visa, Discover, JCB, UnionPay and Maestro allow up to 19. The international standard allows 8 to 19 digits.
What is the format of a JCB card number?
16 digits starting with 3528 to 3589, shown in four groups of four (for example 3530 1113 3330 0000). JCB allows up to 19 digits. The last digit is a Luhn check digit, and the 3-digit CAV2 code is on the back.
What do the first digits of a card number mean?
The first digit is the Major Industry Identifier. The first six to eight digits are the Issuer Identification Number (IIN or BIN): they identify the network and the issuing bank.
Is the CVV part of the card number?
No. The CVV is printed separately and can’t be calculated from the card number. Merchants must not store it after authorization.
What format is the expiry date?
MM/YY on the card, for example 08/29. The card is valid until the last day of that month. Payment APIs usually take the month and a 4-digit year as separate fields.