Spain
Spain Postal Code Format Explained
The Spanish codigo postal explained: five digits, the province prefix from 01 to 52, valid format examples, islands and common input mistakes.
Updated 14 October 2026 · 3 min read
The Spanish codigo postal has five digits, with no letters and no separator. The most useful fact about it is that the first two digits identify the province, so the code tells you where in the country an address lies before you read the town.
Structure
The first two digits are the province number, from 01 to 52, in alphabetical order of the province names. The last three digits identify the delivery area within the province, such as a town, a group of small villages or a district of a city. Examples of the province prefix include 28 for Madrid, 08 for Barcelona and 46 for Valencia. Codes for the Balearic Islands begin with 07, and the Canary Islands use 35 and 38. The autonomous cities of Ceuta and Melilla use 51 and 52.
Because codes are built for mail delivery, a large city has many, and a small village may share a code with neighbouring villages.
Examples of valid format
Generic values that show shape only:
- 12345
- 08123
- 52001
A four-digit or six-digit value is not valid, and neither is a code with a prefix above 52.
Leading zeros
Provinces numbered 01 to 09 produce codes beginning with a zero. This is a legitimate part of the code, and systems that treat it as a number drop the zero. Store it as a five-character text value.
Common mistakes
- Treating the code as a number and losing the leading zero.
- Writing the code after the town, which follows the English order.
- Using a prefix that does not match the province named in the address.
- Adding the letter E or ES before the code on domestic mail.
- Assuming one code per town, when cities have many.
Validation tips
A form can check that the value has five digits and that the first two lie between 01 and 52. Whether a code belongs to a given street needs a lookup, as explained in how to find a Spanish postal code.
How UPCS relates
A UPCS code such as ES-XXXX-XXXX (placeholder) is not a codigo postal. It identifies a 3 m x 3 m cell and can be stored beside the postal code when the exact point matters. Return to the Spain overview or read how Spanish addresses are written.
Frequently asked questions
What do the first two digits of a Spanish postal code mean?
They identify the province, numbered from 01 to 52 in alphabetical order. For example, Madrid uses 28 and Barcelona uses 08.
Can a Spanish postal code start with zero?
Yes. Provinces numbered below 10 give codes that start with 0, so the code must be stored as text.
