PAYMENT ARCHITECTURE & FINTECH#06 • ISO/IEC 7812 Standard

Those 16 Digits on Your Card Tell a Complete Story: System Design & The Luhn Algorithm.

Card numbers are not randomly generated strings. Each digit carries specific architectural information used by global payment switches, issuing banks, and point-of-sale terminals. Here is a practical breakdown of MII networks, BIN layers, customer account references, the Luhn checksum, and CVV cryptography.

By Shyam KumarApr 15, 20268 min read
#Fintech#SystemDesign#LuhnAlgorithm#PaymentGateway
01 / THE ARCHITECTURAL BLUEPRINT

Card Number = Smart Engineering, Not Random Luck

When you look at your debit or credit card, the 16 digits printed across the front may seem like a random number generated by a database sequencer. In reality, credit card numbering is governed by an international standard: ISO/IEC 7812.

“A card number is not randomly generated. Every single digit carries specific information used by global payment routing switches, issuing banks, and security protocols.”

Before your transaction even touches a bank server, point-of-sale systems and payment gateways inspect these digits to know which network to route through, which bank issued the card, whether the card is credit or debit, and if the user simply made a typo.
Visual Graphic: The 16-Digit Card Anatomy
Click segment to highlight
DEBIT / CREDIT
4539672198765430
Card Holder
SHYAM KUMAR
Expires
12/26
VISA
1st Digit: 4
Major Industry Identifier (MII) - Visa
Digits 1–6: 453967
Bank Identification Number (BIN)
Digits 7–15: 219876543
Unique Customer Account ID
16th Digit: 0
Luhn Check Digit Validation
02 / HIERARCHICAL STRUCTURE

Card Number Architecture (Every Digit Has a Purpose)

Payment card numbers usually range from 15 to 19 digits (with 16 digits being the global standard for Visa, Mastercard, and RuPay). The architecture is split into 4 distinct layers:

┌── ISO/IEC 7812 CARD DIGIT ANATOMY ──────────────────────────────┐
4 5 3 9 6 7 8 9 1 2 3 4 5 6 7 8
│
├── First Digit (1st) → Card Network (MII)
│
├── First 6 Digits (1st to 6th) → Bank / Issuer Identification (BIN / IIN)
│
├── Middle Digits (7th to 15th) → Customer Account Identifier
│
└── Last Digit (16th) → Validation Checksum (Luhn Check Digit)
└─────────────────────────────────────────────────────────────────┘

Let's dissect each of these 4 components in detail to understand how payment processors use them in real-time.

03 / FIRST DIGIT

What is MII (Major Industry Identifier)?

The very first digit of a card number is known as the Major Industry Identifier (MII). It immediately tells the payment terminal or online checkout page which industry category and network family the card belongs to.

4
VISA
Banking & Financial
Global Switch
5
MASTERCARD
Banking & Financial (51–55, 22–27)
Global Switch
6
RUPAY / DISCOVER
Merchandising & Banking
NPCI Switch
3
AMERICAN EXPRESS
Travel & Entertainment (34, 37)
Closed Loop
Other ISO 7812 Categories: Digit 1 & 2 represent Airlines; Digit 7 represents Petroleum; Digit 8 represents Healthcare and Telecommunications; Digit 9 is reserved for National assignment.
04 / DIGITS 1 TO 6

BIN / IIN: The Card Identity Layer

The first 6 digits (and recently expanded to the first 8 digits under the latest ISO update) form the Bank Identification Number (BIN), also called the Issuer Identification Number (IIN).

What Does the BIN Reveal to Payment Gateways?

🏦 Issuing Bank
Identifies exact issuing institution (e.g., HDFC Bank, SBI, ICICI, Chase, HSBC).
💳 Card Type & Tier
Specifies whether the card is Credit, Debit, Prepaid, Platinum, Commercial, or Corporate.
🌍 Country & Currency
Geographical origin of the card for fraud profiling, 3D Secure triggers, and FX conversion.
⚖️ Routing & Interchange
Determines domestic vs. international transaction fees, interchange rates, and velocity checks.
05 / DIGITS 7 TO 15

Middle Digits: Individual Customer Account Reference

Digits 7 through 15 represent the customer's specific account identifier. These digits are assigned exclusively by the issuing bank (not the card network like Visa or Mastercard).

Key Properties of Account Digits:

  • •Uniquely identifies the cardholder: Differentiates your card from millions of other cards issued by the exact same bank.
  • •Linked internally to bank records: Maps internally to your core banking account (savings, checking) or credit line ledger.
  • •Generated by the Issuer (Bank), NOT the Network: Visa and Mastercard do not assign these digits; the bank's card-issuing software generates them.
  • •Zero meaning outside the issuing bank: To an outside observer or merchant, these numbers are opaque and meaningless without the bank's internal database.
06 / 16TH DIGIT VALIDATION

Luhn Check Digit: Fast Math to Catch Human Typos

The last digit (the 16th digit on a 16-digit card) is NOT part of your account number. It is a mathematical validation checksum calculated using the Luhn Algorithm (also known as the “Modulus 10” or “Mod 10” algorithm), created by IBM scientist Hans Peter Luhn in 1954.

How the Luhn Algorithm Works (In Short):

  1. 1. Start from the rightmost digit, excluding the last check digit.
  2. 2. Double every second digit moving leftward.
  3. 3. If doubling results in a number > 9, add its digits (e.g., 14 → 1+4 = 5).
  4. 4. Sum all final numbers together.
  5. 5. If (Total + Check Digit) % 10 == 0, the card number is mathematically valid!
Step-by-Step Calculation Example (from PDF)
Step 1: First 15 digits (excluding final check digit)
4   5   3   9   6   7   2   1   9   8   7   6   5   4   3
Step 2: Double every second digit from the right
(4, 10, 3, 18, 6, 14, 2, 2, 9, 16, 7, 12, 5, 8, 3)
Step 3: If result > 9, add its digits
• 10 → 1 + 0 = 1
• 18 → 1 + 8 = 9
• 14 → 1 + 4 = 5
• 16 → 1 + 6 = 7
• 12 → 1 + 2 = 3
Step 4: Add all final single-digit numbers
4 + 1 + 3 + 9 + 6 + 5 + 2 + 2 + 9 + 7 + 7 + 6 + 5 + 8 + 3 = 77
Step 5: Find the next multiple of 10
Next multiple of 10 after 77 is 80.
Calculation: 80 - 77 = 3
✓ Check Digit (Last Digit) = 3

Production Implementation: Luhn Algorithm in Java

LuhnValidator.java(Java 17+)
/**
 * Production-ready Luhn Check Digit Algorithm in Java
 * Verifies standard ISO/IEC 7812 payment card numbers
 */
public class LuhnValidator {

    public static boolean isValidCardNumber(String cardNumber) {
        if (cardNumber == null || cardNumber.length() < 13 || cardNumber.length() > 19) {
            return false;
        }

        // Remove optional spaces or dashes
        String cleanNumber = cardNumber.replaceAll("[^0-9]", "");
        int sum = 0;
        boolean alternate = false;

        // Process digits from right to left
        for (int i = cleanNumber.length() - 1; i >= 0; i--) {
            int n = Character.getNumericValue(cleanNumber.charAt(i));

            if (alternate) {
                n *= 2;
                if (n > 9) {
                    // Equivalent to adding digits: e.g. 16 -> 1+6 = 7 or (16 - 9 = 7)
                    n = (n % 10) + 1;
                }
            }

            sum += n;
            alternate = !alternate;
        }

        // If total sum is divisible by 10, the card number is mathematically valid
        return (sum % 10 == 0);
    }

    public static int calculateCheckDigit(String numberWithoutCheckDigit) {
        String clean = numberWithoutCheckDigit.replaceAll("[^0-9]", "");
        int sum = 0;
        boolean alternate = true; // In calculating check digit, first digit from right doubles

        for (int i = clean.length() - 1; i >= 0; i--) {
            int n = Character.getNumericValue(clean.charAt(i));
            if (alternate) {
                n *= 2;
                if (n > 9) n = (n % 10) + 1;
            }
            sum += n;
            alternate = !alternate;
        }

        int remainder = sum % 10;
        return (remainder == 0) ? 0 : (10 - remainder);
    }

    public static void main(String[] args) {
        // Example from architecture breakdown:
        String testCard = "4539672198765430";
        System.out.println("Card Valid: " + isValidCardNumber(testCard));
    }
}
07 / CARD VERIFICATION VALUE

CVV: Why It Is Never Stored in Databases

The 3-digit (or 4-digit for Amex) Card Verification Value (CVV/CVC) is a cryptographic security code. Its purpose is to prove to the issuing bank that the person initiating an online purchase (Card Not Present) actually holds the physical card.

“CVV is not random, and under global PCI-DSS compliance regulations, it is NEVER stored in any database.”

If a hacker breaches an e-commerce website or merchant database, they may steal stored card numbers and expiry dates, but they can never steal CVVs because merchants are legally forbidden from saving them.
Cryptographic Validation Flow: How the Bank Verifies Your CVV
CVV Input Formula
  • • PAN: 16-Digit Card Number
  • • EXP: Expiry Date (MM/YY)
  • • Service Code: 3-digit POS rule
  • • Master Key (DES/AES): Stored inside Bank HSM (Hardware Security Module)
Network Terminology
  • • Visa: CVV (Card Verification Value)
  • • Mastercard: CVC (Card Validation Code)
  • • Amex: 4-digit CID (Printed on front)
  • • RuPay: CVD (Card Verification Data)
PAYMENT TRANSACTION FLOW:
User inputs Card + Expiry + CVV
    ↓
Merchant sends encrypted payload to Payment Gateway / Network
    ↓
Bank HSM recalculates CVV in real-time using Secret Hardware Key
    ↓
Is Generated CVV == Entered CVV ?
    ├─ YES → Authorize payment & hold funds
    └─ NO  → Immediately decline transaction (Fraud Protection)
08 / SYSTEM CONCLUSION

Card Numbers Aren't Random. They're Engineered Systems.

The next time you make an online transaction or enter your credit card into a checkout form, remember the layers of engineering executing in milliseconds:

The Millisecond Journey of Your 16 Digits:

  • 1. Luhn Check: Browser checks last digit instantly to prevent network calls on simple typos.
  • 2. MII Detection: Browser displays the Visa/Mastercard logo before you submit.
  • 3. BIN Lookup: Payment switch resolves your issuing bank and checks debit vs. credit rules.
  • 4. Account Routing: The bank routes the charge to your specific account reference ledger.
  • 5. Cryptographic CVV Match: Bank HSM regenerates your security code to verify physical ownership.

Did this help you understand how card numbers actually work?

This system architecture breakdown is part of my engineering deep dives on LinkedIn.

Save this post: Bookmark for your next fintech interview
Share: Forward to developers curious about payments
Follow: Stay tuned for distributed system breakdowns
Connect: Reach out on LinkedIn (@shyamkumar1998)
Back to All Articles in The Tech Corner
Discuss Architecture? Contact Me