A classic TIFF file is an 8-byte header and one or more image file directories (IFDs),
which point at everything else. Apart from the header, nothing has a fixed position.
The media type is image/tiff.
File header
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 2 | ASCII | byte order | II (49 49) little-endian; MM (4D 4D) big-endian. It applies to every number in the file. |
| 2 | 2 | u16 | magic | 42. |
| 4 | 4 | u32 | first IFD offset | Where the first directory is, from the start of the file. |
The file therefore starts 49 49 2A 00 or 4D 4D 00 2A.
Image file directory
An IFD must start on a word boundary and has at least one entry. Each page, reduced image or mask in a file has its own.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 2 | u16 | count | The number of entries. |
| 2 | 12 × count | entries | entries | Sorted by tag number, ascending. |
| 2 + 12 × count | 4 | u32 | next IFD offset | Where the next directory is; 0 if this is the last. |
Directory entry
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 2 | u16 | tag | Which field this is. |
| 2 | 2 | u16 | type | The data type, from the table below. |
| 4 | 4 | u32 | count | The number of values, not the number of bytes. |
| 8 | 4 | value or offset | value | The value, or where to find it. |
If count × type size is 4 bytes or fewer, the value is stored in the entry itself, left-justified, in the lower-numbered bytes of the field. Otherwise the field holds the offset of the value, which must begin on a word boundary. Readers must skip entries with a type or tag they do not know.
Data types
| Value | Name | Size | Meaning |
|---|---|---|---|
| 1 | BYTE | 1 | 8-bit unsigned integer. |
| 2 | ASCII | 1 | 7-bit text, with the last byte zero. The count includes it. |
| 3 | SHORT | 2 | 16-bit unsigned integer. |
| 4 | LONG | 4 | 32-bit unsigned integer. |
| 5 | RATIONAL | 8 | Two LONGs: numerator, then denominator. |
| 6 | SBYTE | 1 | 8-bit two’s complement integer. |
| 7 | UNDEFINED | 1 | 8 bits of anything, as the field defines. |
| 8 | SSHORT | 2 | 16-bit two’s complement integer. |
| 9 | SLONG | 4 | 32-bit two’s complement integer. |
| 10 | SRATIONAL | 8 | Two SLONGs: numerator, then denominator. |
| 11 | FLOAT | 4 | IEEE single precision. |
| 12 | DOUBLE | 8 | IEEE double precision. |
| 13 | IFD | 4 | A 32-bit offset to another IFD (added by TIFF Technical Note 1). |
Types 1 to 12 are in TIFF 6.0. Types 16, 17 and 18 belong to BigTIFF. Readers should accept other integer sizes for a field when the value fits, and writers should use the types the specification gives.
Trees of directories
Besides the chain of next IFD offsets, a directory can point at others:
SubIFDs (tag 330) holds child images, such as reduced resolutions of the
same page, and the Exif (34665), GPS (34853) and Interoperability (40965) tags point
at directories of their own, which use the same entry layout and their own tag
numbering.
Required tags
A baseline reader expects, at the least, the following tags. A grey, palette or RGB
image also needs the fields for its type, such as SamplesPerPixel for RGB
and ColorMap for a palette.
| Tag | Name |
|---|---|
| 256 | ImageWidth |
| 257 | ImageLength |
| 258 | BitsPerSample |
| 259 | Compression |
| 262 | PhotometricInterpretation |
| 273 | StripOffsets |
| 278 | RowsPerStrip |
| 279 | StripByteCounts |
| 282 | XResolution |
| 283 | YResolution |
| 296 | ResolutionUnit |
Worked example
A complete little-endian file holding one white greyscale pixel, 111 bytes long. For brevity it leaves out the resolution tags.
| Offset | Bytes | Meaning |
|---|---|---|
| 0 | 49 49 2A 00 | Little-endian, magic 42. |
| 4 | 08 00 00 00 | First IFD at offset 8. |
| 8 | 08 00 | 8 entries. |
| 10 | 00 01 03 00 01 00 00 00 01 00 00 00 | ImageWidth: SHORT, count 1, value 1. |
| 22 | 01 01 03 00 01 00 00 00 01 00 00 00 | ImageLength 1. |
| 34 | 02 01 03 00 01 00 00 00 08 00 00 00 | BitsPerSample 8. |
| 46 | 03 01 03 00 01 00 00 00 01 00 00 00 | Compression 1, none. |
| 58 | 06 01 03 00 01 00 00 00 01 00 00 00 | PhotometricInterpretation 1, BlackIsZero. |
| 70 | 11 01 04 00 01 00 00 00 6E 00 00 00 | StripOffsets: LONG, offset 110. |
| 82 | 16 01 03 00 01 00 00 00 01 00 00 00 | RowsPerStrip 1. |
| 94 | 17 01 04 00 01 00 00 00 01 00 00 00 | StripByteCounts: LONG, 1 byte. |
| 106 | 00 00 00 00 | No next IFD. |
| 110 | FF | The pixel. |