Portuguese NIF: what it is and how to test it
The NIF (Número de Identificação Fiscal) is the tax number of people and companies in Portugal, issued by the Autoridade Tributária. It has 9 digits, the first of which tells the type of holder, and the last is a check digit. It appears in every invoice with "contribuinte".
For tests only. These numbers have a correct format and check digit but belong to no real person or account. Never use them to deceive, to open accounts or to bypass a check. The numbers on this page come from the same generator as the tool, with a fixed seed so that the examples do not change; the tool creates new ones at every click.
Structure of the number
9 digits: the first digit gives the type (1, 2 and 3 for people, 5 for companies, others for entities of a special kind), 7 of sequence and a check digit. The tool generates numbers starting with 1, 2, 3 and 5.
The check digit, step by step
The first 8 digits are multiplied by the weights 9, 8, 7, 6, 5, 4, 3, 2 and summed. The remainder of the sum by 11 gives the check digit: a remainder of 0 or 1 gives 0, any other gives 11 minus the remainder.
Worked example with 219565104:
| Position | Character | Value | Weight | Product |
|---|---|---|---|---|
| 1 | 2 | 2 | 9 | 18 |
| 2 | 1 | 1 | 8 | 8 |
| 3 | 9 | 9 | 7 | 63 |
| 4 | 5 | 5 | 6 | 30 |
| 5 | 6 | 6 | 5 | 30 |
| 6 | 5 | 5 | 4 | 20 |
| 7 | 1 | 1 | 3 | 3 |
| 8 | 0 | 0 | 2 | 0 |
Sum = 172; 172 mod 11 = 7; the check digit is 4 (11 - 7).
Valid examples
Five numbers generated by the tool with a fixed seed, each one accepted by its validator:
| Without mask | Validator |
|---|---|
219565104 | valid |
537538330 | valid |
192696459 | valid |
108332195 | valid |
395878489 | valid |
How the validator answers
The same first example, one with a changed ending and one truncated, checked by the validator:
| Value | Result | Reason |
|---|---|---|
219565104 | valid | - |
219565105 | invalid | the check digit should be 4 |
2195651 | invalid | needs 9 digits |
Common mistakes
- The Portuguese NIF is not the Spanish NIF: they share a name and not the format. The Portuguese one has no letters; when a form asks for a "NIF" check which country it means.
- Do not prefix the NIF with "PT" for a domestic invoice; the prefix belongs to the VAT number (PT123456789) used in cross-border transactions.
Frequently asked questions
Is 123456789 a valid NIF?
By the check digit, yes: 1 x 9 + 2 x 8 + ... + 8 x 2 = 156, and 156 mod 11 = 2, so the digit is 11 - 2 = 9. It is a test number that does not identify anyone.
How does the NIF relate to the VAT number?
For companies the Portuguese VAT number is "PT" followed by the 9 digits of the NIF. The VAT validator of this site checks that form.
Can I use a Portuguese NIF number generated here in a real system?
No. A number such as 219565104 has a correct format and check, but nobody was issued it, and it may coincide with a real holder by chance. Use it in test environments, demos and automated tests that never leave your control.