Maximum Huffman Tables in a Standard JPEG Header
A standard JPEG image can define a maximum of 8 Huffman tables within
its file headers. These tables are specified using the Define Huffman
Table (DHT) marker segment (0xFFC4) defined by the ISO/IEC
10918-1 standard (ITU-T T.81). The specification splits Huffman tables
into two functional classes—DC tables and AC tables—and allows up to 4
distinct tables per class.
Breakdown of the 8-Table Limit
In the JPEG standard, Huffman tables are indexed by a 1-byte identifier located inside the DHT marker segment. This byte is divided into two 4-bit nibbles:
- Table Class (Higher 4 bits): Indicates whether the
table is used for DC coefficients (class
0) or AC coefficients (class1). - Table Destination Identifier (Lower 4 bits):
Identifies the specific table slot, restricted to values
0,1,2, or3.
Because there are 2 valid classes and 4 valid identifiers per class, a decoder can store a maximum of:
- 4 DC tables (Class 0, IDs 0 through 3)
- 4 AC tables (Class 1, IDs 0 through 3)
Combined, this yields an absolute maximum of 8 Huffman tables active in a standard JPEG decoder at any given time.
Baseline vs. Extended JPEG Implementations
While the full standard permits 8 tables, constraints depend on the operating mode:
- Baseline Sequential Mode: The standard restricts baseline implementations to a maximum of 2 DC tables and 2 AC tables (a total of 4 tables), usually allocated as one pair for luminance (\(Y\)) and one pair for chrominance (\(Cb/Cr\)).
- Extended Sequential and Progressive Modes: These modes can fully utilize the maximum limit of 4 DC tables and 4 AC tables (8 tables total), allowing distinct entropy encoding tables for additional color channels or components.
A JPEG file can contain multiple DHT markers or bundle multiple table definitions into a single DHT segment, but it cannot exceed the 4 DC and 4 AC identifier slots without violating the standard.