A geohash is a short string of letters and digits that stands for a rectangle on the Earth. The Statue of Liberty, at 40.689247, -74.044502, has the 9-character geohash dr5r7p62n. Each extra character makes the rectangle smaller, so the length of the code sets its precision.
Geohashes are popular in software because they turn two numbers into one sortable text value. Places with the same starting characters are near each other, which makes it easy to index and search locations in databases.
The geohash alphabet
A geohash uses 32 characters: the digits 0 to 9 and the lowercase letters b to z, without a, i, l and o. Three of the missing letters are easy to mistake for the digits 1 and 0.
0123456789bcdefghjkmnpqrstuvwxyz
Each character stands for a number from 0 to 31, its position in this list. Since 32 = 25, every character carries exactly 5 bits.
How the encoding works
The idea is to keep cutting the world in half and record which half the point is in:
- Start with the whole world: longitude -180 to 180 and latitude -90 to 90.
- Cut the longitude range in the middle. If the point is in the eastern (upper) half, write bit 1; if it is in the western (lower) half, write 0. Keep only that half.
- Cut the latitude range in the middle the same way: north half 1, south half 0.
- Keep alternating longitude, latitude, longitude… Each new bit halves one side of the box.
- Group the bits in fives and turn each group into a character from the alphabet.
Because the bits of the two coordinates are interleaved, one string describes both latitude and longitude at once. Longitude gets the first bit. With an odd number of characters, longitude gets one bit more than latitude; since the longitude range is twice as large (360° against 180°), the cell ends up the same size in degrees on both axes. With an even number, both get the same number of bits and the cell is twice as wide in longitude.
Worked example: the Statue of Liberty
Point: latitude 40.689247, longitude -74.044502.
First character
| Bit | Cut | Middle | Point is… | Bit value |
|---|---|---|---|---|
| 1 | Longitude -180 to 180 | 0 | below (west) | 0 |
| 2 | Latitude -90 to 90 | 0 | above (north) | 1 |
| 3 | Longitude -180 to 0 | -90 | above | 1 |
| 4 | Latitude 0 to 90 | 45 | below | 0 |
| 5 | Longitude -90 to 0 | -45 | below | 0 |
The bits are 01100, which is 12 in binary. Character number 12 in the alphabet (counting from 0) is d.
Second and third characters
The next five cuts compare the point with latitude 22.5, longitude -67.5, latitude 33.75, longitude -78.75 and latitude 39.375. The results are 10111 = 23, which is r. So far the code is dr, a cell from 39.375° N to 45° N and from 78.75° W to 67.5° W, covering a large part of the US Northeast.
The third group compares with longitude -73.125, latitude 42.1875, longitude -75.9375, latitude 40.78125 and longitude -74.53125. The bits 00101 = 5 give the character 5.
Continuing the same way gives dr5r7p62n after nine characters. That cell runs from 40.689240° N to 40.689282° N and from 74.044504° W to 74.044461° W. Its centre, 40.689261, -74.044483, is about 2 m from the original point.
You do not need to do this by hand: the Plus Code and geohash converter encodes and decodes geohashes and shows the cell on a map.
Precision: cell size per length
Each character adds 5 bits, which alternately cut longitude and latitude. The table shows the cell size in degrees and in distance on a sphere with the mean Earth radius (6,371.0088 km). Widths are given at the equator; a degree of longitude shrinks toward the poles, so cells are narrower elsewhere.
| Length | Cell size (lat × long) | Height | Width at the equator |
|---|---|---|---|
| 1 | 45° × 45° | 5,004 km | 5,004 km |
| 2 | 5.625° × 11.25° | 625 km | 1,251 km |
| 3 | 1.40625° × 1.40625° | 156 km | 156 km |
| 4 | 0.17578° × 0.35156° | 19.5 km | 39.1 km |
| 5 | 0.043945° × 0.043945° | 4.89 km | 4.89 km |
| 6 | 0.0054932° × 0.010986° | 611 m | 1.22 km |
| 7 | 0.0013733° × 0.0013733° | 153 m | 153 m |
| 8 | 0.00017166° × 0.00034332° | 19.1 m | 38.2 m |
| 9 | 0.000042915° × 0.000042915° | 4.77 m | 4.77 m |
| 10 | 0.0000053644° × 0.000010729° | 60 cm | 1.19 m |
| 11 | 0.0000013411° × 0.0000013411° | 15 cm | 15 cm |
| 12 | 0.00000016764° × 0.00000033528° | 1.9 cm | 3.7 cm |
At the latitude of New York the cells are narrower. The 9-character cell for the Statue of Liberty is about 4.77 m tall but only about 3.62 m wide.
A geohash is a cell, not a point. If you decode it, you get the centre of the cell plus an error margin of half the cell size on each axis.
The prefix property
Every geohash cell contains 32 smaller cells, one for each possible next character. So a shorter geohash is the parent of every longer geohash that starts with it: dr5r contains dr5r7p62n.
This is what makes geohashes useful in databases. To find everything in a cell, search for strings that start with its code. New York City Hall (40.712776, -74.005974) has the geohash dr5regw3p. It shares the first four characters, dr5r, with the Statue of Liberty, about 4.2 km away.
Edge cases to watch
The reverse is not always true: nearby places do not always share a prefix. When a cell boundary runs between two points, their codes can differ from the very first character.
- At the equator and Prime Meridian. The points 0.0001, 0.0001 and -0.0001, -0.0001 are only about 31 m apart, but their 5-character geohashes are
s0000and7zzzz, with nothing in common. - At Greenwich. Two points at latitude 51.4779, one at longitude 0.0001 and one at -0.0001, are about 14 m apart. Their 6-character geohashes are
u10hb5andgcpuzg. - Cell shape. Cells are rectangles in degrees, so they become narrow slivers near the poles.
Proximity searches therefore usually look at the target cell and its eight neighbours, not just one prefix. For exact distances, use the coordinates themselves with the distance calculator or read distance between two coordinates.
Geohash compared with other codes
- Plus Codes use a 20-character alphabet and are designed to be read and shared by people, with a
+separator and short local forms. See what is a Plus Code. - MGRS is a military grid built on UTM with metric precision. See what MGRS is.
- Decimal degrees remain the simplest way to store and exchange a point. See latitude and longitude formats.
Geohashes use latitude and longitude on WGS84, like GPS. If your source data uses another datum, convert it first; what is a datum explains why.