Developer Tools
Credit Card Number Validator | Luhn Algorithm & Brand Detection
Enter a credit card number to verify its check digit with the Luhn algorithm and automatically detect the brand (Visa, Mastercard, Amex, etc.). Handy for testing form validation.
[[ labels.client_side_note ]]
[[ labels.result_label ]]
| [[ labels.formatted_label ]] | [[ result.formatted ]] |
|---|---|
| [[ labels.brand_label ]] | [[ brandName ]] [[ labels.brand_unknown ]] |
| [[ labels.checksum_label ]] | ✓ [[ labels.checksum_valid ]] ✗ [[ labels.checksum_invalid ]] |
Supported Brands and Detection Rules (IIN & Length)
| Brand | Leading Digits (IIN) | Length |
|---|---|---|
| Visa | 4 | 13, 16, 19 |
| Mastercard | 51–55, 2221–2720 | 16 |
| American Express | 34, 37 | 15 |
| Discover | 6011, 65 | 16 |
| JCB | 3528–3589 | 16 |
| Diners Club | 300–305, 36, 38 | 14 |
| UnionPay | 62 | 16–19 |
Tips
- Try the sample buttons for well-known test numbers (e.g. Visa: 4111 1111 1111 1111) instead of a real card number.
- Spaces and hyphens are stripped automatically, so you can paste a number copied from anywhere.
- This tool only checks the format via the Luhn algorithm. For real authorization or balance checks, use your payment processor's API.
- When building form validation, use this tool to generate both a passing case and a failing case to test your logic.
Frequently Asked Questions
Side Note — Hans Peter Luhn, the Father of the Check Digit
The check digit at the end of a credit card number is verified using an algorithm devised in 1954 by IBM engineer Hans Peter Luhn. He was awarded a patent for it in 1960, but the patent has long since expired, so the algorithm is now free for anyone to use.
The mechanism is surprisingly simple. Starting from the rightmost digit, every second digit is doubled; if the result is two digits, they are added together (e.g. 8×2=16 → 1+6=7). If the sum of all digits is a multiple of 10, the number is considered formally valid.
The algorithm is used well beyond credit cards — it also catches typos in IMEI numbers (used to identify smartphones) and Canadian Social Insurance Numbers, among others. It is worth remembering that Luhn only detects accidental mistypes; it says nothing about whether the card actually exists or has any balance.
The first 6 to 8 digits of a card number form the Issuer Identification Number (IIN), which identifies the card network and issuing bank. This tool's brand detection is based on the publicly documented IIN ranges for each network.