Spain utilizes a comprehensive system of tax identification numbers with multiple formats depending on whether the taxpayer is a Spanish citizen, foreign resident, or legal entity. Understanding the distinctions between NIF, NIE, CIF, and how these relate to Spanish VAT numbers is essential for anyone doing business in Spain or trading with Spanish companies. This guide explains each identifier type, their formats, validation rules, and the process for obtaining them.
The Spanish tax identification system integrates personal and corporate identification for tax purposes. The NIF (Número de Identificación Fiscal) serves as the umbrella term for tax identifiers, encompassing both the DNI-based numbers for Spanish citizens and the NIE for foreign residents. For companies, the former CIF designation has been absorbed into the NIF system, though the term CIF remains in common usage. Spanish VAT numbers for EU purposes add the ES prefix to these domestic identifiers.
The Spanish VAT number for EU intra-community purposes consists of the country prefix ES followed by the domestic NIF. The resulting format varies depending on the type of entity, creating multiple valid patterns that validation systems must accommodate. Spanish VAT numbers can begin with a letter, a digit, or specific letter combinations depending on whether the holder is an individual, company, or foreign entity.
For Spanish companies, the format is ES followed by a letter identifying entity type, seven digits, and a check character. For Spanish individuals, the format is ES followed by eight digits and a check letter derived from the DNI. For foreign residents with NIE, the format is ES followed by a letter (X, Y, or Z), seven digits, and a check letter. This variety of formats makes Spanish VAT validation more complex than countries with single uniform formats.
Company Format: ES + letter + 7 digits + letter/digit
Individual Format: ES + 8 digits + letter
Foreign Resident Format: ES + letter (X/Y/Z) + 7 digits + letter
Total Length: 11 characters
Spanish citizens use their DNI (Documento Nacional de Identidad) number as their NIF for tax purposes. The DNI consists of eight digits followed by a check letter calculated from the numeric portion. The check letter is determined by dividing the eight-digit number by 23 and using the remainder as an index into a specific letter sequence (TRWAGMYFPDXBNJZSQVHLCKE). This algorithm enables validation of any Spanish personal NIF.
The format appears as eight digits plus one letter, making the total nine characters. When used as a VAT number, the ES prefix is added, creating an eleven-character identifier. The check letter provides strong validation capability, as any transcription error in the digits will typically produce an incorrect check letter, immediately identifying the error.
Format: 8 digits + check letter
Example: 12345678Z
Check Letter: Calculated as DNI mod 23, mapped to letter sequence
VAT Format: ES12345678Z
Foreign residents in Spain receive a NIE (Número de Identificación de Extranjero) which serves as their tax identification number. The NIE format begins with a letter (X, Y, or Z depending on when issued), followed by seven digits and a check letter. The check letter is calculated similarly to the DNI, but with the initial letter converted to a digit first (X=0, Y=1, Z=2) before applying the modulo 23 algorithm.
The format produces nine characters: one letter prefix, seven digits, and one check letter. Like the DNI-based NIF, the NIE becomes a Spanish VAT number when prefixed with ES. NIE numbers are essential for any foreign national conducting economic activity in Spain, whether as an employee, self-employed person, or property owner.
Format: Letter (X/Y/Z) + 7 digits + check letter
Example: X1234567L
Check Letter: Same algorithm as DNI after letter-to-digit conversion
VAT Format: ESX1234567L
Spanish legal entities receive a NIF that was formerly called CIF (Código de Identificación Fiscal). Though officially replaced by NIF terminology, CIF remains widely used in practice. The company NIF begins with a letter indicating entity type, followed by seven digits and a check character that may be either a letter or digit depending on the entity type.
The first letter identifies the type of organization: A for public limited companies (Sociedad Anónima), B for private limited companies (Sociedad Limitada), and other letters for various entity types including cooperatives, foundations, and branches of foreign companies. This prefix immediately reveals organizational form when examining a Spanish company tax ID.
Format: Letter + 7 digits + letter/digit
Example: B12345678, A12345678
Entity Type Letters: A (SA), B (SL), C (general partnership), D (limited partnership), E (community of owners), F (cooperative), G (association), H (community of property), J (civil society), N (foreign entity), P (local corporation), Q (public body), R (religious congregation), S (government body), U (temporary business union), V (other), W (permanent establishment of non-resident)
Spanish individuals and companies register for VAT through the Agencia Tributaria (Tax Agency). Registration involves submitting Form 036 or 037 (simplified version) to declare the commencement of economic activities. For entities already holding a NIF, registration adds VAT obligations to their existing tax profile. New entities receive their NIF as part of the formation process through the Registro Mercantil (Commercial Registry).
Foreign businesses seeking Spanish VAT registration apply through the appropriate tax office depending on whether they have a fixed establishment in Spain. Non-EU businesses typically require a fiscal representative. EU businesses can usually register directly without representation. The process requires documentation about business activities, expected Spanish operations, and proof of business existence in the home country.
The registration process timeline varies based on complexity. Straightforward registrations for existing Spanish entities may process within days. Foreign entity registrations take longer, particularly when fiscal representation arrangements must be established. Complete and accurate initial documentation significantly accelerates the process.
Spanish VAT numbers can be verified through the European VIES system. The varied format patterns mean validation must account for multiple acceptable structures. VIES confirmation indicates the number is registered and provides the associated name. Cross-referencing with Spanish business registers provides additional verification for companies.
Format validation for Spanish VAT numbers requires pattern matching against all valid formats. The first character after ES determines which format rules apply. Numbers beginning with letters A-Z (except X, Y, Z) follow company format rules. Numbers beginning with digits follow individual format rules. Numbers beginning with X, Y, or Z follow NIE format rules. Each pattern has its own check character calculation.
The check character algorithms enable mathematical validation. For individuals, dividing the eight-digit portion by 23 and mapping the remainder to the letter sequence verifies the check letter. For NIE, converting the initial letter to a digit first (X=0, Y=1, Z=2) then applying the same algorithm works. Company check character algorithms vary by entity type and are more complex.
Spain requires VAT registration for businesses conducting taxable activities above minimal thresholds. The régimen simplificado (simplified scheme) provides alternatives for certain small businesses, but most commercial activities require standard VAT registration. Self-employed individuals (autónomos) conducting business must register for VAT alongside their social security obligations.
Foreign businesses making taxable supplies in Spain face registration requirements that vary by supply type. Distance sales to Spanish consumers trigger registration once thresholds are exceeded. B2B services may fall under reverse charge mechanisms, avoiding Spanish registration needs. Specific activities like real estate transactions and certain domestic supplies require Spanish registration regardless of establishment status.
The multiple valid formats for Spanish VAT numbers cause validation challenges. Systems expecting uniform formats will incorrectly reject valid Spanish numbers. Ensure validation logic handles letter-first (companies), digit-first (individuals), and X/Y/Z-first (NIE) patterns as all valid Spanish VAT number structures.
Confusion between NIF and CIF terminology persists despite official consolidation under NIF. Business partners and documents may use either term when referring to company tax identification. Functionally, they refer to the same identifier. Accept both terms as referring to Spanish company tax identification.
Check character verification is valuable but requires format-specific implementation. The algorithm differs between individuals, NIE holders, and various company types. Implementing comprehensive Spanish validation requires multiple algorithm branches based on the format detected from the first character.