A geohash is a short string of letters and digits that names a rectangular cell on the Earth's surface. Each extra character narrows the cell to one of 32 smaller cells, so a longer geohash is more precise, and removing characters from the end still points to the same, larger area. It is used to index, group and coarsen locations.

Learning objectives

After reading this article you will be able to:

  • Explain how each geohash character narrows a cell to one of 32 sub-cells
  • Choose a geohash length by weighing cell size against what it discloses
  • Explain why a proximity search must also check a cell's eight neighbours

How a geohash works

A geohash turns a latitude and longitude into a string such as ezs42. The string does not name a point. It names a rectangular cell, and every point inside that cell has the same geohash at that length. The encoding was originally described by Gustavo Niemeyer.

Each character narrows the area. At each level, as Chris Veness explains, every extra character identifies one of 32 sub-cells of the cell before it. So a one-character geohash covers a huge area, and each character added after that shrinks the cell.

Two properties follow, and they make geohashes useful in databases:

  • Truncation keeps the area. The Redis documentation notes that a geohash can be shortened by removing characters from the right: it loses precision but still points to the same area.
  • Prefixes group nearby places. PostGIS describes a geohash as a text form that is sortable and searchable by prefix, so a query for every string starting with a given prefix returns everything in that cell.

The Geohash Python module shows the length at work: the point at latitude 42.6, longitude -5.6 encodes to ezs42e44yx96 at full length, and to ezs42 when you ask for precision 5.

Precision and cell size

How large a cell is depends on the length of the geohash and on latitude, because cells narrow towards the poles. The Elasticsearch reference gives the cell dimensions at the equator, the widest case:

Geohash lengthCell width x height at the equator
15,009.4 km x 4,992.6 km
21,252.3 km x 624.1 km
3156.5 km x 156 km
439.1 km x 19.5 km
54.9 km x 4.9 km
61.2 km x 609.4 m
7152.9 m x 152.4 m
838.2 m x 19 m

Elasticsearch accepts lengths from 1 to 12, and notes that a length-12 geohash covers less than a square metre. Veness’s page gives the same sizes rounded, and points out that cell width shrinks to zero at the poles.

Choosing a length is a trade between detail and disclosure. A five-character geohash places something within a cell a few kilometres across; an eight-character one narrows it to a few tens of metres.

Nearby places and prefixes

Shared prefixes mean shared cells, so places with the same long prefix are close together. The reverse is not true. The Redis documentation warns that strings with different prefixes can still be nearby, and Veness gives an example from France: La Roche-Chalais, in cell u000, is just 30 km from Pomerol, in cell ezzz, because the two sit on either side of a large cell boundary.

The fix is to search neighbours as well. Veness suggests that a reliable proximity search also checks the prefixes of a cell’s eight neighbouring cells, not just the cell itself.

Where geohashes are used

  • Spatial indexes and aggregations. Elasticsearch groups points into geohash grid buckets of a chosen precision, and Redis returns standard geohash strings for members of its geospatial index.
  • Database functions. PostGIS’s ST_GeoHash returns the geohash for a geometry, with an optional maximum number of characters.
  • Sharing a place. Veness notes that a geohash might be easier to read out than a pair of coordinates.
  • Coarsening a location. Truncating a geohash is a simple way to record an area rather than a point, which matters when a location record can reveal more than intended.

Offline Protocol’s Proof of Location is one example of the last use. Its backend commits a precision-5 geohash, approximately a 5 km cell, of a claimed location to an EigenLayer AVS contract on the Ethereum Sepolia testnet, and that geohash and each task’s time remain public there.

Limits

  • Cells are not equal in area. Width shrinks away from the equator, so the same length covers less ground near the poles.
  • Boundaries split neighbours. Two points metres apart can fall into different cells with different prefixes.
  • It is not secret. A geohash is an encoding that anyone can decode. A coarse geohash reveals less, but what it does reveal is readable by everyone who sees it, and over many records even coarse cells can trace a pattern.

Frequently asked questions

Does a geohash hide a location?

No. It is an encoding, not encryption. Anyone can decode a geohash back to its cell. Using a short geohash makes the cell larger, which reveals less, but the cell itself is public to whoever sees the string.

Are two places with similar geohashes always close together?

Places that share a long prefix are close, but the reverse does not hold. Two nearby points on either side of a cell boundary can have quite different geohashes.

Sources

  • Geohashes. Chris Veness, geohash cells, sizes by length and neighbour search
  • Geohash grid aggregation. Elasticsearch reference, including cell dimensions at the equator for each length
  • GEOHASH. Redis command reference on standard geohash strings and their prefix properties
  • ST_GeoHash. PostGIS reference on geohash output and precision
  • Geohash Python module. Encoding and decoding examples, and credit to Gustavo Niemeyer for the encoding
  • Location evidence security. Offline Protocol's public geohash on Sepolia and what it reveals

Build it with Offline Protocol

The Proof of Location security page explains which geohash precision the service commits, what stays public on Ethereum Sepolia, and which off-chain copies exist.

Read the location evidence security page