What the IBAN MOD-97 checksum checks
An IBAN combines a two-letter country code, two check digits, and a country-specific BBAN. MOD-97 tests the check-digit relation in that string; it is a calculation, not a request to a bank or payment network.
Keep syntax, registered country length and BBAN pattern, and checksum as separate checks. Swift publishes the ISO 13616 IBAN Registry for national formats. ISO/IEC 7064 describes check-character systems used to detect common copying or keying errors.
| Layer | Question it answers | Example failure |
|---|---|---|
| Input syntax | Are the characters and spacing acceptable? | A slash, punctuation mark, or unsupported symbol is present. |
| Country format | Does this country code use this length and BBAN pattern? | A country code is paired with the wrong total length. |
| MOD-97 checksum | Do the characters satisfy the check-digit relation? | A changed character makes the remainder differ from 1. |
| Bank or payment verification | Does the account exist and can it receive this payment? | This needs a bank or authorized verification flow, not MOD-97. |
IBAN MOD-97 checksum: the four calculation steps
Start from the electronic IBAN: remove permitted print spaces and uppercase ASCII letters, while rejecting other punctuation. Move the first four characters to the end, then replace A–Z with 10–35; leave decimal digits unchanged.
Process the expanded digits from left to right. Start at zero and update remainder = (remainder × 10 + digit) mod 97. The running value stays between 0 and 96, so no large integer is needed. A final remainder of 1 passes the checksum relation.
- NormalizeRemove permitted spaces, uppercase ASCII letters, and reject unsupported characters.
- RotateMove the first four characters of the IBAN to the end.
- Expand lettersReplace A–Z with 10–35 and leave decimal digits unchanged.
- Stream modulo 97Process each digit and accept checksum consistency only when the final remainder is 1.
Worked example: check GB82 WEST 1234 5698 7654 32
This illustrative value is not an account lookup. Removing spaces and rotating the first four characters gives WEST12345698765432GB82. Mapping W=32, E=14, S=28, T=29, G=16, and B=11 produces 3214282912345698765432161182.
The table processes that string in blocks. Each new block is appended to the previous remainder using its decimal width, so the calculation never needs one huge integer.
- Keep every leading zero when reading a block; a block is text for arithmetic, not an account number to normalize numerically.
- The final remainder is 1, so the example passes the checksum calculation. It does not establish that the string is assigned to an active bank account.
| Calculation point | Digits processed | Remainder |
|---|---|---|
| After the first block | 3214282912 | 23 |
| Append the next 10 digits | 3456987654 | 58 |
| Append the final 8 digits | 32161182 | 1 |
| Final result | 3214282912345698765432161182 mod 97 | Passes checksum consistency |
Generate IBAN check digits from a BBAN
Validation checks a complete IBAN; generation starts with a country code and a BBAN that already follows that country's registered format. For generation, place 00 after the country code, rotate the first four characters, expand letters, and find remainder r modulo 97.
The check digits are 98 − r, padded to two digits. Insert them after the country code and validate the completed value; its remainder should be 1. For the example GB BBAN WEST12345698765432, GB00... produces r=16, so the check digits are 82. The arithmetic does not supply or verify bank account details.
- Start with the right BBANObtain the bank and account fields from the applicable registered country format.
- Insert placeholder digitsBuild country code + 00 + BBAN, then rotate and expand it.
- Calculate two digitsSet check digits to 98 minus the remainder, with two-digit zero padding.
- Verify the resultInsert the digits and confirm the full IBAN now leaves remainder 1.
JavaScript implementation without a large integer
This function checks basic syntax and the checksum only. A production validator must also enforce the current country length and BBAN pattern.
function ibanMod97Remainder(input) {
const iban = input.replace(/ /g, "").toUpperCase();
if (!/^[A-Z]{2}[0-9]{2}[A-Z0-9]+$/.test(iban)) {
throw new Error("Invalid IBAN syntax");
}
let remainder = 0;
const rotated = iban.slice(4) + iban.slice(0, 4);
for (const character of rotated) {
const expanded = character >= "A" && character <= "Z"
? String(character.charCodeAt(0) - 55)
: character;
for (const digit of expanded) {
remainder = (remainder * 10 + Number(digit)) % 97;
}
}
return remainder;
}
ibanMod97Remainder("GB82 WEST 1234 5698 7654 32"); // 1
Keep checksum mismatch, syntax failure, and country-format failure as distinct results; the code does not confirm a bank account.
Python-style streaming calculation
The same bounded-remainder loop works in Python. This example keeps the IBAN as text and leaves country-specific format checks to a maintained registry.
import re
source = "GB82 WEST 1234 5698 7654 32"
iban = re.sub(r" ", "", source).upper()
if re.fullmatch(r"[A-Z]{2}[0-9]{2}[A-Z0-9]+", iban) is None:
raise ValueError("Invalid IBAN syntax")
rotated = iban[4:] + iban[:4]
remainder = 0
for character in rotated:
expanded = str(ord(character) - 55) if "A" <= character <= "Z" else character
for digit in expanded:
remainder = (remainder * 10 + int(digit)) % 97
print(remainder) # 1
- The sample returns 1; production code should report parser and checksum failures separately.
Keep checksum arithmetic independently testable when country-format data changes.
Test cases and boundaries for an IBAN checksum implementation
Test the checksum and its parser with labeled examples, malformed input, and synthetic values. Normalization may remove permitted print spaces and uppercase ASCII; it should not strip arbitrary punctuation, replace lookalike characters, or guess missing data.
- Keep synthetic values in tests and mask customer banking data in diagnostics. MOD-97 is error detection, not authentication or payment approval.
| Test | Expected behavior | Layer |
|---|---|---|
| Known checksum-consistent sample | Remainder 1 | Checksum |
| One altered character | Return a checksum mismatch | Checksum |
| Leading zero in a numeric field | Preserve the zero | Parser and checksum |
| Wrong length or unsupported punctuation | Return a format or syntax error | Input validation |
What a passing IBAN MOD-97 checksum cannot prove
A remainder of 1 proves only that the characters satisfy the checksum relation. It does not show that a bank assigned the IBAN, that an account is open, that a recipient owns it, or that a payment can reach it.
A production flow may need a current format registry, recipient confirmation, or an authorized verification service. Keep statuses separate, such as “format accepted,” “checksum passed,” and “bank details not verified.” Use a bank-issued IBAN for real transfers; do not change digits to force a pass.
IBAN MOD-97 checksum FAQ
Is MOD-97 the same as checking the bank account?
No. MOD-97 checks mathematical consistency of the IBAN characters. It does not contact a bank and cannot confirm account assignment, status, ownership, recipient identity, or payment reachability.
What remainder should a checksum-consistent IBAN produce?
After rotating the first four characters and expanding letters, the final remainder should be 1. Check country length and BBAN structure separately.
How do I calculate IBAN check digits from a BBAN?
Use the correct country code and BBAN, insert 00 after the country code, move those first four characters to the end, map letters to 10–35, and calculate the remainder. Subtract the remainder from 98, pad the result to two digits, insert it, and verify the completed IBAN.
Should I use this checksum algorithm with every country format?
The international checksum step is shared, but country BBAN structure and total length differ. Validate the national format against a current registry such as the Swift-published IBAN Registry before applying the checksum result to a complete-format decision.
Implementation checklist
Normalize permitted input, check the country format, rotate, expand letters, and stream modulo 97. Accept checksum consistency only at remainder 1.
For a practical check, use the IBAN Checker; for BBAN-based digit generation, use the IBAN Calculator. Neither replaces bank verification.
Standards and format references
- Swift IBAN Registry and International Bank Account Number — Swift publishes the ISO 13616 registry of national IBAN format specifications.
- ISO/IEC 7064:2003 check character systems — The official standard describes check-character systems for detecting copying and keying errors.