Public is not the same as open

28 de noviembre de 2026#open-data#side-projects#learning-in-public

A few weeks ago I needed something that sounds trivial: a list of every postal code in Spain and the municipality it belongs to.

It doesn't exist. Not as open data, anyway.

Correos has it, polygons and all, but it sells it. CartoCiudad used to let you download postal code areas until 2017, then stopped. The INE doesn't publish postal codes at all. What you find online are GeoNames dumps and hand-made tables that break as soon as you leave the provincial capitals. I was even using an AI model to fill the gap, and it kept handing me postal codes that existed but belonged to the next town over.

So the information is everywhere. It's on every letter, every delivery, every form you fill in. And yet if you want it in a file to build something on top of it, you pay. There are companies whose whole business is reselling it.

A lot has changed. Not everything.

Spain is far more transparent than it was ten years ago, and a big part of that is people, not institutions. Jaime Gómez-Obregón has spent years pulling public contracts and spending out of portals and PDFs and making them readable. Civio has been doing data journalism and fighting for access for over a decade. And there's a whole crowd on X scraping, cleaning and publishing what the administration technically already shares but nobody can actually use.

That last part is the key. There's a difference that keeps showing up:

Public means you can look at it. Open means you can take it and use it.

Court rulings are the clearest example. CENDOJ publishes them and you can search and read them one by one. Try to download them in bulk and reuse them, and you run into the terms of use. Meanwhile, legal publishers sell databases with all of them inside. Public, yes. Open, no.

Postal codes are the same story on a smaller scale.

What I built

It turns out the INE already publishes the answer, just not under that name. The electoral census street map (Callejero del Censo Electoral) includes the postal code of every street segment in Spain: 1.5 million of them. Count them and you know which postal codes exist, which municipality each one belongs to and, when a code is shared between towns, how much of it belongs to each.

For coordinates I used Diego Hernangómez's open estimate of postal code areas, built from CartoCiudad addresses. Two sources that have nothing to do with each other, and they agree on 10,711 codes.

The result is codigos-postales-espana:

  • 10,790 postal codes across all 8,132 municipalities
  • 1,864 codes shared by more than one municipality, with the share of each
  • coordinates for 10,711 of them
  • plain CSVs, data under CC BY 4.0, code under MIT
  • one command to rebuild everything when the INE updates the street map (every January and July)

The fun part was the errors. The street map has the odd segment with a postal code from somewhere else, like Tremp, in Lleida, showing up with a code from A Coruña. But you can't just drop everything that crosses a provincial border, because some towns really do use the neighbour's codes. Tresviso is in Cantabria, but its only postal code is Asturian, because the road in comes through Asturias.

It's not Correos' database. PO boxes and codes for big companies or public bodies aren't there. But for normal addresses it covers what you need, and anyone can use it for free, businesses included.

A grain of sand

This dataset won't change much on its own. The people pushing for transparency do the heavy lifting, and most of what's still closed needs laws and institutions to move, not a CSV on GitHub.

But every dataset that goes from public to open is one less thing someone has to buy or rebuild by hand, and one more thing someone can build on. When you stumble on one of those gaps and you have the means to close it, it's worth doing.

If you use it, tell me what you built. And if you know other data that's public but not open, I'd love to hear about it.

← all writing