How to Validate Spanish NIF, NIE, CIF and IBAN in Any Programming Language (2026)

If you're building software for the Spanish market, sooner or later you'll need to validate fiscal documents. This guide covers everything: how the algorithms work, code examples in 4 languages, and the fastest way to add validation to any project.

What are NIF, NIE and CIF?

NIF — Tax ID for Spanish individuals (8 digits + 1 letter, e.g. 12345678Z)

NIE — Tax ID for foreign residents in Spain (X/Y/Z + 7 digits + letter, e.g. X1234567L)