Account numbers and identifiers: NUBAN, bank codes, BVN, NIN and phone numbers
Four different numbers name a bank account, a bank, a person and a phone, and most of them are 10 or 11 digits long. Learn what each one can prove, and what a check digit can stop before the network is called
Across the lab's week, the switch carried 12,158 name enquiries. 403 came back 07, 'invalid account'. A name enquiry is a network call to the beneficiary's bank. What share of those 403 could a check on the digits alone, run on the sender's side before any call, have stopped?
A bank transfer is addressed by two things and checked by two more. You name an institution and an account at it. You may hold a number for the person (a BVN or a NIN) and one for the phone. The trouble is that all four look like strings of digits, three of them are ten or eleven digits long, and code that treats them alike will one day send money to the wrong place or refuse the right customer. The earlier chapter on transfers and virtual accounts introduced the account number and the check digit as an idea. This chapter gives you the algorithm and runs it.
Four numbers, four things named
| Identifier | What it names | Issued by | What it cannot tell you |
|---|---|---|---|
| Account number (NUBAN) | One account at one institution | The institution, under a central bank standard | Whose account it is, or whether it is open |
| Bank or institution code | The institution | The central bank assigns the NUBAN codes; the switch operator keeps its own list for routing | Which branch, or which account |
| BVN, bank verification number | A person, across every bank they use | The banking industry’s identity service, run by NIBSS | That the person is the one at the screen |
| NIN, national identification number | A person, for the state | The national identity agency | Which accounts the person holds |
| Phone number | A SIM, and so the person who holds it today | The telco | That the person is who they were when the number was issued |
A name is not on the list on purpose. In the lab, 22,835 accounts carry 640 different holder names, and the commonest name sits on 52 accounts. A name is a label for a human to read. It is never a key.
The account number: NUBAN
NUBAN, the Nigeria Uniform Bank Account Number, is the ten-digit number a customer types. The CBN’s Revised Standards on the NUBAN for banks and other financial institutions supersede the NUBAN standards of 19 August 2010. Search results quoting the document describe a sixteen-digit structure: a six-digit institution code, a nine-digit serial number and a check digit, of which the customer sees the last ten. For a deposit money bank the six digits are its three-digit CBN code with three leading zeros (011 becomes 000011); for other financial institutions the code is a five-digit CBN number with a leading 9 (50547 becomes 950547). The check digit comes from the first fifteen digits, weighted 3, 7, 3 and repeating, summed, taken modulo 10, subtracted from 10, with a result of 10 read as 0. The CBN’s 2018 exposure draft is quoted with a worked example, code 011 and serial 000001457, which gives a sum of 81 and check digit 9, and this chapter recomputed it and got the same. Secondary sources give 9 March 2020 as the circular’s date, and a news report quoting it gives 20 April 2020 as the day it takes effect and 15 March 2021 as the deadline for full compliance; another summary of the document says one year from release. The dates are not settled hereas of 2026-11. The CBN’s PDF could not be opened in this build, so everything above rests on search results and summaries. Read the standard for the exact wording before you write a validator for real traffic.
Leading zeros add nothing to a weighted sum, so for a bank the sixteen-digit form gives the same answer as bank code plus serial. That is the version the lab uses: three digits of code, nine digits of serial, twelve weights (3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3), the same weights the CBN’s method gives once its three leading zeros are set aside. The lab’s bank codes are invented, and the lab gives every participant a three-digit code. It does not model the longer codes of other institutions. Do not copy a lab code into real software.
Work one number through, as step 2 does. The account 3179858018 is at institution B01, whose invented code is 824. Line up 824 and the first nine digits 317985801 against the weights:
| digit | 8 | 2 | 4 | 3 | 1 | 7 | 9 | 8 | 5 | 8 | 0 | 1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| weight | 3 | 7 | 3 | 3 | 7 | 3 | 3 | 7 | 3 | 3 | 7 | 3 |
| product | 24 | 14 | 12 | 9 | 7 | 21 | 27 | 56 | 15 | 24 | 0 | 3 |
The products add to 212. 212 modulo 10 is 2, 10 − 2 is 8, and the number ends in 8. The last digit is a function of the other nine and of the bank. That second part matters: the same nine digits at a bank with a different code give a different last digit, most of the time.
What a check digit catches
Think of a typist. The common slips are one wrong digit and two neighbours swapped. A check digit is built to make the first impossible to miss. Each digit is multiplied by 3 or 7, and neither shares a factor with 10, so changing one digit by any amount changes the weighted sum by an amount that is not a multiple of 10. Step 2 proves it on the data: 2,055,150 wrong numbers made by changing one digit anywhere in all 22,835 accounts, and none passes.
Swaps are weaker. If the two swapped digits have the same weight, the sum does not move at all. In a ten-digit number the weights, left to right, are 3, 7, 3, 3, 7, 3, 3, 7, 3, and the check digit comes last. So the pairs in positions 2 and 3, and 5 and 6 (counting from 0, as step 2 does), carry equal weights, and step 2 shows 100.0% of those swaps passing. Every other pair of serial digits passes about 11% of the time: the swap moves the sum by 4 times the difference between the digits, and that is a multiple of 10 only when the difference is 5 either way. The last pair, the ninth serial digit and the check digit, does not follow that rule, since the check digit is not in the sum, and it passes about one time in ten, as chance would. Most swaps are caught. Some are not, in fixed places, and you should know where.
A check digit also needs the right code. Step 3 shows why the pair travels together.
Bank codes: one bank, several codes
The bank code in the NUBAN sum may not be the only code a bank has. The lab’s participants table holds two: nuban_code, three digits, and inst_code, six digits (900824 for B01 beside its 824), both invented. One bank’s developer documentation describes an endpoint that returns the institutions enrolled on the NIP instant-payment service with their codes. This chapter could not open the page, so it does not say how many digits those codes have or how they relate to the CBN’s NUBAN codes. This is a bank’s own developer page, a vendor description and not a rule: take the codes you route on from the scheme operator’s current list through your sponsor bank or provideras of 2026-11. Whether a real network uses more than one code per institution is a question for that documentation, not for the lab.
The practical rule is plain. Keep a table of institutions with one row per code system, name the system in every column, and never use a code from one system where another is expected. A transfer carries the institution code beside the account number. Drop it, and the number is ambiguous.
Same ten digits, two people
Step 3 finds eight ten-digit numbers that exist at two banks each, and in every case it is the same ten digits. 0184970917 is Kunle Onyeka’s at B01 and Garba Nwosu’s at B24. 1437073236 is Dami Ibrahim’s at B01 and Tunde Usman’s at B20. Nothing is wrong in the data. A bank issues its own serial numbers, and two banks can issue the same nine digits. The number is unique only inside its bank.
Why do these eight sit at B03, B04, B08, B10, B20 and B24, and not at any of the other banks? The reason is exact. The bank code enters the weighted sum through its three digits a, b, c with weights 3, 7, 3, so it adds 3a + 7b + 3c to the sum, and the serial adds the same amount at every bank. Call the code’s contribution g, taken modulo 10. The check digit is 10 minus the sum modulo 10, so moving the same serial from a bank with g1 to a bank with g2 changes the check digit by g1 − g2, modulo 10, whatever the serial is. The shift is constant for a pair of codes. B01 has g = 0 and B05 has g = 2, so B01’s 2552074517 moved to B05 would end in a digit 2 lower, 2552074515, a different number. Only when g1 equals g2 is the shift 0 and the full ten digits identical. In the final table of step 3 the banks fall into nine groups, and the seven in group 0 (B01, B03, B04, B08, B10, B20 and B24) can hold the same number. Counting the pairs inside each group gives 36 of the 276 pairs of banks, so most pairs of banks cannot share a number. The lab plants its eight pairs where they can, with B03 and B04 twice each. The code is worth one of ten values, not a thousand. That is also why the check digit is a weak tell for the wrong bank: a number typed against the wrong bank still passes wherever the group matches. In the lab a number valid at one bank is accepted at 3.11 of the other 23 banks on average (step 3). The check digit narrows the field. It does not choose.
So a screen that lets a customer pick a bank from a list, then type a number, still needs the name enquiry, which asks the beneficiary’s bank. The earlier chapter taught that rule from the regulation; this chapter shows why the digits cannot replace it.
BVN and NIN: identifiers for a person
An account number names a place for money. A BVN or a NIN names a person. The CBN’s BVN page lists the revised Regulatory Framework for BVN Operations and Watch-List as issued on 12 October 2021, replacing the 2017 framework. Law-firm summaries of it say users of the BVN database must obtain the customer’s consent, and that a watch-listed BVN applies to all linked accounts and wallets except Tier 1. This chapter did not open the PDFas of 2026-11. A later addendum is reported by press and law-firm commentary, not read here in the CBN’s text: a law firm’s commentary and several news reports say a 2026 addendum to the framework has institutions keep a temporary watch-list for BVNs tied to suspected fraud, with a listing lasting at most twenty-four hours and the holder to be contacted. Most reports date the circular to 12 March 2026 and its effect to 1 May 2026, while two say it was sent to banks on 26 March. The dates are not settled, and none of these results is the CBN’s own text: check the circularas of 2026-11. Explainer sites, not the CBN text, say a BVN is eleven digits, biometric, tied to a person across all their banks, and held in a database that NIBSS keeps.
A NIN is the national identity number. The telecoms regulator’s FAQ describes the NIN as an eleven-digit number and says the National Identity Management Commission has sole authority to issue it, though accredited enrolment partners, some of them banks, do the enrolmentas of 2026-11. The two numbers are different systems from different issuers that look alike.
Why do they matter on a payments screen? Because they decide who may hold an account of which size. A regulatory-alert summary, which is commentary and not the CBN’s text, says circular PSM/DIR/PUB/CIR/001/053 of 1 December 2023 requires a BVN or a NIN on all Tier 1 accounts and wallets and a BVN and/or NIN on individual Tier 2 and 3 accounts, and bars new Tier 1 accounts without one. Other summaries say funded Tier 1 accounts without either were to be on Post No Debit or Credit status from 1 March 2024, but sources disagree on the dates and the CBN’s own text should be readas of 2026-11. Wallets and stored value covers the tiers; here the point is narrower. The tier decides the identifier, and the identifier lives in the institution’s own record of the customer, not in the number the other bank sees on the transfer. The lab’s transfers carry no BVN, and a BVN column sits in accounts. Whether a real message carries one is a question for the scheme’s documentation.
Step 5 shows one thing about BVNs worth knowing. The generator draws each BVN at random, and two values came up twice by chance: 00163436248 on Amaka Ekpo at B06 and on Yetunde Oladipo at B09, and 00260788770 on Emeka Obi at B09 and on Amaka Ekpo at B15. A real bank would treat a BVN shared by two names as a red flag and ask which record is wrong. The generator’s repeats are not planted, so use them only as the shape of that check.
Phone numbers: an identifier that is also an address
A phone number names a SIM. Two things follow. It is a good way to reach a person, and it can change hands, so the person who holds it today may not be the person who held it when an account was opened: check the telco’s rules on reassignment before you rely on one. It is also how some providers address wallets. A 2020 post on X (then Twitter) by a wallet provider says that its customers’ phone numbers became their account numbers, and that a sender enters the last ten digits of the phone number where a NUBAN goesas of 2026-11. That is one company’s claim from 2020, and this chapter found no current source for how other providers do it. If a provider works this way, its numbers need not satisfy the check digit, which matters for what comes next.
A phone number as people write it has a leading 0 (eleven digits) or +234 in front with the 0 dropped. So ten digits of a phone number and a ten-digit account number are the same shape, and eleven digits of a phone number match a BVN and a NIN. Step 5 prints it: three kinds of identifier, each with several possible meanings, and a short function that lists the meanings a bare string could have. The function has no way to choose. A field must say what it holds.
What the transfer screen can check, in order
Chimdi’s screen runs four checks, cheapest first.
- Shape. Ten digits, nothing else. No network, no table.
- Check digit, for institutions you know. Needs the institution’s code and the algorithm. No network. Stops numbers that cannot exist.
- Name enquiry. One call to the beneficiary’s bank, through the switch. Stops numbers that are well formed and not open, and shows a name.
- A person compares the name. Stops an account that exists and is the wrong one.
Each stage answers something the stage before could not. Checks 1 and 2 are free, and in the lab they remove 81% of the invalid-account answers and 2.7% of all name enquiries. Check 3 is the only one that touches the other bank. Check 4 cannot be automated away: a valid account of the wrong person passes the first three.
The bank’s own answer has the last word, and a local check can be wrong in only two ways. The code table can be stale, so a real customer’s number is refused. Or the institution does not follow the check digit, as with a number that is a phone number. Both mean the local check should reject only where you hold evidence that it applies, and treat everything else as “go to the network”.
Where it goes wrong
Treating the check digit as proof of an account. It proves the digits are consistent with a code. 28.2% of the lab’s accounts still pass with the code left out, which the break at the end of the lab shows.
A stale code table. A bank code is copied into a config file when the screen is built. A new institution or a changed code makes valid numbers fail, and the customer cannot fix it. Load the table from the scheme operator’s list on a schedule and log every rejection with the code version.
Using the number without the institution. A transfer to 5486102507 with no bank is a coin toss between two people. Keep the pair in one value everywhere: the database, the log, the support tool.
Identifiers in free text. A column called id_number that holds a BVN for some rows and a NIN for others turns every later join into guesswork. Store the type with the value.
Names as keys. A match on holder name joins strangers. In the lab, 52 accounts share one name.
Logging identifiers in clear text. A BVN, a NIN and a phone number are personal identifiers. They do not belong in application logs or in a prompt to a public assistant. The next section returns to that.
You work in labs/finance. Everything runs on data/rails.sqlite, the lab’s model week. Its bank codes, response codes and counts are illustrative, so none of them is NIBSS’s or the CBN’s.
1. Generate the week and check it. About one second at the default scale.
cd labs/finance
python3 rails.py
python3 check.py --rails-only32 participants, 22,835 accounts, 17,998 transfers, 12,158 name enquiries, 136 status queries
21 settlement sessions, 125 batch files, 193 RTGS payments, 3,412 USSD sessions, 3,453 PSB postings
planted (answers/rails_truth.csv): credited_without_settlement 4, customer_fee_not_charged 6, customer_reversed_twice 3, levy_not_charged 5, mmo_trust_shortfall 1, participant_limit 4, participant_outage 1, psb_cash_out_fee_not_posted 1, psb_cash_out_posted_twice 1, reversed_after_late_success 4, same_number_two_banks 8, switch_incident 1, telco_record_missing 12
rails week: 17,998 transfers, 21 settlement sessions, 22,835 accounts; checks 21-25 run
OK: all invariants holdInvariant 21 is the one this chapter rebuilds: every account number passes the check digit for its institution’s code. Do not open data/answers/ yet.
2. Compute the check digit, and see what it catches. Save this as nuban.py, or paste it into a terminal. It works one account by hand, validates all 22,835, and tries 2,055,150 wrong numbers.
python3 - <<'PY'
import sqlite3
WEIGHTS = [3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3] # the lab's weights: 3-digit code, then 9-digit serial
def check_digit(code3: str, serial9: str) -> str:
total = sum(int(d) * w for d, w in zip(code3 + serial9, WEIGHTS))
return str((10 - total % 10) % 10)
def is_valid(code3: str, number10: str) -> bool:
return len(number10) == 10 and number10.isdigit() and check_digit(code3, number10[:9]) == number10[9]
db = sqlite3.connect("data/rails.sqlite")
code = dict(db.execute("SELECT code, nuban_code FROM participants"))
accounts = db.execute("SELECT institution, account_no FROM accounts").fetchall()
# 1. one account by hand
inst, no = accounts[0]
digits = code[inst] + no[:9]
print(f"1. {no} at {inst} (code {code[inst]})")
print(" digits ", " ".join(digits))
print(" weights ", " ".join(str(w) for w in WEIGHTS))
products = [int(d) * w for d, w in zip(digits, WEIGHTS)]
print(" products", " ".join(str(p) for p in products), " sum", sum(products))
print(f" sum mod 10 = {sum(products) % 10}; 10 - {sum(products) % 10} = {10 - sum(products) % 10}; mod 10 -> check digit {check_digit(code[inst], no[:9])}; the number ends in {no[9]}")
# 2. every account
bad = [(i, n) for i, n in accounts if not is_valid(code[i], n)]
print(f"2. {len(accounts):,} accounts checked, {len(bad)} fail")
# 3. what the check digit catches
one_digit = missed = 0
for inst, n in accounts:
for pos in range(10):
for d in "0123456789":
if d != n[pos]:
one_digit += 1
missed += is_valid(code[inst], n[:pos] + d + n[pos + 1:])
print(f"3. one digit changed, any position: {one_digit:,} wrong numbers, {missed} still pass")
print(" two neighbouring digits swapped, by the position of the pair (0 is the first digit):")
for pos in range(9):
tried = passed = 0
for inst, n in accounts:
if n[pos] != n[pos + 1]:
tried += 1
passed += is_valid(code[inst], n[:pos] + n[pos + 1] + n[pos] + n[pos + 2:])
print(f" positions {pos}-{pos + 1}: {tried:>6,} swaps, {passed:>6,} still pass ({100 * passed / tried:5.1f}%)")
PY1. 3179858018 at B01 (code 824)
digits 8 2 4 3 1 7 9 8 5 8 0 1
weights 3 7 3 3 7 3 3 7 3 3 7 3
products 24 14 12 9 7 21 27 56 15 24 0 3 sum 212
sum mod 10 = 2; 10 - 2 = 8; mod 10 -> check digit 8; the number ends in 8
2. 22,835 accounts checked, 0 fail
3. one digit changed, any position: 2,055,150 wrong numbers, 0 still pass
two neighbouring digits swapped, by the position of the pair (0 is the first digit):
positions 0-1: 20,529 swaps, 2,305 still pass ( 11.2%)
positions 1-2: 20,538 swaps, 2,260 still pass ( 11.0%)
positions 2-3: 20,554 swaps, 20,554 still pass (100.0%)
positions 3-4: 20,505 swaps, 2,301 still pass ( 11.2%)
positions 4-5: 20,612 swaps, 2,266 still pass ( 11.0%)
positions 5-6: 20,538 swaps, 20,538 still pass (100.0%)
positions 6-7: 20,576 swaps, 2,262 still pass ( 11.0%)
positions 7-8: 20,510 swaps, 2,253 still pass ( 11.0%)
positions 8-9: 20,544 swaps, 2,350 still pass ( 11.4%)All 22,835 accounts pass, which is invariant 21. No single wrong digit gets through. Two positions, 2-3 and 5-6, let every swap through because their weights are both 3. The other pairs of serial digits let through about one swap in nine: the swap changes the sum by 4 times the difference of the digits, and only a difference of 5 either way makes that a multiple of 10. The last pair includes the check digit, so it passes by chance, near one in ten. Your counts match these exactly, since the seed is fixed. The weights are the lab’s: for real traffic read the CBN’s weights in the standard.
3. Find the number that two banks hold, and test it against every bank. The query lists ten-digit numbers held at more than one institution. The loops try every bank account at the other 23 banks’ codes, and group the serials.
python3 - <<'PY'
import sqlite3
from collections import defaultdict
WEIGHTS = [3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3]
def check_digit(code3, serial9):
return str((10 - sum(int(d) * w for d, w in zip(code3 + serial9, WEIGHTS)) % 10) % 10)
def is_valid(code3, number10):
return check_digit(code3, number10[:9]) == number10[9]
db = sqlite3.connect("data/rails.sqlite")
code = dict(db.execute("SELECT code, nuban_code FROM participants"))
banks = [c for c, in db.execute("SELECT code FROM participants WHERE kind = 'DMB' ORDER BY code")]
# 1. the same ten digits at two institutions
rows = db.execute("""SELECT account_no, institution, holder, status FROM accounts
WHERE account_no IN (SELECT account_no FROM accounts GROUP BY account_no HAVING COUNT(*) > 1)
ORDER BY account_no, institution""").fetchall()
print("1. ten-digit numbers held at more than one institution")
for no, inst, holder, status in rows:
print(f" {no} {inst} {holder:<18} {status}")
# 2. does the check digit tell the banks apart?
accounts = db.execute("SELECT institution, account_no FROM accounts WHERE institution LIKE 'B%'").fetchall()
passes = defaultdict(int)
for inst, no in accounts:
passes[sum(is_valid(code[b], no) for b in banks if b != inst)] += 1
n = len(accounts)
print(f"2. each of {n:,} bank accounts tried at the other {len(banks) - 1} banks' codes: how many other banks accept it")
for k in sorted(passes):
print(f" accepted by {k} other bank(s): {passes[k]:>5,} ({100 * passes[k] / n:.1f}%)")
print(f" average {sum(k * v for k, v in passes.items()) / n:.2f} other banks; {100 * passes[0] / n:.1f}% are rejected by every other bank")
# 3. the same nine-digit serial at several banks
dup = db.execute("""SELECT substr(account_no, 1, 9) s, COUNT(*), COUNT(DISTINCT account_no), group_concat(institution)
FROM accounts GROUP BY s HAVING COUNT(DISTINCT institution) > 1 ORDER BY s""").fetchall()
print(f"3. nine-digit serials used at more than one institution: {len(dup)}")
for s, k, ten, insts in dup:
print(f" {s} {insts:<8} distinct ten-digit numbers: {ten}")
# 4. why the answers come in lumps: the code enters the sum only as 3a + 7b + 3c, mod 10
classes = defaultdict(list)
for b in banks:
a, bb, c = map(int, code[b])
classes[(3 * a + 7 * bb + 3 * c) % 10].append(b)
print("4. banks grouped by (3a + 7b + 3c) mod 10 of their three-digit code abc")
for k in sorted(classes):
print(f" {k}: {' '.join(classes[k])}")
PY1. ten-digit numbers held at more than one institution
0184970917 B01 Kunle Onyeka active
0184970917 B24 Garba Nwosu active
1437073236 B01 Dami Ibrahim active
1437073236 B20 Tunde Usman active
2552074517 B01 Funmi Danladi active
2552074517 B03 Garba Lawal active
4264522557 B01 Yetunde Obi active
4264522557 B04 Ibrahim Onyeka active
4375741461 B01 Kunle Ibrahim active
4375741461 B04 Hauwa Ekpo active
6350669841 B01 Tope Ibrahim active
6350669841 B10 Sadiq Salami active
6373514764 B01 Amaka Yusuf active
6373514764 B03 Uche Obi active
7150996092 B01 Jide Ogunleye active
7150996092 B08 Ifeoma Nwosu active
2. each of 20,207 bank accounts tried at the other 23 banks' codes: how many other banks accept it
accepted by 0 other bank(s): 2,524 (12.5%)
accepted by 1 other bank(s): 4,631 (22.9%)
accepted by 3 other bank(s): 6,732 (33.3%)
accepted by 6 other bank(s): 6,320 (31.3%)
average 3.11 other banks; 12.5% are rejected by every other bank
3. nine-digit serials used at more than one institution: 8
018497091 B01,B24 distinct ten-digit numbers: 1
143707323 B01,B20 distinct ten-digit numbers: 1
255207451 B01,B03 distinct ten-digit numbers: 1
426452255 B01,B04 distinct ten-digit numbers: 1
437574146 B01,B04 distinct ten-digit numbers: 1
635066984 B01,B10 distinct ten-digit numbers: 1
637351476 B01,B03 distinct ten-digit numbers: 1
715099609 B01,B08 distinct ten-digit numbers: 1
4. banks grouped by (3a + 7b + 3c) mod 10 of their three-digit code abc
0: B01 B03 B04 B08 B10 B20 B24
2: B05 B12 B13 B16
3: B07 B15
4: B11 B21
5: B09
6: B14 B22
7: B19
8: B02 B17 B18 B23
9: B06Eight numbers are two people each: one ten-digit value, two holders, in two banks, so the number cannot be the identifier without its bank. Each of the eight shared serials has the same nine digits at B01 and another bank, and all eight give the same ten digits, because the other bank (B03, B04, B08, B10, B20 or B24) sits in group 0 with B01 in part 4 and so produces the same check digit for the same serial. A serial moved to a bank in another group would end in a different digit by a fixed amount: B05 (group 2) would give 2552074515 where B01 has 2552074517. The 20,207 is the accounts at the 24 banks. The answers come in lumps of 0, 1, 3 or 6 other banks because the group sizes are 7, 4, 2, 2, 1, 2, 1, 4 and 1, and an account passes at the other banks of its own group. A number valid at one bank is accepted at 3.11 others on average. The check digit narrows the field and does not choose a bank.
4. Count the 07s a local check would have stopped. This reads name_enquiries, runs the check digit for the destination bank on every number, and sorts the answers.
python3 - <<'PY'
import sqlite3
from collections import Counter
WEIGHTS = [3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3]
def is_valid(code3, number10):
total = sum(int(d) * w for d, w in zip(code3 + number10[:9], WEIGHTS))
return str((10 - total % 10) % 10) == number10[9]
db = sqlite3.connect("data/rails.sqlite")
code = dict(db.execute("SELECT code, nuban_code FROM participants"))
exists = {(i, n): s for i, n, s in db.execute("SELECT institution, account_no, status FROM accounts")}
by = Counter()
ms = Counter()
for dest, no, resp, ms_ in db.execute("SELECT dest, account_no, response, latency_ms FROM name_enquiries"):
local = "fails check digit" if not is_valid(code[dest], no) else "passes check digit"
if resp == "07":
why = "no such account" if (dest, no) not in exists else f"account is {exists[(dest, no)]}"
by[(resp, local, why)] += 1
if not is_valid(code[dest], no):
ms["stopped"] += ms_
else:
by[(resp, local, "")] += 1
total = sum(by.values())
print(f"{total:,} name enquiries")
for (resp, local, why), n in sorted(by.items()):
print(f" response {resp}: {local:<18} {why:<22} {n:>6,}")
stopped = sum(n for (r, l, w), n in by.items() if r == "07" and l == "fails check digit")
n07 = sum(n for (r, l, w), n in by.items() if r == "07")
print(f"a local check would have stopped {stopped} of {n07} 07s ({100 * stopped / n07:.1f}%), {100 * stopped / total:.1f}% of all enquiries")
print(f"network time those {stopped} calls took: {ms['stopped']:,} ms in all, about {ms['stopped'] // stopped} ms each")
print(f"the other {n07 - stopped} 07s needed the network: the number is well formed")
p01 = db.execute("SELECT account_no, response FROM name_enquiries WHERE src = 'P01'").fetchall()
print(f"Owoleaf (P01) sent {len(p01)} name enquiries; {sum(r == '07' for _, r in p01)} came back 07")
print(f"any 00 that fails the check? {sum(n for (r, l, w), n in by.items() if r == '00' and l == 'fails check digit')}")
PY12,158 name enquiries
response 00: passes check digit 11,744
response 07: fails check digit no such account 325
response 07: passes check digit account is closed 78
response 91: passes check digit 11
a local check would have stopped 325 of 403 07s (80.6%), 2.7% of all enquiries
network time those 325 calls took: 155,595 ms in all, about 478 ms each
the other 78 07s needed the network: the number is well formed
Owoleaf (P01) sent 156 name enquiries; 3 came back 07
any 00 that fails the check? 0325 of the 403 07s fail the check digit: the generator makes its mistyped numbers by changing one digit, which a check digit always catches, so real typing mistakes would give a lower share. The other 78 are numbers of closed accounts: the digits are right and the account is not open. The 11 91s are name enquiries sent to B07 during its outage, so the bank was down and the number is not at fault. There are fewer enquiries than the week’s 17,998 transfers because about a third of transfers go to a saved beneficiary and reuse an earlier enquiry. No answered 00 fails the check. The 478 milliseconds is the lab’s modelled enquiry latency, not a measured one. Owoleaf’s own 156 enquiries held 3 07s, a small sample.
5. Tell the identifiers apart, then open the key. This step counts the shapes of the account and BVN columns, shows that a bare string cannot be classified, finds the repeated BVN and the shared names, and reads the planted same_number_two_banks rows against what step 3 found.
python3 - <<'PY'
import csv, sqlite3
from collections import Counter
db = sqlite3.connect("data/rails.sqlite")
q = lambda sql, *a: db.execute(sql, a).fetchall()
print("1. what the identifier columns look like")
for col in ("account_no", "bvn"):
shapes = Counter((len(v), v.isdigit()) for (v,) in q(f"SELECT {col} FROM accounts"))
print(f" {col:<11} " + ", ".join(f"{n:,} values of {length} digits" for (length, digits), n in shapes.items() if digits))
def could_be(value):
"""Everything an unlabelled run of digits might be. Shape cannot decide."""
out = []
if len(value) == 10:
out.append("an account number (NUBAN)")
out.append("a phone number without its leading 0")
if len(value) == 11:
out.append("a BVN")
out.append("a NIN")
if value.startswith("0"):
out.append("a phone number with its leading 0")
return out or ["nothing this chapter names"]
for v in ("3179858018", "08000000001", "123456789"):
print(f" {v:<12} could be: {'; '.join(could_be(v))}")
print("2. names do not identify")
holders, accounts = q("SELECT COUNT(DISTINCT holder), COUNT(*) FROM accounts")[0]
print(f" {accounts:,} accounts carry {holders} different holder names")
for name, n in q("SELECT holder, COUNT(*) FROM accounts GROUP BY holder ORDER BY 2 DESC, 1 LIMIT 3"):
print(f" {name:<16} {n} accounts")
print("3. one BVN on two accounts")
for bvn, no, inst, holder in q("""SELECT bvn, account_no, institution, holder FROM accounts
WHERE bvn IN (SELECT bvn FROM accounts GROUP BY bvn HAVING COUNT(*) > 1) ORDER BY bvn, institution"""):
print(f" {bvn} {inst} {no} {holder}")
print("4. the answer key, opened now: same_number_two_banks")
with open("data/answers/rails_truth.csv") as f:
for row in csv.DictReader(f):
if row["kind"] != "same_number_two_banks":
continue
other_no, (first, second) = row["ref"], row["who"].split(" and ")
(first_no,) = q("SELECT account_no FROM accounts WHERE institution = ? AND substr(account_no, 1, 9) = ?", first, other_no[:9])[0]
print(f" {first} {first_no} {second} {other_no} same ten digits: {first_no == other_no}")
PY1. what the identifier columns look like
account_no 22,835 values of 10 digits
bvn 22,835 values of 11 digits
3179858018 could be: an account number (NUBAN); a phone number without its leading 0
08000000001 could be: a BVN; a NIN; a phone number with its leading 0
123456789 could be: nothing this chapter names
2. names do not identify
22,835 accounts carry 640 different holder names
Ifeoma Onyeka 52 accounts
Garba Obi 51 accounts
Chika Lawal 50 accounts
3. one BVN on two accounts
00163436248 B06 7697690386 Amaka Ekpo
00163436248 B09 3223068483 Yetunde Oladipo
00260788770 B09 7219055622 Emeka Obi
00260788770 B15 1286196271 Amaka Ekpo
4. the answer key, opened now: same_number_two_banks
B01 6373514764 B03 6373514764 same ten digits: True
B01 4264522557 B04 4264522557 same ten digits: True
B01 7150996092 B08 7150996092 same ten digits: True
B01 6350669841 B10 6350669841 same ten digits: True
B01 1437073236 B20 1437073236 same ten digits: True
B01 0184970917 B24 0184970917 same ten digits: True
B01 2552074517 B03 2552074517 same ten digits: True
B01 4375741461 B04 4375741461 same ten digits: TrueThe key lists eight planted same_number_two_banks rows, and all eight are the same ten digits. The generator copies a B01 serial to a bank whose code gives B01’s check digit (B03, B04, B08, B10, B20 or B24, the group 0 banks of step 3) and works out that bank’s own check digit, which comes out the same. Copied to a bank in any other group, the serial would end in a different digit and the pair would share a serial and not a number. The eleven-digit BVN column cannot be told from a NIN or a phone number by shape, and the 640 names are no identifier. The two BVN repeats are chance in the generator, not planted breaks. The 08000000001 in the demo is made up.
Leave the bank code out of the check. Run this and see how much of the check is the code:
python3 - <<'PY'
import sqlite3
WEIGHTS = [3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3]
def is_valid(code3, number10):
total = sum(int(d) * w for d, w in zip(code3 + number10[:9], WEIGHTS))
return str((10 - total % 10) % 10) == number10[9]
db = sqlite3.connect("data/rails.sqlite")
accounts = db.execute("SELECT institution, account_no FROM accounts").fetchall()
passed = sum(is_valid("000", n) for _, n in accounts)
print(f"with the bank code left out: {passed:,} of {len(accounts):,} accounts still pass ({100 * passed / len(accounts):.1f}%)")
by = {}
for i, n in accounts:
by.setdefault(i, [0, 0])
by[i][0] += 1
by[i][1] += is_valid("000", n)
print("institutions where every account passes:", " ".join(sorted(i for i, (t, p) in by.items() if t == p)))
print("institutions where none passes:", sum(p == 0 for t, p in by.values()), "of", len(by))
PYIt prints with the bank code left out: 6,440 of 22,835 accounts still pass (28.2%), then the institutions where every account passes (B01 B03 B04 B08 B10 B20 B24 F02), and institutions where none passes: 24 of 32. A blank code is 000, which is a group 0 code: every account at the eight group 0 institutions passes, and not one account passes at the other 24. The check digit is meaningless without the right bank beside it. Ask what your screen does when the customer picks the wrong bank from the list.
Template
# Account-number validation: <screen name>
Owner: <PM> Engineer: <name> Approver: <role> Date: <date> Version: <n>
## Purpose and decision needed
<one paragraph: what the screen does today, and what you ask the approver to decide by when>
## The checks, in order
| # | Check | Needs | Can prove | Cannot prove | Network call? |
|---|-------|-------|-----------|--------------|---------------|
| 1 | Format | <rule> | <...> | <...> | no |
| 2 | Check digit | <code system, algorithm> | <...> | <...> | no |
| 3 | Name enquiry | <switch, bank> | <...> | <...> | yes |
| 4 | Name match | <who compares what> | <...> | <...> | no |
## What the screen shows on each failure
| Failure | Exact message | Customer can | We log |
|---------|---------------|--------------|--------|
## Evidence from the lab (or our own data)
<figure, the line that printed it, what it means for each check>
## Out of scope
<what this specification does not cover>
## How this could be wrong
<one way, and what result would show it>
---
# Ticket: update the institution-code table
Title: <imperative> Owner: <name> Approver: <role> Due: <date>
| Institution | Code system | Code | Follows check digit? | Evidence | Action |
|-------------|-------------|------|----------------------|----------|--------|
Rule for rows with no evidence: <what the screen does>
Rollback: <how to undo> Log: <what a rejection records, with the table version> WORKED EXAMPLE
Adebisi, the product manager for Owoleaf’s transfer screen, writes this with Chimdi, who builds it, and the head of payments approves it. Version 1, 23 November 2026.
Decision needed. Approve blocking at check 2 only for institutions with evidence, by the end of the month.
Checks. (1) Format: ten digits and nothing else. It proves only that the string can be an account number. (2) Check digit with the institution’s three-digit code. In the lab all 22,835 accounts pass it, and 2,055,150 numbers with one digit changed produced 0 passes. It cannot prove the account exists: a number accepted by one bank is accepted by 3.11 other banks on average, and it lets through every swap of the third and fourth digits, or of the sixth and seventh. (3) Name enquiry: only the bank’s own answer. Of 12,158 enquiries, 11,744 answered 00. (4) A person compares the returned name with who they meant to pay. It alone catches a real account of the wrong person, and 52 accounts share one holder name.
Screen. Check 1 fails: “Account numbers have 10 digits.” Check 2 fails: “This number does not look right for the bank you chose. Check both.” Answer 07: “This account was not found or is closed.” Answer 91: “That bank is not answering. Try again later.” Name differs: the customer sees the name and a Cancel button.
Evidence. A local check would have stopped 325 of 403 answers of 07 (80.6%), which is 2.7% of all enquiries, about 478 ms each. The other 78 are closed.
Ticket. Add column follows_check_digit to the institution-code table. The lab only shows the method: all 22,835 accounts pass for their own bank’s code, so B01 (code 824, step 2) is marked yes. On the real list, a row is yes only when real numbers at that institution have passed. Any row with no evidence goes to check 3.
Could be wrong. The lab’s mistyped numbers change one digit, so 80.6% flatters real typing. A stale code table would also refuse real customers. The log of rejections, with the table version, would show both.
Now you
You are the product manager at Ferrowave, the bulk-payouts API. A business customer uploads a salary file and each row carries a bank, a ten-digit account number and an amount. Today the file goes to the switch as it is, and the customer reads about bad rows in the reconciliation file the next day. Nobody is at a screen to compare a returned name. Write the validation specification for the upload step, with its ticket to update the institution-code table. An engineer from your team signs the technical rows, and the head of payments approves it.
Use the lab’s figures, run on your own copy of the week: the 325 numbers that fail the check digit, the 78 closed accounts it cannot see, the 3.11 banks that accept a number, and the participants table with its two code columns (nuban_code and inst_code). State what a row that fails each check does to the rest of the file, and who is told. Say which institutions you have evidence for and which you do not.
Your reader is the head of payments. The decision it supports is whether a failing row is held back or the whole file is stopped.
Self-check
Adebisi and Chimdi decide what Owoleaf's transfer screen does when a customer picks a bank and types a ten-digit number that fails the check digit for that bank's code. The lab says a local rejection would have stopped 81% of the week's invalid-account answers. But a bank code table can go stale, and some institutions may issue numbers that do not follow the check digit at all. Which policy do they ship?
- DOC Revised Standards on the Nigeria Uniform Bank Account Number (NUBAN) for Banks and Other Financial Institutions (CBN, 2020) Central Bank of Nigeria, 2020
The regulator's own text for the structure and the check digit. Read the account structure and the worked example, and take the exact weights from it before you write a validator. This chapter rests on search results quoting it, so check each figure yourself.
- DOC Exposure circular for NUBAN for banks and other financial institutions (CBN, 2018) Central Bank of Nigeria, 2018
The earlier draft of the revised standard, quoted in search results with a worked example (code 011, serial 000001457, check digit 9). Work the example by hand against the lab's function, and treat the 2020 document as the one in force.
- DOC Bank Verification Number (CBN) Central Bank of Nigeria
The regulator's own page on the BVN, which lists the BVN framework and its dates. Read it for the current framework documents, and check whether newer circulars are listed.
- DOC Revised Regulatory Framework for Bank Verification Number (BVN) Operations and Watch-List (CBN, 2021) Central Bank of Nigeria, 2021
The rules for how BVNs are issued, shared between institutions and placed on the watch-list. Read the sections on the watch-list and on who may access BVN data. A 2026 addendum is reported in commentary, so look for the circular itself.
- DOC About the NIN (Nigerian Communications Commission FAQ) Nigerian Communications Commission
A regulator's plain description of the NIN and who issues it. Read it to see the NIN as a different system from the BVN. It is a telecoms regulator's FAQ, not the identity agency's own rule, so check NIMC for the current process.
- DOC Check digit (Wikipedia) Wikipedia
A general introduction to check digits and the errors they catch, including weighted modulus-10 schemes and transposition errors. Read it for the idea, then use the CBN's standard for the actual algorithm. A reference article, not a source of rules.
- DOC GetNIPBanks (a bank's developer documentation) Providus Bank
An example of how a bank exposes the list of institutions enrolled on NIP with their codes. Read it to see the shape of a code table. It is one bank's vendor page, not the scheme's own list, so take your routing codes from the operator.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.