Everyday Tools

UK Postcodes: How They Are Built and How to Validate and Clean a List

How UK postcodes are structured, which letters are allowed, how to format them correctly and how to clean a spreadsheet column of postcodes.

Saizul Amin
Saizul Amin23 Oct 2026 · 3 min read
UK Postcodes: How They Are Built and How to Validate and Clean a List

UK Postcodes: Structure and Validation

A postcode is the shortest way to describe an address in the UK, and it is also one of the most frequently mistyped. Lower case, missing spaces, a letter O instead of a zero: they all happen. The UK Postcode Format Validator checks and cleans them, one by one or in a list.

The two halves

A postcode has an outward code and an inward code, separated by a space. The inward code is always the last three characters: one digit and two letters. The outward code is the front part and has the postcode area (one or two letters), then a district made of a digit or two digits, or a digit followed by a letter. Examples: SW1A 1AA, M1 1AE, B33 8TH, CR2 6XH, DN55 1PT, W1A 1HQ and EC1A 1BB.

The parts in detail

  • Area: the letters at the start, such as M for Manchester or EC for East Central London.
  • District: the number (and sometimes a letter) after the area, such as 1A in SW1A.
  • Sector: the district plus the first character of the inward code, such as SW1A 1.
  • Unit: the last two letters, identifying a group of addresses or a single large user.

Rules for the letters

The first position cannot be Q, V or X. The second position cannot be I, J or Z. In the last two letters, C, I, K, M, O and V are not used. The special code GIR 0AA, from the former Girobank, is valid. The rules came from the need to avoid confusion in sorting and handwriting.

What the tool does

It removes spaces and fixes the case, tests the length (5 to 7 characters without a space), checks the inward code against the pattern of a digit followed by two permitted letters and the outward code against the six permitted shapes (A9, A99, AA9, AA99, A9A, AA9A). For valid codes it shows the correctly spaced form and splits the code into outward code, area, district, sector and unit. It checks format only; it cannot know if the postcode is in use.

Cleaning a list

Copy a column of postcodes from a spreadsheet and paste them in the box, one per line. The table shows each result, the formatted postcode and the failing rule for errors. Export the table as CSV or copy only the valid ones back. This works well for a customer list, a mailing, a donor database or a form where users type their own codes.

Examples

m1 1ae becomes M1 1AE: area M, district 1, sector M1 1, unit AE. EC1A1BB becomes EC1A 1BB. Q1 1AA fails because Q cannot be the first letter. 123 456 fails because there are no letters. B33 8TH is valid with area B and district 33.

Format does not mean existence

A postcode can pass the check and not exist. New codes are created and old ones retired. To check that an address exists you need the Royal Mail Postcode Address File, which is licensed data. This tool does not look anything up, and nothing you type leaves your browser.

Tips for forms

On a web form, accept lower case, strip spaces, then validate and show the standard form back to the user. Do not reject valid but unusual codes, such as those with letters in the district. Allow the special code GIR 0AA if you serve businesses.

Limits

British Forces Post Office codes, overseas territories and Crown Dependencies follow other rules. The tool is a format check and not an address lookup.

Quick answers

Why do some postcodes have a letter in the district? In central London and a few other places there are more districts than digits, so a letter is added, as in W1A or EC1A.

Should I store postcodes in capitals? Yes, with the space, which makes sorting and matching easier.

Can I use the code to find a town? The area letters identify a region, but only a licensed database can map a full postcode to an address.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages