Introduction
The PBF format is the compact binary form of OpenStreetMap
data, the free map of the world built by volunteers. The whole planet and regional
extracts are published as .osm.pbf files, which are much smaller and faster
to read than the same data in OpenStreetMap’s XML format (.osm). PBF stands
for Protocolbuffer Binary Format: the data is encoded with
Protocol Buffers.
The file holds OpenStreetMap’s three kinds of element: nodes, points
with a latitude and longitude; ways, ordered lists of nodes that make
roads, rivers and building outlines; and relations, groups of other
elements. Each element carries tags, such as highway=residential.
Structure
The file is a sequence of blocks with no overall header. Each block is:
- a 4-byte big-endian length
- a
BlobHeadermessage of that length, giving the block type,OSMHeaderorOSMData, and the size of the blob - a
Blobmessage holding the block’s data, raw or compressed, usually with zlib
The first block is an OSMHeader with the bounding box and the features a
reader must support. Each OSMData block is a primitive block of any
number of elements within the size limits (writers commonly use about 8,000). Its
strings are kept in one table and referred to by number, and
coordinates and IDs are stored as differences from the previous one, often in the packed
DenseNodes form, which keeps the file small. The
blocks and messages page gives every
message and field.
In the explorer
Drop an .osm.pbf or .pbf file on this site. The structure tree shows every block (the 4-byte length,
the BlobHeader with its type, indexdata and datasize, and the Blob with its raw_size and the data field). Blocks are
decompressed (raw, zlib, lzma, bzip2, lz4 and zstd) and decoded: the header summary lists the bounding box (in nanodegrees and
degrees), the required and optional features, the writing program, the source and the replication fields, and the Elements table
lists every node, dense node, way, relation and change set with its coordinates (granularity and offsets applied), its tags
resolved through the block’s string table, every node reference, every relation member and, with LocationsOnWays,
the location of every way node, and its metadata (version, timestamp, change set, user, visible; an absent visible is shown as true
when the header requires HistoricalInformation). IDs beyond 253 are exact. Each feature in the header is listed with its meaning.
The Blocks table gives each block’s type, sizes, compression and contents; the Block parameters table gives each data block’s granularity,
latitude and longitude offsets, date granularity, string count and groups; the String tables table lists every string of every block.
lzma_data is read as an xz container or as an LZMA-alone stream, whichever its first bytes are.
Reported, with the block and offset: missing headers, unknown required features, wrong raw sizes, wrong wire types, missing required
fields (a node’s id, lat and lon, a bounding-box side), arrays of different lengths (dense columns, way locations, relation members),
string indices past the table, strings that are not UTF-8, and every unknown field in every message with how often it occurs.
Where the header promises something, the viewer checks it: Sort.Type_then_ID against the order of the elements,
Has_Metadata against elements without metadata, LocationsOnWays against ways without locations.
Those three checks cover the blocks decoded when the file opened, and the report says so when later blocks were left out.
Not described
Nothing of the format is left undescribed. Three notes, none a gap: blocks are decoded when the file opens up to 64 MB of compressed data
(counts, header and issues), and blocks past that are decoded and listed when the table “Elements of later blocks” is first opened; the tree
draws the first 2,000 blocks as nodes and the Blocks table lists them all; the format does not say how the lzma_data field is
wrapped, so the viewer lets the bytes decide (an xz container by its magic, otherwise LZMA-alone with its 13-byte header) and reports a stream that is neither;
the contents of indexdata are not interpreted, as the format defines none.
Re-checked on 2026-11-27 against the OSM wiki’s PBF Format page, both .proto files and libosmium’s PBF decoder; every message and field
in fileformat.proto and osmformat.proto is on the
messages page.
Not part of the format: the wiki’s advice on ordering entities, building the string table by frequency and
choosing block sizes is non-normative, and what a particular program stores in or reads from the optional
indexdata bytes of a BlobHeader is that program’s convention. The format only says the field is
an optional, arbitrary blob reserved for future indexed files, which the messages page now states; none of this changes which files are valid.
Links
Software
- Osmium Tool – filters, merges and converts OpenStreetMap files (Windows, macOS, Linux)
- osm2pgsql – loads OpenStreetMap data into a PostgreSQL database
- QGIS – free GIS that opens PBF files through GDAL’s OSM driver (Windows, macOS, Linux)
Developers
Reference
- PBF Format – the OpenStreetMap wiki’s description of the format