Mexico's 18-digit bank number has a typo detector built in

You paste an 18-digit CLABE into your banking app, hit send on a SPEI transfer, and the money goes... somewhere. Maybe to the right person. Maybe to a stranger whose account number differs from your friend's by one digit. The bank will show you the beneficiary name before you confirm, but by then you are already trusting your own typing.

Here is the part nobody tells you: the CLABE itself can catch your typo. The last of its 18 digits is not part of the account at all. It is a check digit, computed from the other 17 with a small weighted sum. Get one digit wrong and the check digit almost always disagrees. The number literally fails its own arithmetic.

What a CLABE actually is

CLABE stands for Clave Bancaria Estandarizada. Since 2004 it has been the standard account number for interbank transfers in Mexico, and every SPEI transfer rides on one. The 18 digits split into four parts:

  • Digits 1 to 3: the bank code. 012 is BBVA Mexico, 002 is Banamex, 014 is Santander, 072 is Banorte.
  • Digits 4 to 6: the plaza, the code of the city where the account was opened.
  • Digits 7 to 17: the account number, padded with zeros to 11 digits.
  • Digit 18: the check digit.

So a CLABE is not a random string. It is a small structured record, and the last digit is its seal.

The 3-7-1 check

The check digit uses weights 3, 7 and 1, repeating, over the first 17 digits. Multiply each digit by its weight, keep only the last digit of each product, add them up, and the check digit is what brings the total up to the next multiple of 10.

Take 032180000118359719. The first 17 digits are 03218000011835971:

const weights = [3, 7, 1]; const digits = "03218000011835971".split("").map(Number); const products = digits.map((d, i) => (d * weights[i % 3]) % 10); // [0, 1, 2, 3, 6, 0, 0, 0, 0, 3, 7, 8, 9, 5, 9, 1, 7] const sum = products.reduce((a, b) => a + b, 0); // 61 const checkDigit = (10 - (sum % 10)) % 10; // 9 

The sum is 61, so the check digit is 9. The CLABE ends in 9. Valid.

Change one digit and it breaks. 032180000118359718 ends in 8, but the math still says 9, so the number is rejected. That is the whole point: a single mistyped digit, and most swaps of two neighbouring digits, make the check digit disagree. The error is caught before any money moves.

Here is the complete validator in about ten lines:

function isValidClabe(clabe) { const clean = clabe.replace(/\D/g, ""); if (clean.length !== 18) return false; const weights = [3, 7, 1]; let sum = 0; for (let i = 0; i < 17; i++) { sum += (Number(clean[i]) * weights[i % 3]) % 10; } return (10 - (sum % 10)) % 10 === Number(clean[17]); } isValidClabe("012345678901234568"); // true (sum 82, check 8) isValidClabe("002010077777777771"); // true (sum 69, check 1) isValidClabe("032180000118359718"); // false (check should be 9) 

Two details worth noticing. First, each product is reduced modulo 10 before adding. That is what makes the check sensitive to transpositions: swapping two adjacent digits changes which weight each one gets, so the sum usually changes too. Second, the (10 - x) % 10 at the end handles the case where the sum already ends in 0, in which case the check digit is 0, not 10.

What the check cannot do

A valid check digit proves the number is well formed. It does not prove the account exists, that it is open, or that it belongs to the person you think you are paying. A CLABE copied from the wrong person passes the check perfectly. That is why your banking app shows the beneficiary name returned by the receiving bank before you confirm a SPEI transfer: the check digit guards against typos, the name guards against paying the wrong person. Use both.

It also cannot tell you which bank a code belongs to on its own. The first three digits are a code from Banco de Mexico's SPEI participant list, and that list changes as banks merge and new fintechs join. A validator can map the common codes, 012 to BBVA Mexico, 002 to Banamex, 014 to Santander, 072 to Banorte, 638 to Nu Mexico, and show "unknown code" for anything outside its list. Unknown does not mean invalid; it just means the list does not cover that institution.

The same trick is everywhere

Once you see the pattern, you start spotting it in every identifier you type. A US routing number uses the same 3-7-1 weights over 9 digits. A credit card number uses the Luhn algorithm. An ISBN-13 uses alternating 1 and 3 weights. A SWIFT/BIC code has its own structure rules. They are all the same idea: a little redundancy, placed where a human is most likely to slip, so the error announces itself instead of silently costing money.

If you work with Mexican payments, or you are building anything that accepts a CLABE, run the check before you send anything. It is ten lines, it runs entirely in the browser, and it catches the most common failure mode of all: a tired human typing 18 digits by hand.

I built a free validator that does exactly this, with the step-by-step working shown so you can see every weight and product: https://www.theutilityhub.online/tools/clabe-validator

Paste a CLABE, see whether it is valid, which bank the code belongs to, and what the check digit should have been. If you only have 17 digits, it computes the 18th for you.