Skip to main content

Spanish Social Security Number (NAF) Generator

Generate and format valid Spanish Social Security Number (NAF) for software testing and development.

Waiting for generation...

About Spanish Social Security Number (NAF)

The NAF is the unique 12-digit number assigned to workers registered in the Spanish Social Security system. It is mandatory for employment in Spain.

This tool generates and validates NAF codes, verifying the last 2 check digits applying the standard Modulo 97 algorithm on the first 10 digits.

Anatomy & Structure of Spanish NAF

The Social Security Affiliation Number (NAF) consists of 12 digits issued by TGSS:

PositionFieldLengthMeaning & RuleExample
1 & 2Province2 digitsINE province code of first registration (e.g., 28 Madrid, 08 Barcelona)28
3 to 10Sequential8 digitsUnique correlative worker sequential number in Social Security12345678
11 & 12Check Digits2 digitsTwo-digit control checksum calculated using Modulo 9742

NAF Validation Algorithm (Modulo 97)

Social Security calculates the control digits using Modulo 97 over the 10-digit base:

DV = (parseInt(Province + Sequential) % 97).padStart(2, "0")
  1. 1. Isolate the first 10 digits (2 province + 8 sequential).
  2. 2. Parse the sequence as a 10-digit integer.
  3. 3. Compute the integer remainder modulo 97.
  4. 4. Format the result as a 2-digit zero-padded string.
  5. 5. Compare with the 11th and 12th digits of the NAF.

Frequently Asked Questions & Technical Guidelines