2026.11.20 · 5 min · javascript · backend · open source · performance
PMTiles: the whole world map is one file.
PMTiles packs every map tile on Earth into one file you put in a bucket. The browser reads a 16 KB index, then asks for only the bytes of the tiles on screen with HTTP Range requests: no tile server, no API key. How it finds a tile inside a 139.55 GB file, the code, and the hosting details that break it. As of 2026.11.
Most developers assume a map means Google Maps or Mapbox: an API key, usage limits and a bill that depends on traffic. PMTiles takes a different route. The whole world's map tiles go into one file, the file goes into a bucket, and the browser reads just the few kilobytes it needs with a plain HTTP feature you already use every time you seek in a video.
Watch the 60-second version on Instagram.
It's on the front page this week through Bruce Röttgers' post Self-hosting map tiles has gotten cheap and easy (462 points on Hacker News), which hosts the 139 GB world on Bunny for about $5 a month of storage.
One file, read in slices
The Protomaps docs call PMTiles "a single-file archive format for pyramids of tiled data". Readers use HTTP Range requests to fetch only the tile or metadata they need. The daily planet build from 2026.11.17 is 139.55 GB (139,547,428,331 bytes), zoom 0 to 15, and the browser never downloads more than a sliver of it.
A Range request asks for part of a file:
GET /planet.pmtiles
Range: bytes=0-1023
HTTP/1.1 206 Partial Content
Content-Range: bytes 0-1023/139547428331The server answers 206 Partial Content with just those bytes. A server without range support answers 200 and sends the whole file, which is the failure to watch for.
How the browser finds one tile
- Read the index. The file starts with a 127-byte header, then the root directory. Both fit in the first 16,384 bytes, so one request gets them.
- Look up the tile. The directory maps a tile to an offset and a length in the file.
- Fetch its bytes. One Range request for that slice; the bucket answers
206.
For tiles the root directory doesn't cover, there are leaf directories. In the format's words, "nearly any map tile can be retrieved in at most two additional requests", and those requests are cacheable. The bar in the figure isn't to scale: at 139.55 GB, the 16 KB index wouldn't be a visible sliver.
Why neighbours sit together
PMTiles doesn't address a tile by Z/X/Y. It gives each one a single TileID along a Hilbert curve, so z12/3423/1763 becomes 19078479. The curve snakes through the grid so that tiles next to each other on the map end up close together in the file.
Point at the grid: the 2 × 2 window of tiles moves, and its cells light up in the file strip below, in a few short runs near each other rather than spread across the file. The 8 × 8 grid is a small illustration; the real planet goes to zoom 15. The same trick saves space: duplicate tiles, like open ocean, are stored once, through run-length entries and shared offsets. The docs claim 70%+ smaller files for global basemaps.
The code
The client is the pmtiles package (v4.5.0) registered as a protocol in MapLibre:
import maplibregl from "maplibre-gl";
import { Protocol } from "pmtiles";
maplibregl.addProtocol("pmtiles", new Protocol().tile);
// source: { type: "vector", url: "pmtiles://https://bucket.example/world.pmtiles" }You don't need the whole planet. pmtiles extract cuts out what you need: --maxzoom=6 gives a world file of about 60 MB, and --bbox= cuts out a city. Each extra zoom level roughly doubles the size.
pmtiles extract https://build.protomaps.com/20261117.pmtiles city.pmtiles --bbox=<w,s,e,n>Run that once and copy the result to your own bucket. Don't hotlink the daily builds.
Hosting it
The host has to answer Range requests and allow CORS: allow GET and HEAD, allow the range and if-match headers, and expose etag. It works on Cloudflare R2 (recommended by Protomaps, no egress fees), S3, Google Cloud Storage, Azure, Bunny and others. GitHub Pages works only up to 1 GB.
The alternative is worse than it sounds: uploading about 300 million separate tile files instead "could cost 1,500 USD in request fees and take days", per the Protomaps docs.
What people get wrong
- "The browser downloads the 139 GB file." It downloads 16 KB of index, then a few KB per tile, as long as the host honours Range.
- "
curlworks, so the map works." Missing CORS or anetagthat isn't exposed breaks the map in the browser whilecurlstill succeeds. - "No API key means no other files." Tiles, yes. Labels and icons still need
glyphsandspriteURLs. They're static too, and you can self-host them from basemaps-assets. - "Static means free and fast." Every range read counts as a GET, so request fees scale with traffic. Each tile is also a round trip to the bucket; commenters on HN put a Worker or CDN, or a tile server like Martin, in front for latency. A CDN that doesn't cache Range responses costs money: on Bunny, turn on "Optimize for large object delivery".
- "It works on every network." Some corporate proxies strip the Range header and pull the whole file.
- "I can patch one tile." The format is read-only. Changing one tile means rewriting the whole file.
The data is OpenStreetMap's, so attribution is required (ODbL).
On a client project I'd use it for any map whose tiles change rarely, with an extract cut to the client's region and a CDN in front of the bucket, and I'd check curl -I for accept-ranges: bytes before anything else.
The short version
- PMTiles is one file holding every tile; any static host that answers Range requests can serve it.
- The browser reads a 127-byte header and root directory in the first 16 KB, then fetches one tile's bytes, answered
206. - Tile IDs follow a Hilbert curve, so neighbouring tiles sit close together in the file; nearly any tile is at most two more cacheable reads away.
- Host it with CORS that allows
rangeandif-matchand exposesetag; without Range support, the browser gets the whole file. - Fonts and sprites are separate static files, request fees scale with traffic, and OSM attribution is required.
Sources: Protomaps, PMTiles concepts · MDN, HTTP range requests · PMTiles v3 spec · Protomaps blog, PMTiles v3 · Protomaps build metadata · Protomaps, Basemap downloads · Protomaps, Getting started · Protomaps, Cloud storage · npm, pmtiles · Protomaps, MapLibre · Bruce Röttgers, Self-hosting map tiles has gotten cheap and easy · Hacker News discussion · Protomaps, Basemaps in MapLibre