Developer and Text Tools

Code Melli: How Iran's 10-Digit National Code Is Checked

How the Iranian national code (code melli) is built: issuing office, serial and check digit, the mod 11 rule, leading zeros and Persian digits.

Saizul Amin
Saizul Amin29 Oct 2026 · 3 min read
Code Melli: How Iran's 10-Digit National Code Is Checked

Code Melli: How Iran's 10-Digit National Code Is Checked

The national code, code melli (کد ملی), is the identity number of every Iranian citizen. It is printed on the smart national card and the birth certificate (shenasnameh), and almost every service asks for it: banks, the tax office, insurers, universities, mobile operators, online shops and e-government portals. Mistyping it is a common reason for rejected forms. The last digit is a check digit that catches most mistakes, and the Iran National Code Validator applies the rule to one code or a long list.

How the code is built

  • Digits 1 to 3: the code of the civil registration office that issued the number. Codes issued in Tehran, for example, often start with 001 to 008.
  • Digits 4 to 9: a serial number within that office.
  • Digit 10: the check digit.

The number does not contain the date of birth or the gender, so nothing about the person can be read from it except the issuing office.

The check rule

  1. Multiply the first nine digits by 10, 9, 8, 7, 6, 5, 4, 3 and 2.
  2. Add the nine products.
  3. Divide by 11 and keep the remainder r.
  4. If r is 0 or 1, the check digit is r. Otherwise it is 11 − r.

A worked example

Take 0084575948.

Digit008457594
Weight1098765432
Product006428303520278

The sum is 212. 212 = 19 × 11 + 3, so r = 3 and the check digit is 11 − 3 = 8. The last digit is 8, so the code passes. If you change it to 9, the code fails.

Codes that pass but are wrong

Codes made of one repeated digit, such as 0000000000 or 1111111111, satisfy the formula but are never issued. The validator rejects them separately, so a lazy test entry does not slip through a form.

Leading zeros and spreadsheets

Because many codes start with zeros, spreadsheet programs often turn 0084575948 into the number 84575948. When you import such a list, the validator pads 8 and 9-digit entries with zeros back to ten digits before checking. In your own files, store national codes as text, not numbers, to keep the zeros.

Persian and Arabic digits

Codes copied from Persian documents often use Persian digits (۰۰۸۴۵۷۵۹۴۸) or Arabic-Indic digits. The validator converts them to Latin digits automatically. Spaces and dashes are removed, so 008-457594-8 works as well.

Checking a list

Paste one code per line. Each line shows whether it passed and, if not, why: the wrong number of digits, a repeated digit or a wrong check digit. This makes it easy to clean an HR export or a customer list before uploading it to a bank or an insurer.

For developers

The check is cheap and can run on every keystroke. In code it is a loop over nine digits with weights from 10 to 2, a modulo 11, and the rule for remainders below 2. Run it on the client for quick feedback and on the server before saving. Remember that a passing code is still only a well-formed number.

Test codes

The tool can make random codes that pass the check, for testing your own forms. They are generated, not taken from real people. Do not use them in real applications.

Privacy and limits

The national code is personal data. The validator runs entirely in your browser and sends nothing anywhere. A code that passes does not prove that it belongs to a living person or to the person in front of you; only the civil registration organisation can confirm that.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages