nif.mod11
Portuguese NIF — Mod-11 algorithm and prefixes
9-digit Portuguese tax ID; check digit computed via Mod-11 with weights 9..2.
What a NIF is
A NIF (Número de Identificação Fiscal) is the 9-digit Portuguese tax ID issued by AT to individuals, companies and other entities. SAF-T files reference NIFs in three required spots: Header.TaxRegistrationNumber, every Customer.CustomerTaxID, and every Supplier.SupplierTaxID.
The Mod-11 algorithm
The 9th digit is a check digit computed from the first eight:
- Multiply digit 1 by 9, digit 2 by 8, …, digit 8 by 2.
- Sum the products.
- Take the sum modulo 11.
- If the result is 0 or 1, the check digit is 0.
- Otherwise the check digit is 11 − result.
# Worked example: 503504564
# digits 5 0 3 5 0 4 5 6
# weights 9 8 7 6 5 4 3 2
# products 45 0 21 30 0 16 15 12 → sum 139
# 139 mod 11 = 7
# 11 - 7 = 4
# check = 4 → matches digit 9 ✓
Allowed first digits
| Range | Used by |
|---|---|
| 1, 2, 3 | Individuals (residents) |
| 5 | Companies (LDA, SA, etc.) |
| 6 | Public administration |
| 8 | Empresário em Nome Individual (ENI) |
| 9 | Other entities |
| 45, 70-79, 90, 91, 98, 99 | Specific cases (e.g. heritage, condominium, foreign-resident) |
Special cases
999999990is the AT-reserved placeholder for "Consumidor final" (anonymous retail buyer). It is allowed inCustomer.CustomerTaxIDfor retail-style invoices.- Any NIF that fails the Mod-11 check is rejected, even if the digits look plausible.
How to fix
The fix depends on which side has the wrong digit:
- Header.TaxRegistrationNumber wrong — your own NIF is misconfigured in the ERP. Update the company profile and re-export — or, if you only need to ship this one file, use the inline editor to patch the value in place.
- Customer or Supplier NIF wrong — typo or stale record. Correct it in the master data and re-export — or patch the offending occurrence with the inline editor when re-exporting is not an option.
SAFTCheck never invents a NIF; the inline editor only applies the value you supply. We do not auto-suggest tax IDs.
Related
- ATCUD format — the document-level unique code, separate from NIFs.
- Inline editor — patch a NIF in place once you have the correct value.