This reference guide provides essential information about the Mexican banking system, including institution codes, CLABE validation, RFC formats, and SPEI operating schedules. This information is crucial for implementing SPEI transfers and withdrawals in Mexico.

Institution Codes

Major Mexican financial institutions and their corresponding codes for SPEI transactions:
CodeBank NameCLABE PrefixType
40012BBVA México012Commercial Bank
40014Santander014Commercial Bank
40021HSBC021Commercial Bank
40072Banorte072Commercial Bank
40646STP646Payment Institution
40137Banregio137Commercial Bank
40058Banco Azteca058Commercial Bank
40030Bajío030Commercial Bank
40036Inbursa036Commercial Bank
40042Mifel042Commercial Bank
40060Bansi060Commercial Bank
40102The Royal Bank102Foreign Bank
40103American Express103Credit Card Company
40106Bank of America106Foreign Bank
40108JP Morgan108Foreign Bank
40110Credit Suisse110Foreign Bank
40124Deutsche Bank124Foreign Bank
40126Credit Agricole126Foreign Bank
40127Azteca127Commercial Bank
40128Autofin128Development Bank
40129Barclays129Foreign Bank
40130Compartamos130Development Bank
40131Banco Famsa131Commercial Bank
40132BMULTIVA132Brokerage
40133ACTINVER133Brokerage
40135NAF135Development Bank
40136Intercam Banco136Commercial Bank
40138Intercam138Brokerage
40139Bancoppel139Commercial Bank
40140ABC Capital140Brokerage
40141UBS Bank141Foreign Bank
40143CIBanco143Commercial Bank
40145Bbase145Commercial Bank
40147Bankaool147Commercial Bank
40148Pagatodo148Payment Institution
40150Inmobiliario150Development Bank
40151Donde151Payment Institution
40152Bancrea152Commercial Bank

CLABE Validation

CLABE (Clave Bancaria Estandarizada) is Mexico’s standardized bank account number format used for SPEI transfers.

CLABE Format Structure

  • Total length: 18 digits
  • Bank code: 3 digits (positions 1-3)
  • Branch code: 3 digits (positions 4-6)
  • Account number: 11 digits (positions 7-17)
  • Check digit: 1 digit (position 18)
Example CLABE Breakdown:
CLABE: 012345678901234567
│││└─────────────────── Account number (11 digits)
││└─────────────────────── Branch code (3 digits)
│└──────────────────────── Bank code (3 digits)
└───────────────────────── Check digit (1 digit)
Where:
  • 012: BBVA México bank code
  • 345: Branch code (specific branch)
  • 67890123456: Account number (11 digits)
  • 7: Check digit (calculated using algorithm)

CLABE Validation Algorithm

The check digit is calculated using a weighted sum algorithm:
def validate_clabe(clabe):
    """Validate CLABE number using check digit algorithm"""
    
    if len(clabe) != 18 or not clabe.isdigit():
        return False
    
    # Weights for positions 1-17
    weights = [3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7]
    
    # Calculate weighted sum
    weighted_sum = sum(int(clabe[i]) * weights[i] for i in range(17))
    
    # Calculate check digit
    remainder = weighted_sum % 10
    calculated_check_digit = (10 - remainder) % 10
    
    # Compare with actual check digit
    actual_check_digit = int(clabe[17])
    
    return calculated_check_digit == actual_check_digit

# Example usage
clabe = "012345678901234567"
is_valid = validate_clabe(clabe)
print(f"CLABE {clabe} is {'valid' if is_valid else 'invalid'}")

CLABE Components Extraction

The code block below shows how to parse the CLABE into its components.

RFC (Tax ID) Format

RFC (Registro Federal de Contribuyentes) is Mexico’s tax identification system.

RFC Format Types

TypeLengthStructurePatternExample
Individual134 letters + 6 digits + 3 alphanumeric characters^[A-Z&Ñ]{4}\\d{6}[A-Z\\d]{3}$MAGR850920XY1
Business123 letters + 6 digits + 3 alphanumeric characters^[A-Z&Ñ]{3}\\d{6}[A-Z\\d]{3}$ABC850920123

RFC Format Breakdown

TypeLetters PartDigits PartVerification PartDescription
IndividualMAGR850920XY1Name-derived letters + birth date + verification code
BusinessABC850920123Business name-derived letters + registration date + verification code

RFC Validation

Here is an example of how to validate the RFC format.

RFC Type Detection

The code block below shows how to determine the type of RFC.

SPEI Timing and Operational Constraints

SPEI operates with specific timing considerations that affect when transfers can be processed and completed. Understanding these constraints helps ensure reliable payment processing.
The code block below shows how to check if SPEI is currently operating.

Bank Account Types

The table below shows the different account types in Mexico.
CodeTypeDescription
1Checking AccountCuenta de cheques
2Savings AccountCuenta de ahorros
3Credit AccountCuenta de crédito
40CLABE AccountCuenta CLABE (for SPEI)
10Investment AccountCuenta de inversión
Usage in WithdrawalsFor SPEI withdrawals, the account type is usually picked up automatically from the CLABE format. However, for some operations, you might need to specify it yourself:
{
  "beneficiary": {
    "account": "012345678901234567",
    "account_type": "40",
    "name": "Roberto Martínez García",
    "rfc": "MAGR850920XY1",
    "institution": "40012"
  }
}

Complete Validation Function

The code block below shows a complete validation function for Mexican banking data.

Common Implementation Patterns

Expand the items below to see the code for some common implementation patterns.

Error Messages

The table below shows the error messages for Mexican banking data.
Error CodeEnglish Message
invalid_clabeCLABE must be exactly 18 digits with valid checksum
invalid_clabe_checksumCLABE checksum is invalid
invalid_rfcRFC format is invalid (must be 12-13 alphanumeric characters)
invalid_institutionInstitution code not found in Mexican banking system
clabe_institution_mismatchCLABE bank code does not match institution code
spei_not_operatingSPEI transfers are not processed outside business hours
invalid_account_typeAccount type must be valid for SPEI transfers
You can use the code block below to get the error message for a given error code.
MEXICAN_BANKING_ERRORS = {
    'invalid_clabe': 'CLABE must be exactly 18 digits with valid checksum',
    'invalid_clabe_checksum': 'CLABE checksum is invalid',
    'invalid_rfc': 'RFC format is invalid (must be 12-13 alphanumeric characters)',
    'invalid_institution': 'Institution code not found in Mexican banking system',
    'clabe_institution_mismatch': 'CLABE bank code does not match institution code',
    'spei_not_operating': 'SPEI transfers are not processed outside business hours',
    'invalid_account_type': 'Account type must be valid for SPEI transfers'
}

def get_error_message(error_code, lang='en'):
    """Get localized error message"""
    
    spanish_messages = {
        'invalid_clabe': 'CLABE debe tener exactamente 18 dígitos con suma de verificación válida',
        'invalid_rfc': 'Formato de RFC inválido (debe tener 12-13 caracteres alfanuméricos)',
        'spei_not_operating': 'Las transferencias SPEI no se procesan fuera del horario bancario'
    }
    
    if lang == 'es' and error_code in spanish_messages:
        return spanish_messages[error_code]
    
    return MEXICAN_BANKING_ERRORS.get(error_code, 'Unknown banking error')

Next Steps