This page follows Esri’s ESRI
Shapefile Technical Description (white paper J-7855, July 1998), read
2026-11-12.
A shapefile is at least three files with the same name: .shp (shapes),
.shx (index) and .dbf (attributes, one
row per shape, in the same order). Integers are 32-bit and doubles 64-bit IEEE; the
byte order is given for each field, because it changes.
File header
100 bytes, the same in .shp and .shx.
| Offset | Type | Order | Field |
|---|---|---|---|
0 | integer | big | File code, 9994. |
4 | 5 integers | big | Unused, zero. |
24 | integer | big | File length in 16-bit words, header included. |
28 | integer | little | Version, 1000. |
32 | integer | little | Shape type. All non-null shapes in a file have this type. |
36 | double | little | Xmin |
44 | double | little | Ymin |
52 | double | little | Xmax |
60 | double | little | Ymax |
68 | double | little | Zmin (0 when not used) |
76 | double | little | Zmax |
84 | double | little | Mmin |
92 | double | little | Mmax |
Records
Each .shp record is an 8-byte header and the contents.
| Offset | Type | Order | Field |
|---|---|---|---|
0 | integer | big | Record number, from 1. |
4 | integer | big | Content length in 16-bit words. Each record adds 4 + this value to the file length. |
8 | integer | little | Shape type of this record (the file’s type, or 0 for a null shape). |
The .shx file is the header, then 8 bytes per record: the record’s
offset in the .shp file and its content length, both big-endian and in
16-bit words. The first record’s offset is therefore 50. The .shx
header’s file length is 50 + 4 × the number of records.
Shape types
| Value | Shape | Value | Shape |
|---|---|---|---|
| 0 | Null shape | 18 | MultiPointZ |
| 1 | Point | 21 | PointM |
| 3 | PolyLine | 23 | PolyLineM |
| 5 | Polygon | 25 | PolygonM |
| 8 | MultiPoint | 28 | MultiPointM |
| 11 | PointZ | 31 | MultiPatch |
| 13 | PolyLineZ | ||
| 15 | PolygonZ |
Other values are reserved. “M” shapes add a measure to each point (such as a distance along a route); “Z” shapes add a height and optionally a measure.
Record contents
All little-endian, after the 4-byte shape type. Offsets count from the shape type.
Point, PointM, PointZ
X (double, offset 4), Y (12); PointM adds M (20); PointZ adds Z (20) and M (28). A null shape is just the type, 0.
MultiPoint
| Offset | Field |
|---|---|
4 | Bounding box: Xmin, Ymin, Xmax, Ymax (4 doubles) |
36 | NumPoints (integer) |
40 | Points: X, Y pairs (16 bytes each) |
PolyLine and Polygon
| Offset | Field |
|---|---|
4 | Bounding box (4 doubles) |
36 | NumParts (integer) |
40 | NumPoints (integer) |
44 | Parts: for each part, the index of its first point (integers) |
| 44 + 4 × NumParts | Points: X, Y pairs |
A polyline part is a connected line. A polygon part is a closed ring, its first and last points the same; the outer ring runs clockwise and holes run counter-clockwise, so the inside of the polygon is always on the right.
The Esri description says polygons stored in a shapefile must be “clean”: no segment of one ring may intersect a segment of another ring, rings may touch at vertices but not along segments, and colinear segments count as intersecting. A “dirty” polygon is one whose hole rings also run clockwise, which makes interiors overlap. The order of rings in the points array is not significant. The Parts array holds, for each ring, the index of its first point (indexes start at 0), and there is no delimiter between rings in the points array. (Source: Esri Shapefile Technical Description, July 1998, Polygon notes.)
M and Z additions
The M forms of MultiPoint, PolyLine and Polygon add, after the points: Mmin, Mmax (doubles) and one M per point; the description marks these as optional. The Z forms add Zmin, Zmax and one Z per point, then the optional M range and values. Whether the optional part is there follows from the record’s content length.
Any floating-point value below −1038 means “no data”; the description uses this only for measures. Infinity and NaN are not allowed anywhere. In an empty shapefile the bounding box values are unspecified.
MultiPatch
Bounding box, NumParts, NumPoints, Parts, then PartTypes (one integer per part), then Points, Z range and values, and optionally M range and values. Part types:
| Value | Part type |
|---|---|
| 0 | Triangle strip |
| 1 | Triangle fan |
| 2 | Outer ring |
| 3 | Inner ring |
| 4 | First ring (of a polygon whose ring types are not known) |
| 5 | Ring (of such a polygon) |
A single triangle strip or triangle fan is one surface patch. In a strip, every vertex after the first two completes a new triangle by joining the new vertex to its two immediate predecessors. In a fan, each new vertex after the first two is joined to its immediate predecessor and to the first vertex of the part. A run of ring parts describes a polygonal patch with holes: normally an outer ring followed by inner rings. When the ring types are unknown the run must start with a first ring followed by rings; a run of rings not preceded by a first ring is treated as outer rings without holes. (Source: Esri Shapefile Technical Description, MultiPatch.)
File names and the dBASE table
A shapefile is a main file, an index file and a dBASE table. The one-to-one link
between geometry and attributes is the record number, so the dBASE records must be in
the same order as the shapes in the main file, one record per shape feature. All three
files share the same prefix and use the suffixes .shp, .shx
and .dbf. The names follow the 8.3 convention: the prefix starts with an
alphanumeric character (a-Z, 0-9) followed by up to seven characters (a-Z, 0-9, _, -).
On operating systems with case-sensitive names all letters in the file name are lower
case. The year in the dBASE header must be the year since 1900. The description points
to the Inprise Corp. site for the dBASE format itself; see the
DBF pages. (Source: Esri Shapefile Technical
Description, Naming Conventions and Organization of the dBASE File.)
Other files of a shapefile
The 1998 description covers only .shp, .shx and
.dbf. Other files found beside shapefiles, such as .prj
(the coordinate system), are not part of it and are not described here.