AlgoMaster Logo

Geohash

Last Updated: May 26, 2026

Ashish

Ashish Pratap Singh

High Priority
10 min read

Many location systems need to find nearby places without scanning every latitude and longitude row.

Geohash converts a two-dimensional location into a hierarchical string. Nearby points often share a prefix, so ordinary ordered indexes can fetch a small set of candidate locations.

Geohash is a coarse filter, not an exact distance engine. Production queries still need neighboring cells, exact distance checks, and careful precision choices.

1. What Is Geohash?

Geohash is a hierarchical spatial encoding for latitude and longitude. It divides the Earth into rectangular cells and assigns each cell a short Base32 string.

Longer strings represent smaller cells:

  • 9q8yy covers a broad area around San Francisco.
  • 9q8yyk covers a smaller cell inside that area.
  • 9q8yyk8 covers a still smaller cell.

Invented by Gustavo Niemeyer in 2008, Geohash became popular because it fits cleanly into existing storage systems. A geohash is just a string, so you can store it in a normal column, sort it, prefix-match it, and index it with a B-tree.

Here is the core idea:

This hierarchy is why prefix queries work. Searching for 9q8yy% means "find points stored in this cell and its descendants."

2. How Geohash Encoding Works

Premium Content

This content is for premium members only.