dqagent
← Blog

Validating Turkish IBANs with the Mod-97 Check

· 5 min read

A Turkish IBAN has 26 characters: the country code TR, two check digits, a 5-digit bank code, one reserved digit and a 16-digit account number. Payment files, customer master data and reconciliation jobs all carry IBANs, and a single mistyped digit can cause a rejected payment or a failed match. The two check digits let you detect nearly all single-digit typos and most transpositions before a payment is attempted.

How the check works

  • Remove spaces and convert to upper case. A Turkish IBAN must then be 26 characters, start with TR, and contain only digits after that.
  • Move the first four characters (TR and the two check digits) to the end of the string.
  • Replace each letter with two digits, A = 10, B = 11 and so on up to Z = 35. T becomes 29 and R becomes 27.
  • Read the result as one large integer. The IBAN is valid only if that integer mod 97 equals 1.

A tested implementation

def is_valid_tr_iban(value: str) -> bool:
    iban = value.replace(" ", "").upper()
    if len(iban) != 26 or not iban.startswith("TR") or not iban[2:].isdigit():
        return False
    rearranged = iban[4:] + iban[:4]                 # move "TR" + check digits to the end
    number = int("".join(str(int(ch, 36)) for ch in rearranged))  # A=10 ... Z=35
    return number % 97 == 1

is_valid_tr_iban("TR33 0006 1005 1978 6457 8413 26")  # True  (published sample IBAN)
is_valid_tr_iban("TR33 0006 1005 1978 6457 8413 27")  # False (last digit changed)

Python integers have arbitrary precision, so the large number is not a problem there. In languages with fixed-width integers, process the string in chunks and carry the remainder forward instead of building the whole number.

Checks that go beyond the checksum

  • Bank code: the 5 digits after the check digits identify the bank. Compare them against the list of codes you actually do business with.
  • Reserved digit: this position is expected to be 0 in Turkish IBANs.
  • Duplicates: the same IBAN attached to many unrelated customers is a data quality and a fraud signal.
  • Formatting drift: spaces, lower case and hyphens in the same column point to inconsistent input channels.

As with national ID numbers, a valid checksum means the IBAN is well-formed, not that the account exists or belongs to the named customer.

DQ-Agent includes an IBAN format check (TR plus 24 digits and the mod-97 test) as a critical validity anomaly in its on-premise profiling and anomaly detection phases.

30-minute live demo against your own schema

Not a slideshow — a live install. We profile your SQL Server connection in minutes.