The format for the vast majority is <Letter>[Optional <Letter> <Digit>[optional <Digit>] <space> <Digit><Letter><Letter>
The initial (usually 2 but occasionally 1) letters indicate the postal region.
Each postal region is split into a number of zones, numbered sequentially.
This is followed by a space (to separate the zone from the next number)
There is then an area digit (1 - 9), to further restrict the location.
Finally there is a two-letter "Walk" designator which is a group of adjacent addresses. In a town, this would typically be one side of a street (the route the postman walks to drop off the mail) in rural areas, it might be an entire road or just a part thereof.
As an example, my postcode is "RH12 3DJ"
The Postal Town is Rehill in Surrey (which is where the main sorting office was when postcodes started).
We are in Zone 12 (Horsham and the villages to the West)
Area 3 is my village (Rudgwick)
We are walk DJ (the southern side of the North-Eastern end of Lynwick Street - 12 houses and 1 farm). The opposite side of the road is "DG" (22 houses). In the middle of "DG" is also the local Brickworks with its own dedicated postcode (DH). The Southwestern end of the road is DL (2 Farms with 8 dwellings) and DN (8 houses).
That way, the postcode drills down to a small group of addresses, so in theory a house name or number and postcode are sufficient to get there. Often (if the postman knows you, as ours in the village do) a name and postcode would be sufficient.
The most interesting part about them is that public money is used to create maintain the database, but the public does not have direct access to it... other than a 1 at a time look up on royal mail's site, with a limit to 15 lookups a day...
Also be advised that post codes may not always be immutable. I have noticed post code structures in certain towns such as Reading to change over time. If anyone needs UK post codes PM me.
I have 1.8 million in csv format
The GB postcode data is actually freely available for the public to download under the OpenData program.
It is called Code Point - Open and is maintained by ordnance survey
The data includes every postcode (there are about 1.7 million of them) and the NHS codes and Admin districts and a few other bits and pieces.
The only problem is that the data comes with Northing and Eastings rather than Longitude and Latitude. The reasoning behind this is that the data is maintained by Ordnance Survey who are responsible are also responsible for mapping GB.
Please also note that this only covers England, Scotland and Wales as they are part of GB but the Channel Islands and Northern Ireland which are part of the UK but not GB have there own mapping and postal systems.
All the postcodes for Northern Ireland start with BT (for Belfast) and are looked after by Ordnance Survey Northern Ireland. Northern Ireland data is available but there seems to be a fee attached to this as the Open Data law does not apply in Northern Ireland.
There are a few different scripts around only (particularly in PHP) that will convert Northing and Easting into Latitude and Longitude which will make it usable for POI.
Can you please comment on how each house/building address is mapped to UK postal codes? Postal code code can only give the spread on map but how each house /building address is mapped to these postal codes? Thanks