Spain Postal Codes Dataset
A complete reference of Spanish postal codes (códigos postales) with coordinates and official administrative geography — 11,142 five-digit codes covering all 19 autonomous communities, all 52 provinces and all 8,132 municipalities, as 14,538 postal-code × municipality rows.
Last updated: 2026-08-18 · Rows: 14,538 · Encoding: UTF-8 ·
Primary key: (postal_code, admin_code3)
Every row carries a coordinate, and every row states which granularity that coordinate came from, so a fine point and a coarse one are never confused.
Contents
| File | Description |
|---|---|
es.csv | The dataset (CSV, UTF-8) |
es.zip | The same four files, zipped |
datapackage.json | Machine-readable schema and metadata (Frictionless Data Package) |
validation_report.json | Frictionless validation report, run from inside this folder |
README.md | This document |
Fields
| # | Field | Type | Fill | Description |
|---|---|---|---|---|
| 1 | country_code | string | 100.0% | ISO 3166-1 alpha-2 — always ES |
| 2 | postal_code | string | 100.0% | Five-digit código postal (leading zeros significant) |
| 3 | place_name | string | 100.0% | Municipality name, natural reading order |
| 4 | admin_name1 | string | 100.0% | Autonomous community (comunidad autónoma) |
| 5 | admin_code1 | string | 100.0% | ISO 3166-2:ES community code, ES- stripped (AN, CT, MD …) |
| 6 | admin_name2 | string | 100.0% | Province (provincia) |
| 7 | admin_code2 | string | 100.0% | INE province code (CPRO), 01–52 |
| 8 | admin_name3 | string | 100.0% | Municipality (municipio) |
| 9 | admin_code3 | string | 100.0% | INE municipality code (CPRO+CMUN), five digits |
| 10 | latitude | number | 100.0% | WGS84 / EPSG:4326, decimal degrees, 5 dp |
| 11 | longitude | number | 100.0% | WGS84 / EPSG:4326, decimal degrees, 5 dp |
| 12 | accuracy | string | 100.0% | POSTAL_CODE or MUNICIPALITY — see Coordinates below |
| 13 | alternative_city_name | string | 46.7% | Pipe-separated aliases and localities |
Administrative tiers
Spain nests three tiers, and all three are populated for every row:
- Autonomous community (
admin_name1/admin_code1) — 17 communities plus the autonomous cities of Ceuta and Melilla, 19 in all. The code is the ISO 3166-2:ES community code, so name and code stay one-to-one. - Province (
admin_name2/admin_code2) — 50 provinces plus Ceuta and Melilla. The code is the INECPRO, which is also the postal code's first two digits. - Municipality (
admin_name3/admin_code3) — 8,132 municipalities as of 2026-01-01. The code is the INE five-digitCPRO+CMUN, the standard join key for Spanish statistical, cadastral and electoral data.
Reading the file correctly
postal_code, admin_code2 and admin_code3 are strings with significant leading
zeros. CSV is a typeless format and quoting does not stop a type-inferring reader from
turning "01001" into 1001. Read via the datapackage schema, or force string types:
import pandas as pd
df = pd.read_csv("es.csv", dtype={"postal_code": str, "admin_code2": str, "admin_code3": str})
from frictionless import Package
rows = Package("datapackage.json").get_resource("es").read_rows() # types honoured
Coordinates
accuracy states where each point came from, and there are exactly two tiers:
accuracy | Rows | Meaning |
|---|---|---|
POSTAL_CODE | 14,250 | Resolved for that individual five-digit code by the national geocoder |
MUNICIPALITY | 288 | A PO-box range with no street geography — the point is the median of the per-code points resolved inside its municipality |
Where one code spans several municipalities, each of those rows repeats the code's single representative point — the point belongs to the code, not to the municipality.
Coordinates are WGS84 / EPSG:4326 in decimal degrees, rounded to 5 decimal places (~1.1 m). No coordinate is interpolated or invented, and none is copied from a source that could not be verified; there are no empty cells.
Characteristics worth knowing before you join
One postal code can span several municipalities. 2,108 of the 10,854 codes do, up to
10 municipalities for 09640. That is why the primary key is (postal_code,
admin_code3) and not postal_code alone — joining on the code by itself will fan out.
Conversely a large city holds many codes: Madrid alone has over 200.
The postal prefix follows the serving post office, not the province. In 40 of 14,250
rows the code's first two digits name a different province from admin_code2, and that is
correct, not a defect:
| Postal code | Municipality | Province | Why |
|---|---|---|---|
01118, 01211 | Condado de Treviño | Burgos | a Burgos enclave entirely surrounded by Álava |
50686 | Petilla de Aragón | Navarra | a Navarrese exclave inside Zaragoza |
33554 | Tresviso | Cantabria | its only road reaches the network through Asturias |
22806, 22808 | Murillo de Gállego, Santa Eulalia de Gállego | Zaragoza | served from Huesca |
admin_name2 / admin_code2 always give the municipality's real province. If you
need the routing province instead, take the first two digits of the code.
Shared and communal land is excluded. Spanish cartography codes mancomunidades, parzonerías and communal territories ("Comunidad de Arauzo de Miel y Huerta del Rey") as pseudo-municipalities in a province number that does not exist. 69 such relations were removed. No postal code was lost: every affected code also belongs to a real municipality.
Municipality names use natural reading order. The Spanish statistical register writes
Coruña, A and Madrid, Comunidad de; this dataset ships A Coruña and
Comunidad de Madrid, keeping the register form in alternative_city_name. Bilingual
official names are preserved in full (Alicante/Alacant, Araba/Álava).
Seven recently created municipalities — including Usansolo, split from Galdakao in 2023 — appear in no bulk source and were resolved individually against the official geocoder, each with its own recorded evidence. They share their parent municipality's postal code, which is why the code appears more than once.
PO-box and large-customer ranges are included — 288 codes, mostly XX070, XX071 and
XX080, plus installation-specific codes such as a nuclear plant and an airport. They have
no street geography, so no per-code point exists for them anywhere; each is attached to its
municipality individually, with its own recorded evidence, and carries a MUNICIPALITY
coordinate.
Coverage
| Measure | Value |
|---|---|
| Distinct postal codes | 11,142 |
| Municipalities covered | 8,132 of 8,132 (100%) |
| Provinces covered | 52 of 52 |
| Autonomous communities covered | 19 of 19 |
| Rows with a coordinate | 14,538 of 14,538 (100%) |
| Duplicate primary keys | 0 |
Two independent sources agree on 10,850 of the geographic codes, which is what the coverage claim rests on rather than a single upstream file.
Not included — 12 codes. These are assigned to individual hamlets and installations
(03459 Villa Rosa, 10150 Centro Militar Santa Ana, 15591 Montecoruto, 19131 Pantano
de Entrepeñas, 28851 Parque Corredor del Henares, 34260 Vizmalo, 37467 Villagarcía,
37608 Pedraza de la Sierra, 43518 Sant Llàtzer, 43729 Valdemar, 45489 Quintos del
Pizarro, 50176 Hostal El Ciervo). No open source states which municipality they belong to,
and two of them carry a postal prefix from a different province than the name suggests, so
assigning one would be a guess. They are listed here rather than quietly dropped.
Sources and licence
This dataset is derived from CC BY 4.0 sources and is itself distributed under CC BY 4.0. Attribution is a condition of that licence and must be preserved in onward use:
- Obra derivada de CartoCiudad 2026 CC-BY 4.0 scne.es — postal code ↔ municipality relations and postal-code coordinates, Instituto Geográfico Nacional / CNIG, under Orden FOM/2807/2015.
- Elaboración propia con datos extraídos del sitio web del INE: www.ine.es — Relación de municipios y sus códigos por provincias, updated 2026-01-01. The Instituto Nacional de Estadística neither participates in nor endorses this dataset.
- © GeoNames, CC BY 4.0 — independent cross-check and locality names.
No data from share-alike sources (OpenStreetMap, Wikipedia) was used at any point, so nothing here is encumbered by ODbL or CC BY-SA.