Classic sequence
- Input
- 12345678
- Expected output
- Dígito 9, NIF 123456789
Sum 156, remainder 2, 11 minus 2.
validate Portuguese NIF check digit
The last digit of a NIF is not random: it comes from an arithmetic on the first 8. If you know it, you can validate a NIF in any language or spreadsheet without an outside service. Paste a number into the tool to see the result and the corrected digit.
Sum 156, remainder 2, 11 minus 2.
Sum 139, 11 minus 7.
Sum 22, a multiple of 11.
Remainder 1 also gives 0.
The tool suggests the digit.
Each of the first 8 digits is multiplied by the weights 9, 8, 7, 6, 5, 4, 3, 2 and the products are added. The remainder of the division by 11 decides the ninth digit: 0 or 1 gives 0, and any other remainder r gives 11 minus r. For 204716624 the sum is 139, the remainder is 7 and the digit is 4.
The idea is similar (weights and modulus 11) but the details differ. The CPF has 11 digits and two check digits, with weights from 10 to 2 and from 11 to 2. The NIF has 9 digits and a single check digit, with weights from 9 to 2.
Take SUMPRODUCT of the first 8 digits by the weights 9 to 2, take the remainder by 11 with the modulo function and compare it with the ninth digit, treating remainder 0 and 1 as digit 0. The tool shows each result so you can check your formula.
It can, if the site queries the AT or VIES and the number is not assigned or active. Local validation only guarantees the number is well formed.
Valid NIF structure
This checks structure and arithmetic only. It does not prove the number was issued to anyone, or that the account exists.