Generate one random UK postcode or five hundred. Every outward code is a genuine Royal Mail district drawn from 57 post towns across 60 postcode areas; the inward code is generated to the official format rules, so results validate without being live delivery points.
A UK postcode is an alphanumeric code, five to seven characters long, that identifies a group of delivery points. Royal Mail introduced them nationally between 1959 and 1974, and there are now around 1.8 million of them. A full postcode covers about fifteen properties on average, which is precise enough that a postcode plus a house number identifies a single address — the reason UK address lookup works the way it does, and something a US ZIP code cannot do.
Postcodes are a postal routing system first and a geography second. They do not align with county or council boundaries, a postcode area can cross a national border, and the post town in an address is a sorting designation rather than a statement about which town the property is in.
Every postcode splits into two halves separated by a single space. The outward code routes mail to the sorting office; the inward code routes it from there to the street.
Six formats are valid and no others, which is what makes UK postcodes checkable without a database lookup. In the patterns below, A stands for any permitted letter and 9 for any digit; the outward code varies between two and four characters while the inward code is always a digit followed by two letters.
One postcode sits outside all six: GIR 0AA, issued to the National Girobank in Bootle. It is still valid and still catches out validation code that only implements the general rules.
The four levels nest, each one narrowing the delivery target further, and each is a prefix of the next. Knowing which level you actually need matters when you store postcodes: an analytics rollup usually wants the district, a delivery-zone rule wants the sector, and only address matching needs the full unit. Taking SW1A 1AA — Buckingham Palace — apart from the outside in:
Not every letter can appear in every position. The exclusions exist because postcodes were designed to be read by early optical character recognition and handwritten by the public, so letters that are easily confused with digits or with each other were removed from the positions where the confusion would matter. Any validator that ignores these rules will accept postcodes that cannot exist.
The generator applies all five rules, so every postcode it produces will pass a correctly written UK postcode validator. Whether a validator accepts them is, in practice, a useful test of the validator.
| UK postcode | US ZIP code | |
|---|---|---|
| Characters | 5–7, letters and digits, one internal space | 5 digits, or 9 as ZIP+4 |
| Example | EC1A 1BB | 10001 |
| How many | About 1.8 million full postcodes | About 41,000 ZIP codes |
| Precision | Around 15 delivery points | A delivery route, town or city district |
| Identifies an address? | Yes, with a house number | No, the full street address is needed |
| Structure | Area, district, sector, unit | National area, sectional centre, delivery area |
| Case and spacing | Conventionally upper case with one space; both are significant to some validators | Digits only, no spacing question |
| Changes | New districts and units are added as areas develop | Boundaries are redrawn by USPS as volume shifts |
The size difference is the one that matters when porting software: a database column sized for five characters, a numeric column type, or a regex of ^\d{5}$ will all reject valid UK postcodes.
The outward code — the half before the space — is a real Royal Mail postcode district taken from the registry, so the area, district and post town are genuine. The inward code after the space is generated to the official format rules. The result is a structurally valid postcode that is not a live delivery point, which is exactly what you want in test data: it validates, but it cannot be mistaken for a real address.
Yes, if the validator implements the published rules. Every generated postcode uses one of the six valid formats and respects the excluded letters at each position. A regex or library that follows the UK Government Data Standards Catalogue definition will accept them. A lookup against Royal Mail’s Postcode Address File will not find them, because they are not assigned.
Yes. Filter by country — England, Scotland, Wales or Northern Ireland — or narrow to a single post town, and every postcode will come from a district that town genuinely serves. The result table shows the area, district, sector and format for each one.
Up to 500 in the browser, and up to 1,000 per request through the free REST API at /api/v1/postcodes/random. No API key or sign-up is required.
They nest from broad to narrow. In SW1A 1AA, the area is SW, the district is SW1A, the sector is SW1A 1, and the unit is the whole postcode. The area routes to a region, the district to a sorting office, the sector to a few streets, and the unit to about fifteen delivery points.
Those are the A9A and AA9A formats, used where a district needed subdividing after the original allocation. They are concentrated in central London — W1A, EC1A, SW1A — and they are the formats most often broken by validation code that assumes the outward code ends in a digit.
Yes. It was issued to the National Girobank in Bootle and remains valid. It fits none of the six standard formats, so it has to be special-cased. It is a good test of whether a validator was written from the specification or from a guess.
Yes, with no attribution required — in commercial software, open-source projects, QA pipelines and staging databases. They must not be used to imply a real address or for identity verification.
Postcodes are generated on demand and never stored. They are for software testing and development only, and must not be used to imply a real address or for identity verification.