Portugal NIF Validator
Online Portuguese NIF (Tax Number) validator. Perfect for software QA.
How does Portuguese NIF validation work?
Validation checks if the NIF has exactly 9 digits, starts with a valid category prefix, and computes a Modulo 11 sum of the first 8 digits using decrescent weights from 9 to 2.
If the weighted sum % 11 is 0 or 1, the check digit must be 0. Otherwise, it is 11 minus the remainder. Any discrepancy marks the document as invalid.
Anatomy & Structure of Portuguese NIF
The Tax Identification Number (NIF) consists of 9 digits issued by AT:
| Position | Field | Length | Meaning & Rule | Example |
|---|---|---|---|---|
| 1 | Prefix / Category | 1 digit | Taxpayer category (1/2/3 Individual, 5 Company, 6 Public Body, 8 Sole Trader, 9 Funds) | 5 |
| 2 to 8 | Sequential | 7 digits | Sequential identifier assigned by the Tax Authority (AT) | 0123456 |
| 9 | Check Digit | 1 digit | Weighted checksum digit calculated with Modulo 11 and weights 9 to 2 | 7 |
NIF Validation Algorithm (Weighted Modulo 11)
The Tax Authority calculates the check digit using descending weights from 9 to 2:
DV = 11 - (sum(d_i * [9, 8, 7, 6, 5, 4, 3, 2]) % 11) | if DV >= 10, DV = 0
- 1. Multiply first 8 digits by weights [9, 8, 7, 6, 5, 4, 3, 2].
- 2. Compute sum of products.
- 3. Calculate remainder modulo 11: Remainder = Sum % 11.
- 4. Preliminary check digit: DV = 11 - Remainder.
- 5. If DV is 10 or 11, set DV = 0; otherwise use the calculated number.