A binary STL file is an 80-byte header, a count, and a fixed 50-byte record for each triangle. There is nothing else: no signature, no end marker, and the file ends after the last triangle. The 1989 StereoLithography Interface Specification from 3D Systems defines it, as reprinted in Marshall Burns’ Automated Fabrication (1993).
The file
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 80 | bytes | Header | Free content, often the name of the program that wrote the file; readers ignore it. See below |
| 80 | 4 | uint32 | Number of triangles | How many triangle records follow |
| 84 | 50 × count | records | Triangles | One record per triangle, back to back |
So the size of a valid file is exactly 84 + 50 × count bytes, the best
test that a file is binary STL.
Triangle record
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| +0 | 12 | 3 × float32 | Normal | i, j, k: the unit normal, pointing out of the object |
| +12 | 12 | 3 × float32 | Vertex 1 | x, y, z |
| +24 | 12 | 3 × float32 | Vertex 2 | x, y, z |
| +36 | 12 | 3 × float32 | Vertex 3 | x, y, z |
| +48 | 2 | uint16 | Attribute byte count | 0 in the specification, whose attribute syntax was never documented. Some programs store a colour here; see Colour extensions |
The vertices run anticlockwise when the facet is seen from outside, and every triangle must share two vertices with each of its neighbours, as in ASCII STL. Many writers store a normal of (0, 0, 0) and leave the reader to compute it from the vertex order.
Because a record is 50 bytes, the floats after the first record are not aligned to four-byte boundaries, so a reader should copy values out byte by byte rather than map the records onto an array of floats.
Numbers and byte order
Floats are IEEE 754 single precision and integers are unsigned. The specification names the IEEE representation but not the byte order. In practice files are written little-endian, least significant byte first, and readers assume it. There are no units: coordinates are in whatever unit the model was made in, usually millimetres.
The header
The specification leaves the header’s content free, and readers skip it. Writers
fill it with text such as the program’s name, padded with spaces or zero bytes. It
should not start with the word solid, because some programs then take
the file for ASCII STL. Some programs write it
anyway, so readers should test the size instead. Materialise Magics stores
a colour for the whole object in the header; see
Colour extensions.
Worked example
One triangle, with corners at (0, 0, 0), (1, 0, 0) and (0, 1, 0) and a normal of
(0, 0, 1), with the header text Example followed by zero bytes. The file is
84 + 50 = 134 bytes.
00000000 45 78 61 6D 70 6C 65 00 00 00 00 00 00 00 00 00 Example.........
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000050 01 00 00 00 00 00 00 00 00 00 00 00 00 00 80 3F ...............?
00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 3F ...............?
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 3F ...............?
00000080 00 00 00 00 00 00 ......
| Offset | Bytes | Meaning |
|---|---|---|
| 0 | 45 78 61 6D 70 6C 65, then 73 × 00 | Header: Example and padding |
| 80 | 01 00 00 00 | One triangle |
| 84 | 00 00 00 00 00 00 00 00 00 00 80 3F | Normal (0.0, 0.0, 1.0) |
| 96 | 12 × 00 | Vertex 1 (0.0, 0.0, 0.0) |
| 108 | 00 00 80 3F 00 00 00 00 00 00 00 00 | Vertex 2 (1.0, 0.0, 0.0) |
| 120 | 00 00 00 00 00 00 80 3F 00 00 00 00 | Vertex 3 (0.0, 1.0, 0.0) |
| 132 | 00 00 | Attribute byte count 0 |