PicScrub logoPicScrub
Back to Formats

TIFF Format

Tagged Image File Format

Header Structure

TIFF is the grandfather of image metadata. When you see EXIF data in a JPEG, that's actually a TIFF structure embedded inside the file. Understanding TIFF means understanding how most image metadata works.

The format starts with an 8-byte header that tells you two critical things: the byte order (Intel vs Motorola) and where to find the first IFD. From there, it's all pointer-chasing.

TIFF File Structure

Header
IFD0
Strip Data
EXIF IFD
GPS IFD
Header
8 bytes
Byte order + magic + IFD offset
IFD0
200 bytes
Main image directory
Strip Data
Variable length
Image pixel data
EXIF IFD
500 bytes
EXIF sub-directory
GPS IFD
100 bytes
GPS sub-directory

TIFF Header

Byte Order (II = Little Endian)
Magic Number (42)
First IFD Offset
OffsetHexASCII
0000
49492A0008000000
II*.....

Byte Order

49 49 (II)

Intel:Little-endian (least significant byte first)

4D 4D (MM)

Motorola:Big-endian (most significant byte first)

IFD Structure

IFD stands for Image File Directory, but think of it as a table of contents. It's a flat list of tags, each pointing to some piece of data. The clever part is that IFDs can point to other IFDs, creating a tree structure.

IFD Layout

2 bytesEntry count (number of tags)
12 × N bytesTag entries (12 bytes each)
4 bytesNext IFD offset (0 if none)

Tag Entry Structure (12 bytes)

Tag IDTypeCountValue/Offset
2 bytes2 bytes4 bytes4 bytes

If data fits in 4 bytes, it's stored directly in the value field. Otherwise, value field contains an offset to the data.

Tag Types

TIFF is strongly typed. Each tag specifies not just what it contains, but how to interpret the bytes. This is why you need to understand the type system to parse TIFF correctly.

IDNameSizeDescription
1BYTE1Unsigned 8-bit integer
2ASCII1Null-terminated string (8-bit)
3SHORT2Unsigned 16-bit integer
4LONG4Unsigned 32-bit integer
5RATIONAL8Two LONGs: numerator/denominator
6SBYTE1Signed 8-bit integer
7UNDEFINED1Raw bytes (binary data)
8SSHORT2Signed 16-bit integer
9SLONG4Signed 32-bit integer
10SRATIONAL8Two SLONGs: signed num/denom
11FLOAT4IEEE 32-bit float
12DOUBLE8IEEE 64-bit double
13IFD4Pointer to nested IFD

Value Storage Rule

If size × count ≤ 4 bytes, the value is stored directly in the 4-byte value field. Otherwise, the field contains an offset pointing to where the data is stored in the file.

IFD Offset Calculations

The hardest part of parsing TIFF is following the offset chain. Everything is relative to the start of the file, and you'll be jumping around a lot. Here's how the math works:

// IFD0 location
IFD0_offset = bytes[4:8] // From TIFF header
// Next IFD location (e.g., IFD1 for thumbnail)
next_IFD = IFD0_offset + 2 + (entry_count × 12) + 4
// SubIFD location (EXIF, GPS)
subIFD_offset = tag_value // From pointer tag (0x8769, 0x8825)

Important Tags

Image Data Tags (Preserved)

0x0100:ImageWidth
0x0101:ImageLength
0x0102:BitsPerSample
0x0103:Compression
0x0111:StripOffsets
0x0117:StripByteCounts

Metadata Tags (Removed)

0x010F:Make (camera manufacturer)
0x0110:Model (camera model)
0x0132:DateTime
0x013B:Artist
0x8298:Copyright
0x9003:DateTimeOriginal

Pointer Tags (Sub-IFDs)

0x8769:ExifIFDPointer
0x8825:GPSInfoIFDPointer
0xA005:InteroperabilityIFDPointer

SubIFDs

The main IFD (IFD0) often contains "pointer tags" that reference sub-directories. This is how EXIF, GPS, and other metadata gets organized into logical groups while keeping the main IFD clean.

EXIF SubIFD

Contains camera-specific metadata: exposure, aperture, ISO, focal length, flash, white balance, and more.

GPS SubIFD

Contains geolocation data: latitude, longitude, altitude, timestamp, satellites, speed, direction. Major privacy concern.

Maker Notes

Proprietary camera data. Format varies by manufacturer. May contain serial numbers, firmware version, custom settings.

How PicScrub Processes TIFF

1

Parse Header

Determine byte order (II/MM) and locate first IFD

2

Build Tag Whitelist

Identify essential tags for image rendering

3

Filter IFD Entries

Remove metadata tags, zero out SubIFD pointers

4

Rewrite File

Reconstruct TIFF with clean IFDs and copied image data

Offset Recalculation

TIFF files use file offsets extensively. When metadata is removed, PicScrub must recalculate all offsets to maintain file integrity.