Random UK Postcode Generator

A UK postcode generator produces structurally valid postcodes that follow the Royal Mail format rules, using real postcode districts and generated inward codes.

Every postcode uses a genuine outward code from the district registry — M20, EH8, BT7, CF10 — combined with a generated sector and unit that obey the structural rules, including the excluded letters (no Q, V or X first, no I, J or Z second, and no C, I, K, M, O or V in the final pair). Results show the area, district, sector and which of the six permitted formats each postcode matches.

Options

NameTypeDefaultDescription
countinteger10How many records to return, from 1 to 1000.
countryenumRestrict to one UK country.
locationstringPost-town slug.
areastringPostcode area, for example "BT" or "M".
seedintegerOptional. Any integer. The same seed with the same options always returns the same records.

Use cases

  • Regex and validator testing: Feed valid postcodes of all six formats into your validation logic, including the AA9A and A9A shapes that most home-grown patterns reject.
  • Search and autocomplete fixtures: Populate a postcode search box or lookup mock with realistic values across all four UK countries.
  • Analytics and reporting samples: Produce district and sector level sample data for dashboards without using customer postcodes.

REST API

GET /api/v1/postcodes/random

curl "https://ukaddressgenerator.org/api/v1/postcodes/random?count=10&country=Wales"
{
  "status": "success",
  "count": 2,
  "data": [
    { "postcode": "EH8 3RY", "outwardCode": "EH8", "inwardCode": "3RY", "area": "EH", "district": "EH8", "sector": "EH8 3", "format": "AA9", "postTown": "EDINBURGH", "county": "City of Edinburgh", "country": "Scotland" },
    { "postcode": "BT7 2LN", "outwardCode": "BT7", "inwardCode": "2LN", "area": "BT", "district": "BT7", "sector": "BT7 2", "format": "AA9", "postTown": "BELFAST", "county": "County Antrim", "country": "Northern Ireland" }
  ]
}

Frequently asked questions

Are these real postcodes?

The outward code is real. The inward code is generated, so the full postcode is valid in format but is not a live delivery point and will not appear in a Postcode Address File lookup.

Which postcode formats are covered?

All six: A9 9AA, A99 9AA, A9A 9AA, AA9 9AA, AA99 9AA and AA9A 9AA, drawn from the districts present in the registry.

Can I generate Northern Ireland postcodes?

Yes. Filter by country or select the BT postcode area, which covers the whole of Northern Ireland.

Related tools