Skip to main content
CLABE (Clave Bancaria Estandarizada) is Mexico’s standardized bank account number format used for SPEI transfers. This guide explains the validation algorithm and provides implementation examples. CLABE numbers contain four distinct components that can be extracted for processing:
  • 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)
Here is an example of a CLABE number and a breakdown of its components: CLABE: 012345678901234567
012Bank Code3 digits (positions 1-3)Identifies the financial institution. See Institution Codes.
345Branch Code3 digits (positions 4-6)Identifies the specific branch or plaza.
67890123456Account Number11 digits (positions 7-17)Unique account identifier within the branch.
7Check Digit1 digit (position 18)Validates the entire CLABE using a weighted algorithm.
The first 3 digits of a CLABE correspond to the last 3 digits of the institution code. For example, 012 in the CLABE maps to institution code 40012 (BBVA Mexico).

CLABE Validation Algorithm

The CLABE validation algorithm uses a weighted sum calculation to verify account number integrity. Each of the first 17 digits is multiplied by a specific weight (following the pattern 3, 7, 1 repeatedly), then all products are summed. The check digit is calculated as (10 - (sum % 10)) % 10 and must match the 18th digit for the CLABE to be valid:

RFC (Tax ID) Validation

RFC (Registro Federal de Contribuyentes) is Mexico’s tax identification system used alongside CLABE numbers. RFC identifiers come in two distinct formats depending on whether they’re for individuals or businesses: Each RFC format contains specific components that encode different types of information: The following functions provide RFC validation and type detection capabilities:
This function validates RFC format using regex patterns to ensure proper structure for both individual and business formats:
This function determines whether an RFC belongs to an individual or business based on its length:

Common Validation Patterns

Common validation patterns involve checking the combined length of CLABE and RFC, ensuring they match the expected formats, and validating the check digits for each component. The following functions provide comprehensive validation for Mexican banking data:

Error Messages

When validation fails, your application should handle these standardized error codes to provide clear feedback to users. Each error code corresponds to a specific validation failure with localized message support: The following code provides a centralized error handling system with support for both English and Spanish messages. Use the get_error_message() function to retrieve localized error messages based on error codes returned by validation functions:

See also

You can find more information about the Mexican banking system in the following guides: