How to use the NIF generator tool
- Choose an Operation: Validate checksum for an existing number, Generate test numbers for new ones.
- When validating, type the nine digits into Portuguese NIF without the PT country prefix.
- When generating, set Test numbers to generate to a value between 1 and 50.
- Select Process number. The Result box shows the verdict or a list with one NIF per line.
- Select Copy to copy the output, or Clear to empty the form.
What a Portuguese NIF looks like
The NIF (Número de Identificação Fiscal), also called número de contribuinte, is the nine-digit tax number that the Portuguese tax authority issues to people and organizations. Eight digits identify the holder and the ninth is a check digit. With PT in front, the same number serves as the Portuguese VAT identification number in EU trade.
The leading digit signals the type of holder. 1, 2 and 3 are used for individuals, 5 for companies and other legal persons, 6 for public bodies, 8 for sole traders and 9 for various other entities and special cases. 999999990 is the generic number invoices use for a final consumer who is not identified.
How the NIF check digit works (modulo 11)
Multiply the first eight digits by the weights 9, 8, 7, 6, 5, 4, 3 and 2, add the products and take the remainder after dividing by 11. If the remainder is 0 or 1, the check digit is 0. For any other remainder it is 11 minus the remainder.
For 12345678 the weighted sum is 156. Dividing 156 by 11 leaves 2, and 11 - 2 = 9, so the complete number is 123456789.
1*9 + 2*8 + 3*7 + 4*6 + 5*5 + 6*4 + 7*3 + 8*2 = 156
156 mod 11 = 2
11 - 2 = 9
Input: 123456789
Result: Checksum valid. Assignment status is unknown.Rules this NIF generator and validator applies
The validator removes spaces, dots, slashes and hyphens and then requires exactly nine digits. It applies three tests, and the generator only outputs numbers that pass all of them.
- The ninth digit must equal the modulo 11 result.
- The first digit must be 1, 2, 3, 5, 6, 8 or 9.
- The nine digits must not all be the same.
- Input with the PT prefix, another letter or a different length stops with Enter 9 digits.
A limitation with NIFs that start with 4 or 7
Portugal also issues numbers with other prefixes, for example 45 for non-resident individuals and several ranges starting with 7 for undivided estates, investment funds and non-resident entities. This tool reports every NIF that begins with 0, 4 or 7 as Invalid Portuguese NIF number, even when the check digit is right. For such numbers, verify the check digit with the formula above.
Using generated NIFs in tests
Generated numbers consist of eight random digits, drawn with crypto.getRandomValues and redrawn until the first digit is in the allowed set, plus the computed check digit. The first digit is random within that set, so you cannot choose the holder type. The numbers suit form validation tests, billing software demos and sample SAF-T files. A random NIF can match one that is assigned to a real taxpayer, so never present one as your own tax number.
Frequently asked questions
Is a NIF that passes the checksum a registered number?
Not necessarily. The check digit only shows that the nine digits fit the formula. Whether the tax authority has assigned the number, and to whom, cannot be determined in the browser, so the result adds Assignment status is unknown.
Can I validate a Portuguese VAT number such as PT123456789?
Remove the PT prefix first. The tool expects nine digits and answers Enter 9 digits when letters are present. The digits after PT are the NIF, so the checksum result applies to the VAT number as well.
Why does the tool reject a NIF beginning with 45 or 7?
Its first-digit list contains only 1, 2, 3, 5, 6, 8 and 9. Real numbers with other prefixes exist, but this validator marks them invalid regardless of the check digit.
What is the difference between NIF and NIPC?
NIPC (Número de Identificação de Pessoa Coletiva) is the name for the tax number of a company or other legal person. It has the same nine-digit layout and the same check digit formula as an individual's NIF, so this tool handles both.