Spain is the EU's fourth-largest economy and one of the most challenging EU VAT number formats to validate correctly. The Spanish NIF (Número de Identificación Fiscal) — also referred to as CIF for company entities — uses a variable-character format where the first and last positions can be letters or digits, and the leading letter encodes the type of legal entity. This makes Spain one of the few EU countries where format validation alone cannot determine the entity type without parsing the structure. This guide covers the complete format, what the leading character means, the VIES behaviour specific to Spain, and complete code examples.
Note
Spanish VAT numbers (Número de Identificación Fiscal — NIF) are issued and managed by the Agencia Tributaria (AEAT). VIES routes Spanish validation requests to the AEAT system in real time. Spain participates fully in the EU VIES system.
The Spanish VAT Number Format (NIF)
A Spanish VAT number consists of the prefix ES followed by 9 characters: one character (letter or digit), then exactly 7 digits, then one final character (letter or digit) — 11 characters in total. The simplified regex is ^ES[0-9A-Z][0-9]{7}[0-9A-Z]$. Valid examples include ESA12345678 (a corporation), ESX1234567T (a foreign entity with NIE), and ES12345678Z (a sole trader).
The first character after ES encodes the legal entity type. For Spanish corporations (sociedades), it is always a letter from a specific set: A = Sociedad Anónima (S.A.), B = Sociedad de Responsabilidad Limitada (S.L.), C = Sociedad Colectiva, D = Sociedad Comanditaria, E = Comunidad de Bienes, F = Sociedad Cooperativa, G = Asociación, H = Comunidad de Propietarios, J = Sociedad Civil, N = Non-resident entity, P = Local body, Q = State or public body, R = Congregation or religious entity, S = State administration body, V = Other entity types, W = Permanent establishment of non-resident. For individual Spanish entrepreneurs (autónomos), the first character is a digit (the first digit of their DNI/NIF personal number). For foreign individuals with a NIE, the prefix is X, Y, or Z.
The final character is always a check character — either a digit or a letter depending on the entity type. For entities with a leading letter (corporations), the last character is a letter. For entities with a leading digit (individuals and autónomos), the last character is also a digit. The check character is computed algorithmically from the 7-digit middle section. The TaxID API performs full check character validation before making the VIES call.
| Property | Value |
|---|---|
| Prefix | ES |
| Total length | 11 characters (ES + 9 chars) |
| Format | ES + 1 char (letter or digit) + 7 digits + 1 char (letter or digit) |
| Example (company) | ESA12345678 |
| Example (individual/autónomo) | ES12345678Z |
| Regex | ^ES[0-9A-Z][0-9]{7}[0-9A-Z]$ |
| VIES country code | ES |
| National authority | Agencia Tributaria (AEAT) |
| Local name | Número de Identificación Fiscal (NIF) / CIF for companies |
Common Spanish VAT Format Errors
- →Missing ES prefix: 'A12345678' instead of 'ESA12345678' — the most common error.
- →Submitting the DNI instead of NIF: the DNI (Documento Nacional de Identidad) is a personal identity document number, not a VAT number in isolation. Autónomos use their DNI-based NIF as their VAT number, but it must have the ES prefix.
- →Submitting the NIE without prefix: NIE numbers (for foreigners) start with X, Y, or Z followed by 7 digits and a letter. These are valid Spanish VAT numbers but need the ES prefix: ESX1234567T.
- →Wrong check character: the final character is computed. A number with the correct structure but wrong check character fails check digit validation at the TaxID API level before consuming quota.
- →Lowercase: 'esa12345678' — normalise to uppercase before validation.
- →Spaces or separators: some invoices format as 'ES A-1234567-8' — strip all non-alphanumeric characters.
- →Canary Islands / Ceuta / Melilla: businesses based in these territories use the IGIC (Canarias) or IPSI systems, not standard Spanish VAT. They do not have EU VAT numbers and cannot be validated via VIES.
Spanish Company Types and VAT Registration
The dominant legal forms for Spanish B2B customers are S.L. (Sociedad de Responsabilidad Limitada — the most common form for SMEs and startups, equivalent to a GmbH or LLC, NIF starts with B), S.A. (Sociedad Anónima — public company, NIF starts with A), and autónomo (self-employed sole trader, NIF is their personal DNI-based number starting with a digit). Spanish startups almost universally use the S.L. form. NIF numbers starting with B (S.L.) are the most common you will encounter from Spanish B2B SaaS customers.
Spanish autónomos (freelancers) are fully VAT-registered unlike French auto-entrepreneurs — there is no revenue threshold exemption. An autónomo with a VAT number can receive reverse charge treatment. However, some autónomos apply for a simplified VAT regime (recargo de equivalencia) if they sell goods to final consumers — these businesses charge higher VAT rates to their B2C customers and cannot reclaim input VAT. This is irrelevant for B2B reverse charge purchases you make from them, but affects invoices they issue to final consumers.
VIES and Spain's AEAT: What to Expect
Spain's AEAT VIES endpoint is one of the less reliable in the EU, with above-average downtime and slower response times compared to Germany or France. AEAT system maintenance is common on weekends and Spanish public holidays (which are numerous — each region also has regional holidays). Response times for live lookups typically range from 400ms to over 1 second. During peak periods like quarterly VAT filing deadlines (last business day of January, April, July, October), AEAT response times degrade significantly.
Spain generally returns company name via VIES for corporate entities. Address data is returned less consistently. For autónomo (individual) NIF numbers, VIES typically returns the individual's name rather than a business name. Use the returned name on invoices for compliance, but note that autónomo VAT numbers will show the individual's personal name rather than any trading name they may use. Spanish VAT validation via TaxID caches active results for 24 hours and handles the allow-and-re-validate pattern automatically for service_unavailable responses.
Spanish VAT Rates
Spain applies a standard VAT rate of 21% (IVA — Impuesto sobre el Valor Añadido) to most goods and services. A 10% reduced rate applies to food and beverages for human consumption, passenger transport, hotel accommodation, and certain construction services. A super-reduced rate of 4% applies to essential food staples (bread, milk, eggs, cheese, fruit, vegetables), books and newspapers, pharmaceuticals, and certain social and educational services. Spain also applies a 0% rate to specific categories including some financial services.
For SaaS and digital services sold to Spanish consumers (B2C), the applicable rate is 21%. For Spanish B2B customers with a valid NIF, zero-rate reverse charge applies. Note that Canary Islands businesses use IGIC (Impuesto General Indirecto Canario) at 7% standard rate, not IVA — they do not have EU VAT numbers, so VIES validation is not applicable for Canarian customers.
Code Examples
cURL
# Validate a Spanish VAT number (NIF)
curl https://taxid.dev/api/v1/validate/ES/ESB12345678 \
-H "Authorization: Bearer YOUR_API_KEY"
# Expected response:
# {
# "valid": true,
# "status": "active",
# "vat": "ESB12345678",
# "country_code": "ES",
# "company_name": "Ejemplo S.L.",
# "address": "Calle Mayor 1, 28001 Madrid",
# "cached": false,
# "request_id": "req_01j..."
# }Node.js / TypeScript
export async function validateSpanishVat(vatNumber: string): Promise<{
valid: boolean;
companyName: string | null;
address: string | null;
status: string;
}> {
const normalised = vatNumber.replace(/\s/g, '').toUpperCase();
// ES + 1 char (letter or digit) + 7 digits + 1 char (letter or digit)
if (!/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(normalised)) {
return { valid: false, companyName: null, address: null, status: 'format_invalid' };
}
const res = await fetch(
`https://taxid.dev/api/v1/validate/ES/${normalised}`,
{
headers: { Authorization: `Bearer ${process.env.TAXID_API_KEY}` },
signal: AbortSignal.timeout(8000), // AEAT can be slower than other VIES endpoints
}
);
const data = await res.json();
return {
valid: data.valid,
companyName: data.company_name,
address: data.address,
status: data.status,
};
}Python
import re, os, requests
from dataclasses import dataclass
from typing import Optional
# ES + 1 char (letter or digit) + 7 digits + 1 char (letter or digit)
ES_PATTERN = re.compile(r'^ES[0-9A-Z][0-9]{7}[0-9A-Z]$')
@dataclass
class SpanishVatResult:
valid: bool
company_name: Optional[str]
address: Optional[str]
status: str
def validate_spanish_vat(vat: str) -> SpanishVatResult:
normalised = vat.replace(' ', '').upper()
if not ES_PATTERN.match(normalised):
return SpanishVatResult(False, None, None, 'format_invalid')
r = requests.get(
f'https://taxid.dev/api/v1/validate/ES/{normalised}',
headers={'Authorization': f'Bearer {os.environ["TAXID_API_KEY"]}'},
timeout=8,
)
r.raise_for_status()
d = r.json()
return SpanishVatResult(
valid=d['valid'],
company_name=d.get('company_name'),
address=d.get('address'),
status=d['status'],
)Frequently Asked Questions
- →What is the difference between NIF and CIF? CIF (Código de Identificación Fiscal) was the old name for the Spanish company VAT number. It was renamed NIF in 2008. They are the same number — CIF is still commonly used colloquially for company VAT numbers.
- →Is ES always the VIES code for Spain? Yes. Spain uses ES as its ISO code and VIES prefix.
- →Can a Spanish autónomo receive reverse charge treatment? Yes. Spanish autónomos are fully VAT-registered (no exemption threshold unlike France). They can receive zero-rate reverse charge treatment if their NIF validates successfully via VIES.
- →What if a customer says they are in the Canary Islands? Canary Islands businesses are not in the EU VAT area. They use IGIC, not IVA, and do not have EU VAT numbers. You cannot validate them via VIES and should charge at the applicable rate based on your B2C obligations.
- →Why does Spain's VIES take longer? The AEAT system is one of the slower VIES endpoints. Use a timeout of at least 8 seconds for Spanish validations and always implement service_unavailable handling — AEAT downtime is more frequent than most EU members.
Validating Spanish VAT Numbers at Scale
Spain's above-average VIES unreliability makes the caching and allow-and-re-validate patterns particularly important at scale. For platforms with significant Spanish B2B customer bases, consider increasing your re-validation interval — re-validating Spanish numbers more frequently than every 90 days adds little compliance value given the AEAT's consistency. Store the request_id from each API response. For the complete format reference and live validator, see validate-vat/es.
Related pages on taxid.dev
Format reference, NIF structure guide, and code examples for Spain
Standard (21%), reduced (10%), and super-reduced (4%) IVA rates
All 27 EU member states, VIES architecture, and compliance guide
Essential for Spain — AEAT has above-average VIES downtime
Another major EU market with above-average VIES downtime
Start validating EU VAT numbers
Free plan — 100 validations/month. No credit card required.