How Card Numbers Work: The Luhn Check and the Network Prefixes
How the Luhn formula catches typing errors in card numbers, how the first digits identify UnionPay, Visa and Mastercard, and how to test safely.

How Card Numbers Work
A payment card number is not random. Its first digits show who issued it, and its last digit is a check digit that lets a form detect typing mistakes immediately. The Payment Card Number Validator shows both.
The parts of a number
The first digit is the major industry identifier: 3 for travel and entertainment cards, 4 and 5 for banking, 6 for merchandising and banking. The first six digits are the issuer identification number, which names the network and the bank. The following digits identify the account, and the last digit is the check digit. The total length is from 13 to 19 digits. Visa cards usually have 16, American Express has 15, and UnionPay cards have 16 to 19.
The network prefixes
UnionPay numbers start with 62. Visa numbers start with 4. Mastercard numbers start with 51 to 55, and since 2017 also with 2221 to 2720. American Express numbers start with 34 or 37. JCB numbers start with 3528 to 3589. The tool applies these rules in order and shows the network. Many other networks and local schemes exist, and the tool then says other or unknown.
The Luhn formula
Hans Peter Luhn designed the check in the 1950s to catch simple mistakes. Starting from the right, leave the check digit as it is, double the next digit, leave the next, double the next, and so on. If a doubled digit is greater than 9, subtract 9. Add all the digits. If the total is a multiple of 10, the number passes. A single wrong digit will fail, and a swap of two neighbouring digits fails in nearly all cases. The formula is also used for many other identifiers, such as health provider numbers.
What the check cannot do
Luhn is not a security measure. Anyone can make a number that passes, and a card thief only needs a valid number to try. Passing says nothing about whether a card exists, whether it has funds or whether it belongs to a person. Only the bank can tell that.
Testing safely
Use published test numbers when you build or test a payment form. 4111 1111 1111 1111 is a well-known Visa test number, 5555 5555 5555 4444 is a Mastercard test number and 3782 822463 10005 is an American Express test number. 6200000000000005 can be used as a UnionPay-type test number. Do not enter real card numbers into tools you do not control. This tool runs in your browser and sends nothing, but test numbers are the habit to keep.
Using the validator
Paste one number per line. Spaces and hyphens are removed. A valid number is shown in groups of four with the network, the length and the first six digits. A failed line explains whether the characters, the length or the check digit is wrong.
A worked example
6200000000000005 passes, and the network is UnionPay. Changing the last digit to 6 makes the total fail the multiple-of-10 test. A number with four digits fails because of its length.
Limits
This is a technical check and not financial advice.
For developers
Validate card numbers on the client for fast feedback, but never rely on it for security. Let the payment provider handle the card data through its hosted fields, so that numbers do not touch your servers. Show the network icon while the user types, using the prefix rules. Accept spaces and hyphens, and reject letters. Always follow the payment card industry rules for storing and sending card data.
Card security basics
A card number is only one of the details a thief needs, but it is the start of many scams. Never read your full number, expiry date and security code to a caller, and be careful with links in messages that ask for them. Use virtual card numbers or mobile wallets when you pay online, if your bank offers them.



