Geohash Encoder and Decoder Guide: Turn Coordinates Into Short Codes
A pair of coordinates is precise, but it is not friendly. Latitude and longitude are two long decimal numbers, easy to mistype, easy to transpose, and awkward to paste into a short message, a filename, or a database key. A geohash solves the packaging problem: it turns that pair into a single short string, such as u4pruydqqvj, that still points at a recognisable patch of ground. The Geohash Encoder and Decoder lets you convert in both directions, so you can see exactly what a code means and what a pair of coordinates becomes when it is packed this way. It is a format tool, not a map and not a survey instrument, and understanding that boundary is what makes it useful rather than misleading.
The idea behind a geohash is interleaving. Latitude and longitude are each converted to binary, and the bits are woven together, alternating longitude and latitude, before being grouped into base-32 characters. The characters used are the digits 0 to 9 plus a set of lowercase letters, with a, i, l, and o left out because they look too much like digits. The result reads like a short password, but every character carries real geographic meaning: the first character places the point in one of 32 large regions of the world, and each following character divides the remaining rectangle into 32 smaller rectangles and picks one. That is why a geohash is a prefix code. Two places that share a long prefix sit inside the same small box, while two places that differ early sit in different large regions.
Length is the precision control, and it is the single most misunderstood part of the format. A one-character geohash covers an area thousands of kilometres wide. A five-character code narrows that to roughly a neighbourhood, a few kilometres across. An eight-character code narrows it to a street-sized rectangle, tens of metres across, and a twelve-character code narrows it to a few centimetres. Longer is not automatically better, though. Extra characters beyond the accuracy of your original measurement add false precision: they suggest you know a location to the centimetre when your phone or your source data only knew it to the nearest hundred metres. Choose a length that matches the job. A city guide needs five or six characters; a delivery bay needs eight or nine; anything longer belongs in a specialised system, not a shared message.
How encoding and decoding actually work
Encoding starts with two numbers: latitude, which runs from minus 90 at the South Pole to plus 90 at the North Pole, and longitude, which runs from minus 180 to plus 180. Feed them in that order, latitude first, because that is the convention the tool and almost every mapping system expects. The tool then interleaves the bits and returns the string. Decoding reverses the process: it unpacks the characters into bits, separates them back into latitude and longitude ranges, and returns the centre of the resulting rectangle together with its size. That centre is an estimate, not the original point. If you encode a point and then decode the code, you get back a point very close to the original, but not necessarily identical, because the code only ever stored a box, not the exact coordinates.
This box behaviour explains the most famous geohash quirk. Two places a few metres apart can have completely different codes if a grid boundary runs between them, because they fall in different boxes at some level of division. Conversely, two codes that look similar are close together, but the reverse is not guaranteed. Never use string similarity as a distance measure. If you need real distances, pair the tool with the Distance between Two Lat Long tool, which computes the gap between two coordinate pairs properly, and read the companion guide on Distance between Two Lat Long before trusting any shortcut. For a different kind of coordinate work, the IP and CIDR Subnet Calculator shows the same lesson in another domain: a compact code is only useful when you know exactly what it encodes.
Worked example
Take a sample location in central London, using clearly labelled sample values rather than a claim about any real address: latitude 51.5074, longitude minus 0.1278. Encoding that pair at length eight gives the code gcpvj0du, and decoding gcpvj0du returns a centre near latitude 51.5074 and longitude minus 0.1278, inside a rectangle roughly 38 metres wide by 19 metres tall. The arithmetic of precision is visible in the step from length seven to length eight. At seven characters the rectangle is about 153 metres by 153 metres; adding one character divides it into 32 smaller rectangles, so the width falls to about 38 metres, since 153 divided by 4 is roughly 38, and the height falls to about 19 metres, since 153 divided by 8 is roughly 19. Each character does not shrink the box evenly in both directions, because the bit interleaving alternates, but the direction is always the same: smaller, never larger.
Now shorten the same code to five characters, gcpvj. Decoding that gives a much larger rectangle, several kilometres across, whose centre is still in the same part of London but could be kilometres from the original point. The lesson is practical. If you share a five-character code for a meeting point, your friend may arrive in the right district but not at the right door. If you share an eight-character code, they arrive at the right building. And if you accidentally swap the pair and encode longitude first, latitude minus 0.1278 and longitude 51.5074, you land in the Atlantic near West Africa instead of in London, an error of thousands of kilometres from a single slip. Always read the pair back after encoding.
Mistakes to avoid
The most common mistake is the swapped pair, and it is worth a habit to defeat it: say "lat, long" out loud as you type, and check that the first number lies between minus 90 and plus 90. A first number of 120 or minus 140 is a longitude wearing a latitude costume, and the tool should make you stop and re-check. The second common mistake is over-precision, publishing a twelve-character code for a location you only know approximately, which then looks authoritative in a database while being wrong by metres. The third is treating a geohash as secret or private: it is an encoding, not encryption, and anyone can decode it, so never use it to hide a sensitive location. The fourth is assuming neighbours share prefixes, which fails at boundaries as described above. Finally, never paste a code with ambiguous characters: if a code you received contains an a, i, l, or o, it is either mistyped or from a different system, because valid geohashes exclude those letters.
Putting it into practice
Use short geohashes where a short, sortable key helps: grouping nearby reports in a spreadsheet, labelling photos by area, or caching results by region. Use longer codes where the exact spot matters, such as a gate, a trailhead, or a survey marker, and keep the original coordinates alongside the code in your records so nothing is lost to rounding. When you receive a code from someone else, decode it before acting on it, and confirm the decoded centre makes sense for the context. When you store codes in a database, store them all at one consistent length for any field you plan to group or sort by, or your groupings will silently split. And when precision matters for safety, such as emergency rendezvous points, confirm the decoded location on a map as well; a format tool tells you what the code says, not whether the code was right in the first place.
Key points
- A geohash packs latitude and longitude into one short string of letters and digits
- Each extra character narrows the area, so longer codes mean smaller boxes, not better accuracy
- Latitude always comes first when you enter coordinates, and swapping the pair moves the point far away
- Neighbouring places can have very different codes near a grid boundary, so never judge distance from the text alone
In short: a geohash is a compact, readable way to carry a location, and its length is its precision setting. Encode with latitude first, decode before you trust a code you received, and match the length to how accurately you actually know the place. Do that, and one short string can safely stand in for two long numbers.