UK Postcode Format Explained: How UK Postcodes Work
Razvan Simion, Lead Software Engineer

UK Postcode Format Explained: How UK Postcodes Work
A UK postcode has two parts separated by a single space. The outward code, such as SW1A, identifies the postcode area and district. The inward code, such as 1AA, narrows that district down to a sector and then to a unit, usually a handful of neighbouring addresses. Put together, SW1A 1AA points at one building: Buckingham Palace.
Royal Mail introduced postcodes to sort mail by machine, starting with a trial in Norwich in 1959 and completing the country by 1974. The format has hardly changed since, and once you know its four levels, every UK postcode reads the same way.
The four levels of a UK postcode
Take SW1A 1AA apart from left to right:
| Part | Example | What it identifies |
|---|---|---|
| Postcode area | SW | A large region named after a town or part of London |
| Postcode district | SW1A | A part of that area, the unit of the outward code |
| Postcode sector | SW1A 1 | A group of streets within the district |
| Postcode unit | SW1A 1AA | A street, part of a street or a single large building |
The outward code (area plus district) is what sorting offices use to route mail between delivery offices. The inward code (sector plus unit) is what the delivery office uses to sort mail for individual walks.
The six formats of the outward code
The inward code is always one digit followed by two letters. The outward code is where the variation lives, and there are six shapes in use, where A stands for a letter and 9 for a digit:
| Format | Example |
|---|---|
A9 9AA | M1 1AE |
A99 9AA | B33 8TH |
AA9 9AA | CR2 6XH |
AA99 9AA | DN55 1PT |
A9A 9AA | W1A 0AX |
AA9A 9AA | EC1A 1BB |
So a UK postcode is five to seven characters long, plus the space. The formats with a letter at the end of the district, such as W1A and EC1A, occur in central London, where the original districts were too busy and had to be split.
Postcode areas in the UK
There are around 120 postcode areas. Each is one or two letters, and most are named after the main town in the region: B for Birmingham, M for Manchester, LS for Leeds, G for Glasgow, EH for Edinburgh, CF for Cardiff. London is split into compass-point areas (N, NW, E, EC, SE, SW, W, WC), and the whole of Northern Ireland shares the area BT.
The area letters are a mnemonic, not a boundary. The B area covers far more than the city of Birmingham, and an address's post town, the town in its postal address, is the town of its delivery office, which is not always the town the address is actually in.
Postcode districts
A postcode district is the area plus the number after it: LS1, LS2, LS6. There are about 3,000 of them. Within an area, low numbers often sit near the centre of the main town, but that is a historical tendency and not a rule you can rely on.
Some districts are reserved rather than geographic. Organisations that receive very large volumes of mail can have a district or a postcode of their own, so a postcode does not always correspond to a place you could walk to.
Sectors and units: the inward code
The digit after the space is the sector. The two letters after it are the unit, and the unit is the level that makes a postcode useful: across the UK, about 1.8 million postcode units cover the delivery addresses, around 15 on average and rarely more than 100. A large office building can have a postcode to itself; a residential street may share one across both sides.
The two letters of the unit never include C, I, K, M, O or V, which are left out because they are easily misread, in handwriting or by machines, as other characters.
How do UK postcodes change?
Postcodes are an operational tool of Royal Mail, not an administrative geography. New units are created when new streets are built, units are split or merged when delivery routes change, and old ones are retired. A postcode can also cross a county or local authority boundary.
That has two consequences for anyone storing addresses. A postcode that was valid when a customer entered it can be retired later, and a postcode is not a reliable way to work out which council or county an address belongs to. For that you need a postcode directory, such as the ONS Postcode Directory, that maps each postcode to its administrative areas and keeps the retired ones.
How to write a UK address
Royal Mail's guidance for addressing an envelope is short:
- The recipient's name, or the organisation.
- The building: flat or unit, building name, building number and street.
- The locality, only if it is needed to tell two streets with the same name apart.
- The post town, in capital letters.
- The postcode, on its own line, in capital letters with one space.
For example:
The Occupier
10 Downing Street
LONDON
SW1A 2AAThe county is not required, and has not been part of a postal address since 1996. Adding one does no harm, but leaving it out does not slow delivery either. Punctuation at the line ends is unnecessary. For post sent to the UK from abroad, add UNITED KINGDOM as the final line.
What the format means for address forms
The postcode format is precise enough that it is tempting to validate it with a pattern and stop there. A pattern answers only one question: is this shaped like a postcode? A made-up code with the right letters and digits in the right places passes it. A few real codes also break the pattern, such as GIR 0AA, the historical Girobank postcode, and British Forces Post Office addresses, which use BFPO numbers instead.
Forms that handle UK postcodes well do four things:
- Accept the postcode however it is typed, in lower case or without the space, and normalise it to capitals with one space before the last three characters.
- Check that the postcode exists, not just its shape, and preferably that it matches the street.
- Do not require a county, and allow more than one address line for flats and building names.
- Fill in the rest from the postcode, so the customer types less and makes fewer mistakes.
The last two are where a postcode lookup does the work: the customer gives the postcode and building number, and the form fills in the street and town. Validating an address with one API call covers what such a check returns, and our guide to UK postcode lookup covers the whole process from postcode to full address.
Postcodes and the identifiers behind them
A postcode identifies a group of addresses, not one property. When you need to identify a single property, for example to match your records with council or utility data, the UK has two other identifiers: the UPRN for every addressable location and Royal Mail's delivery-point reference in the Postcode Address File. UPRN and PAF explained covers what each one is and when you need it.
Frequently asked questions
How many characters is a UK postcode?
Five to seven characters, plus a space before the last three. The last three, the inward code, are always a digit and two letters.
What is the outward code of a postcode?
The part before the space. It holds the postcode area (one or two letters) and the district (a number, sometimes followed by a letter), for example SW1A or LS6.
What is a postcode district?
The area letters plus the district number, such as M1 or CR2. There are about 3,000 districts across the UK, and each one is divided into sectors and units.
Does a UK address need a county?
No. Royal Mail has not needed the county since 1996, because the post town and the postcode identify the delivery office.
Is the space in a UK postcode required?
It is part of the official format and belongs in printed addresses. A form should accept the postcode with or without it and add the space itself.
Can I validate a UK postcode with a regular expression?
A regular expression checks the shape only. Use it as a first filter, then check that the postcode exists with a lookup.
Next steps
Pro6PP checks English postcodes against live data and returns the street, town and coordinates behind them. Scotland, Wales and Northern Ireland are not covered at address level yet.
