← Lessons

quiz vs the machine

Silver1080

System Design

Geohash Encoding

Turning a latitude and longitude pair into one short string that groups nearby places together.

4 min read · intro · beat Silver to climb

What a geohash is

A geohash encodes a latitude and longitude into a single short string of letters and digits. The trick is interleaving bits: the world is repeatedly cut in half, alternating between the longitude axis and the latitude axis, and each cut writes one bit. Groups of five bits become one base32 character.

Why it is useful

  • Prefixes are spatial. Two points that share a long common prefix are physically near each other.
  • Precision is adjustable. More characters mean a smaller, more precise cell.
  • It maps to a one dimensional key, so a plain sorted index or a key value store can answer rough proximity queries.

The edge case to remember

Points right across a cell border can be far apart in string space even though they are physically close. A robust nearby search checks the central cell plus its eight neighbors, not just one prefix.

Key idea

A geohash flattens two dimensions into one sortable string where a shared prefix usually means physical closeness.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a shared geohash prefix usually indicate?

2. Why should a nearby search also scan neighbor cells?