What you want is available in the UK Data Service website. The link has files containing every single postcode and the "Census built-up area" (BUA) to which it belongs. As the User Guides (February 2015) state:
England and Wales:
Built-up areas and built-up area sub-divisions were created as part of the 2011 Census outputs and provide information on villages, towns and cities, allowing comparisons between people living in built-up areas and those living elsewhere. Previously called urban areas, data has been produced every 10 years since 1981. A new methodology to capture the areas was used in the 2011 version, but it still follows the rules used in previous versions so that results will be broadly comparable.
Scotland and Northern Ireland:
This data is not yet available.
The data comes in a massive .csv
file where the BUA column has codes like E35000003
and E35001670
. The city, town or village to which these codes belong are available in an associated file, both as .txt
and .csv
.