Generator · French data

French NIR

Endpoint GET /v1/fr/nir

What it covers

Returns a valid French NIR (numéro de sécurité sociale) with a correct control key. Constrain with `sex` and age/birth-date filters (year and month are encoded; the day is not). Contradictory combinations are rejected with a 400. Set `invalid=true` for a deliberately wrong key.

How it’s calculated

The French NIR (numéro de sécurité sociale) ends in a two-digit control key equal to 97 minus the 13-digit significant part taken modulo 97.

Algorithm

  1. Build the 13-digit significant part by concatenating, with zero-padding, these fields in order: S = sex digit (1 for male, 2 for female); YY = birth year modulo 100, two digits; MM = birth month, two digits; DD = department code, two digits (this generator draws 01-95); CCC = commune code, three digits (drawn 001-990); OOO = order number, three digits (drawn 001-999).
  2. Concatenation yields exactly 13 digits: S YY MM DD CCC OOO. Treat this whole 13-digit string as a single base-10 integer N (use big-integer arithmetic; 13 digits exceeds 32-bit range).
  3. Compute R = N mod 97.
  4. Compute the control key K = 97 - R.
  5. Format K as a two-digit string, left-padded with a zero if K < 10 (K ranges 1..97, so it is always 1 or 2 digits).
  6. Append the two-digit K to the 13-digit significant part. The full NIR is 15 characters: 13 significant digits followed by the 2-digit key.

Worked example

Male born April 1980, department 75, commune 108, order 042 -> 1800475108042 + key ?

Sex digit S = 1 (male).
YY = 1980 mod 100 = 80.
MM = 04 (April).
Department DD = 75.
Commune CCC = 108.
Order OOO = 042.
Significant part N = 1 80 04 75 108 042 = 1800475108042 (13 digits).
R = 1800475108042 mod 97 = 95.
K = 97 - 95 = 2.
Zero-pad K to two digits: 02.
Full NIR = 1800475108042 concatenated with 02 = 180047510804202.

The control key is 02, giving the full NIR 180047510804202.

Edge cases

  • The first digit encodes sex: 1 = male, 2 = female (this generator only emits 1 or 2; the real NIR also uses 3-4 and 7-8 for certain non-mainland/foreign registrations, which this generator does not produce).
  • The control key K = 97 - (N mod 97) ranges from 1 to 97 and is always emitted as two digits (e.g. a residue of 0 would give K = 97, a residue of 96 gives K = 01).

Gotchas

  • The modulus is applied to the entire 13-digit significant part as one integer, not to a weighted digit sum — use BigInt / big-integer math because 13 digits overflows 32-bit and even standard 53-bit float precision for the mod operation is unsafe; the primitive uses BigInt(numericString) % 97n.
  • This generator uses purely numeric department codes (01-95) and does NOT emit the Corsica codes 2A/2B, so it never needs the real-world rule of substituting 2A->19 and 2B->18 before the mod-97 computation.
  • The birth day is not encoded in the NIR at all — only sex, year-mod-100, and month are taken from the birth date; the day drawn is discarded.

Parameters

ParameterTypeDescription
atAgeintegerExact age in years at request time.
bornAfterstringpattern ^\d{4}(?:-\d{2}(?:-\d{2})?)?$Born after this date or fragment (YYYY, YYYY-MM, YYYY-MM-DD).
bornBeforestringpattern ^\d{4}(?:-\d{2}(?:-\d{2})?)?$Born before this date or fragment (YYYY, YYYY-MM, YYYY-MM-DD).
bornOnstringpattern ^\d{4}(?:-\d{2}(?:-\d{2})?)?$Born on a date or within a fragment: YYYY, YYYY-MM, or YYYY-MM-DD.
countinteger1–1000Number of records to return, 1–1000 (your plan may lower this). Omitted returns a single record; set it for a batch.
edgebooleanRestrict output to edge-case values.
extremebooleanReturn 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.
invalidbooleanReturn a NIR with a deliberately wrong control key; sex/year/month stay valid.
olderThanintegerMinimum age in years at request time.
seedintegerInteger seed for reproducible output: the same seed always yields the same record.
sex"m" | "f"Encoded sex: "m" or "f".
youngerThanintegerMaximum age in years at request time.

Response fields

FieldTypeDescription
valuestringThe 15-character NIR.
digitsstringThe canonical 15-character NIR.
sex"m" | "f"Encoded sex: `m` (1) or `f` (2).
birthYearintegerThe full four-digit birth year.
birthMonthintegerThe birth month, 1–12.

Other generators for France

See all generators for France →

The same kind of identifier elsewhere

Try it

Generate a live example below — every response is valid by format and entirely synthetic.