Can a JPEG Have Multiple Comment Markers?

The JPEG file format fully supports embedding multiple Comment (COM) markers within a single image file. This article explores how the JPEG specification defines comment markers, the structural rules governing their placement, the data limits associated with each marker, and how different software applications interpret multiple comments.

The JPEG COM Marker Specification

In the JPEG standard (ISO/IEC 10918-1 / ITU-T T.81), markers are two-byte codes beginning with the byte 0xFF followed by a byte that indicates the marker type. The Comment marker is assigned the byte value 0xFFFE.

Following the marker code, a two-byte length field specifies the length of the comment segment, including the two length bytes themselves. Because this field is a 16-bit integer, the maximum total size of a single COM segment is 65,535 bytes, leaving up to 65,533 bytes for the actual text or binary payload.

Embedding Multiple Comments

The standard does not restrict a file to a single COM marker. An encoder can write as many COM markers as needed, subject only to the overall file size limits of the medium or filesystem.

These markers can be placed almost anywhere within the JPEG stream between the Start of Image (SOI, 0xFFD8) marker and the Start of Scan (SOS, 0xFFDA) marker, alongside other metadata markers like APP segments (such as Exif or XMP). While it is technically legal according to the specification for comments to appear after the scan data or between scans in progressive JPEGs, best practice dictates placing them in the header region before the image data starts.

Practical Advantages

Using multiple COM markers provides distinct technical advantages:

Software Compatibility and Behavior

Although multiple COM markers are syntactically valid according to the JPEG standard, how they are displayed depends on the software reading the file:

Because reader behavior varies, relying on multiple COM markers for critical application metadata requires testing with the target toolchain, though the file itself remains fully standards-compliant.