Generator · Portuguese data
Portuguese NIF
Endpoint GET /v1/pt/nif
What it covers
Returns a valid Portuguese NIF (tax identification number) with a correct mod-11 check digit. Use `entity` to shape a person or company (NIPC) number, `format` for the `PT` VAT form, and `invalid=true` for a NIF with a deliberately wrong check digit.
How it’s calculated
The Portuguese NIF/NIPC check digit (9th digit) is a weighted mod-11 complement of the first eight digits, with an overflow rule that collapses a complement of 10 or 11 to 0.
Algorithm
- Take the first 8 digits of the NIF (positions 1..8, left to right). The 9th digit is the check digit to be computed.
- Assign fixed position weights [9, 8, 7, 6, 5, 4, 3, 2] to digits 1 through 8 respectively (digit 1 gets weight 9, digit 2 gets weight 8, ..., digit 8 gets weight 2).
- Compute the weighted sum: multiply each digit by its weight and add all eight products together.
- Take the weighted sum modulo 11; call this `base` (a value 0..10).
- Compute the complement: `raw = 11 - base` (a value 1..11).
- Apply the mod11-mod10 overflow rule: `check = (raw % 11) % 10`. This means a raw of 11 becomes 0, a raw of 10 becomes 0, and any raw 1..9 stays unchanged. The result is always a single digit 0..9.
- Append `check` as the 9th digit. (Note: the leading digit is not free — persons use a leading digit of 1, 2, or 3; companies/NIPC use 5, 6, 8, or 9 — but this constraint does not affect the checksum computation.)
Worked example
NIF 12345678? (person, leading digit 1)
Payload digits: 1, 2, 3, 4, 5, 6, 7, 8 with weights 9, 8, 7, 6, 5, 4, 3, 2.
Products: 1×9=9, 2×8=16, 3×7=21, 4×6=24, 5×5=25, 6×4=24, 7×3=21, 8×2=16.
Weighted sum = 9+16+21+24+25+24+21+16 = 156.
base = 156 mod 11 = 156 - (11×14=154) = 2.
raw = 11 - 2 = 9.
check = (9 mod 11) mod 10 = 9 mod 10 = 9.The check digit is 9, so the full NIF is 123456789.
Edge cases
- The leading digit encodes the entity kind: 1-3 for a natural person's NIF, and 5/6/8/9 for a company (NIPC). This is enforced when drawing the number but is not part of the checksum math.
- The check digit can legitimately be 0 (when the complement raw value is 10 or 11, both collapse to 0 under the mod11-mod10 overflow), so a trailing 0 is valid.
- Because the mod11-mod10 overflow always yields a single digit 0..9 for any eight-digit prefix, no prefix is ever 'unissued' for the checksum's sake — the generator never has to redraw payload digits to obtain a valid check digit.
Gotchas
- This is the complement style (raw = 11 - (sum mod 11)), NOT the plain-remainder style used by e.g. PL NIP. Using sum mod 11 directly gives the wrong digit.
- The overflow rule is specifically mod11-mod10 ((raw % 11) % 10): both raw=11 and raw=10 map to 0. Do not treat raw=10 as 'invalid/unissued' the way DK CVR or FI Y-tunnus do — PT NIF collapses it to 0 instead.
- Weights run 9 down to 2 (position 1 = weight 9), not 2 up to 9. The highest weight is on the leftmost/leading digit.
Parameters
| Parameter | Type | Description |
|---|---|---|
| count | integer1–1000 | Number of records to return, 1–1000 (your plan may lower this). Omitted returns a single record; set it for a batch. |
| edge | boolean | Restrict output to valid edge-case NIFs from the rare corners. |
| entity | "person" | "company" | Taxpayer kind: `person` (leading 1–3) or `company`/NIPC (leading 5/6/8/9). |
| extreme | boolean | Return a correct value wrapped in a hostile encoding (untrimmed whitespace, invisible/zero-width characters, BOM, or bidi/combining marks). Homoglyphs are excluded so the value stays machine-parseable; it still validates after normalisation. |
| format | "national" | "vat" | Rendering: bare 9-digit NIF (default) or the `PT`-prefixed VAT form. |
| invalid | boolean | Return a NIF with a deliberately wrong mod-11 check digit. |
| seed | integer | Integer seed for reproducible output: the same seed always yields the same record. |
Response fields
| Field | Type | Description |
|---|---|---|
| value | string | The NIF in the requested format (national or PT VAT). |
| digits | string | The canonical, unprefixed 9-digit NIF. |
| entity | "person" | "company" | Which entity kind the number was shaped for. |
Other generators for Portugal
Portuguese Cartão de Cidadão numberPortuguese companyPortuguese company namePortuguese email addressPortuguese IBANPortuguese personPortuguese person namePortuguese product or service offeringPortuguese vehicle registration plate
See all generators for Portugal →The same kind of identifier elsewhere
Austrian data · Austrian SVNRBelgian data · Belgian RijksregisternummerBulgarian data · Bulgarian EGNCroatian data · Croatian JMBGCroatian data · Croatian OIBCypriot data · Cyprus TICCzech data · Czech rodné čísloDanish data · Danish CPRDutch data · Dutch BSNEstonian data · Estonian isikukoodFinnish data · Finnish henkilötunnusFinnish data · Finnish Y-tunnusFrench data · French NIRGerman data · German Steuer-IdNrGreek data · Greek AFMGreek data · Greek AMKAHungarian data · Hungarian adóazonosító jelHungarian data · Hungarian személyi azonosítóHungarian data · Hungarian TAJIrish data · Irish PPSNItalian data · Italian Codice FiscaleLatvian data · Latvian personas kodsLithuanian data · Lithuanian asmens kodasLuxembourg data · Luxembourg matriculePolish data · Polish PESELRomanian data · Romanian CNPSlovak data · Slovak rodné čísloSlovenian data · Slovenian davčna številkaSlovenian data · Slovenian EMŠOSpanish data · Spanish DNISpanish data · Spanish NIESwedish data · Swedish personnummer
Try it