Spain (ES)

Spanish VAT Number Validation

Format, pattern, and checksum algorithms for ES VAT numbers

Spanish VAT numbers are the most complex in the EU, with different formats and validation rules depending on whether the entity is a Spanish citizen (DNI), foreigner (NIE), or legal entity (CIF).

Format vs. Active Validation

This checks format only, not if a VAT number is really registered. Use VatDB's API to verify is a number is really registered and active. VatDB checks official EU and national datasources.

Format Overview

Property Value
Country Code ES
Format Letter/digit + 7 digits + letter/digit
Length 9 characters
Examples ESA12345678, ES12345678A, ESX1234567A

Regex Pattern

^ES[A-Z0-9][0-9]{7}[A-Z0-9]$

Types of Spanish VAT Numbers

DNI (Starts with digit) - Spanish Citizens

def validate_dni(number):
    letters = "TRWAGMYFPDXBNJZSQVHLCKE"
    digits = number[:8]
    check = number[8]
    return letters[int(digits) % 23] == check

NIE (Starts with X, Y, Z) - Foreign Residents

def validate_nie(number):
    letters = "TRWAGMYFPDXBNJZSQVHLCKE"
    prefix = {"X": "0", "Y": "1", "Z": "2"}
    digits = prefix[number[0]] + number[1:8]
    check = number[8]
    return letters[int(digits) % 23] == check

CIF (Starts with A-H, J, N, P-W) - Legal Entities

CIF validation uses weighted sums with doubling. The check character can be either a digit or letter depending on the entity type prefix: - K, L, M: Always letter check - A, B, E, H: Always digit check - Others: Can be either

Important Notes

  • Spain has the most complex VAT validation rules in the EU
  • Some Spanish VAT numbers are for domestic use only and won't appear in EU-wide systems
  • The prefix letter indicates the type of entity

Frequently Asked Questions

How do I validate a Spanish VAT number?
Spanish VAT validation depends on the format: DNI (starts with digit) uses MOD 23, NIE (starts with X/Y/Z) converts the prefix then MOD 23, CIF (starts with letter) uses weighted sums. Use VatDB's API for official verification against EU and national databases.
What does a Spanish VAT number look like?
Spanish VAT numbers have format ES + 9 characters. Examples: ESA12345678 (company), ES12345678A (individual DNI), ESX1234567A (foreign resident NIE). The format varies by entity type.
How many characters are in a Spanish VAT number?
A Spanish VAT number always has exactly 9 characters after the ES prefix: typically a letter/digit, 7 digits, and a letter/digit. The total length is 11 characters including ES.
What is the difference between Spanish NIF, CIF, and NIE?
NIF is the tax ID for Spanish citizens (based on DNI). NIE is for foreign residents. CIF was the old name for company tax IDs. All are now officially called NIF but the formats differ based on entity type.
Why is my Spanish VAT number not found when validating?
Some Spanish businesses are registered only for domestic VAT, not for intra-EU trade. VatDB's API checks against both EU and national databases for comprehensive verification.
How do I check if a Spanish company is VAT registered?
Verify VAT numbers using VatDB's API, which checks against official EU and national databases for comprehensive validation including domestic registrations.
What's the difference between format validation and checking if a VAT number is active?
Spain's format rules validate structure only. A properly formatted number might be fabricated or deregistered. VatDB's API queries official records for actual registration confirmation.

Validate Spanish VAT Numbers Instantly

Use our API for real-time ES VAT number validation across all formats

Try Free