An Image File Directory (IFD) consists of a 2-byte count of the number of entries (i.e. the number of fields), followed by a sequence of 12-byte field entries, followed by a 4-byte offset of the next Image File Directory (or 0 if none). (Do not forget to write the 4 bytes of 0 after the last IFD.)
See figure 1.
Each 12-byte IFD entry has the following format:
Bytes 0-1 The Tag that identifies the field.
Bytes 2-3 The field Type.
Bytes 4-7 The number of values, Count of the indicated Type.
Bytes 8-11 The Value Offset, the file offset (in bytes) of the Value for the field. The Value is expected to begin on a word boundary; the corresponding Value Offset will thus be an even number. This file offset may point anywhere in the file, including after the image data.