When entropy_coding_mode_flag is 0, each block of transform coefficients
in the residual data is coded with
CAVLC, context-adaptive variable-length coding (descriptor ce(v)). A block
is sent as coeff_token, the signs of up to three trailing ±1 levels, the
other levels, total_zeros and the run_before values. This page
gives every code table. Source: ITU-T H.264 (06/2026, version 16), clause 9.2 and
Tables 9-5 to 9-10. Codes are written with a space every four bits for reading.
Decoding a block
- Read
coeff_tokenfrom the column of Table 9-5 chosen by nC. It givesTotalCoeff(0 to 16) andTrailingOnes(0 to 3). With 0 coefficients the block is all zeros. - Read one
trailing_ones_sign_flagper trailing one: 0 means +1, 1 means −1. - Read the remaining
TotalCoeff − TrailingOneslevels, each aslevel_prefixandlevel_suffix(below). - If
TotalCoeffis less than the block sizemaxNumCoeff, readtotal_zerosfrom Tables 9-7 to 9-9, using the columntzVlcIndex = TotalCoeff. - For each coefficient but the last, while zeros are left, read
run_beforefrom Table 9-10 using the column for the zeros left; the last coefficient takes all remaining zeros. - Place the levels from the highest frequency down: starting at position −1, each level advances by its run + 1 (clause 9.2.4). Levels are in reverse scan order: the first level read is the last non-zero coefficient.
Choosing nC
For chroma DC, nC is −1 for 4:2:0 (ChromaArrayType 1) and −2 for 4:2:2.
Otherwise nC comes from the 4 × 4 blocks to the left (A) and above (B), of the same
colour component (clause 9.2.1):
- A neighbour is unavailable if it is outside the picture or slice, or if the current
macroblock is intra,
constrained_intra_pred_flagis 1, the neighbour is inter and data partitioning is used (NAL types 2 to 4). - An available neighbour counts 0 if it is P_Skip or B_Skip or its coded block pattern
bit is 0, 16 if it is I_PCM, and otherwise its own
TotalCoeff(AC coefficients only, for Intra 16 × 16 and chroma blocks). - nC = (nA + nB + 1) >> 1 with both, nA or nB with one, 0 with none. For Intra 16 × 16 DC, the block index is taken as 0.
With a 15-coefficient block (AC only), TotalCoeff may not be 16.
coeff_token (Table 9-5)
T1 is TrailingOnes, TC TotalCoeff. A dash means the
combination cannot occur in that column. For 8 ≤ nC the code is a fixed 6 bits: the
top four are TotalCoeff − 1 and the bottom two TrailingOnes,
except that 0000 11 means no coefficients.
| T1 | TC | 0 ≤ nC < 2 | 2 ≤ nC < 4 | 4 ≤ nC < 8 | 8 ≤ nC | nC = −1 | nC = −2 |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 11 | 1111 | 0000 11 | 01 | 1 |
| 0 | 1 | 0001 01 | 0010 11 | 0011 11 | 0000 00 | 0001 11 | 0001 111 |
| 1 | 1 | 01 | 10 | 1110 | 0000 01 | 1 | 01 |
| 0 | 2 | 0000 0111 | 0001 11 | 0010 11 | 0001 00 | 0001 00 | 0001 110 |
| 1 | 2 | 0001 00 | 0011 1 | 0111 1 | 0001 01 | 0001 10 | 0001 101 |
| 2 | 2 | 001 | 011 | 1101 | 0001 10 | 001 | 001 |
| 0 | 3 | 0000 0011 1 | 0000 111 | 0010 00 | 0010 00 | 0000 11 | 0000 0011 1 |
| 1 | 3 | 0000 0110 | 0010 10 | 0110 0 | 0010 01 | 0000 011 | 0001 100 |
| 2 | 3 | 0000 101 | 0010 01 | 0111 0 | 0010 10 | 0000 010 | 0001 011 |
| 3 | 3 | 0001 1 | 0101 | 1100 | 0010 11 | 0001 01 | 0000 1 |
| 0 | 4 | 0000 0001 11 | 0000 0111 | 0001 111 | 0011 00 | 0000 10 | 0000 0011 0 |
| 1 | 4 | 0000 0011 0 | 0001 10 | 0101 0 | 0011 01 | 0000 0011 | 0000 0010 1 |
| 2 | 4 | 0000 0101 | 0001 01 | 0101 1 | 0011 10 | 0000 0010 | 0001 010 |
| 3 | 4 | 0000 11 | 0100 | 1011 | 0011 11 | 0000 000 | 0000 01 |
| 0 | 5 | 0000 0000 111 | 0000 0100 | 0001 011 | 0100 00 | – | 0000 0001 11 |
| 1 | 5 | 0000 0001 10 | 0000 110 | 0100 0 | 0100 01 | – | 0000 0001 10 |
| 2 | 5 | 0000 0010 1 | 0000 101 | 0100 1 | 0100 10 | – | 0000 0010 0 |
| 3 | 5 | 0000 100 | 0011 0 | 1010 | 0100 11 | – | 0001 001 |
| 0 | 6 | 0000 0000 0111 1 | 0000 0011 1 | 0001 001 | 0101 00 | – | 0000 0000 111 |
| 1 | 6 | 0000 0000 110 | 0000 0110 | 0011 10 | 0101 01 | – | 0000 0000 110 |
| 2 | 6 | 0000 0001 01 | 0000 0101 | 0011 01 | 0101 10 | – | 0000 0001 01 |
| 3 | 6 | 0000 0100 | 0010 00 | 1001 | 0101 11 | – | 0001 000 |
| 0 | 7 | 0000 0000 0101 1 | 0000 0001 111 | 0001 000 | 0110 00 | – | 0000 0000 0111 |
| 1 | 7 | 0000 0000 0111 0 | 0000 0011 0 | 0010 10 | 0110 01 | – | 0000 0000 0110 |
| 2 | 7 | 0000 0000 101 | 0000 0010 1 | 0010 01 | 0110 10 | – | 0000 0000 101 |
| 3 | 7 | 0000 0010 0 | 0001 00 | 1000 | 0110 11 | – | 0000 0001 00 |
| 0 | 8 | 0000 0000 0100 0 | 0000 0001 011 | 0000 1111 | 0111 00 | – | 0000 0000 0011 1 |
| 1 | 8 | 0000 0000 0101 0 | 0000 0001 110 | 0001 110 | 0111 01 | – | 0000 0000 0101 |
| 2 | 8 | 0000 0000 0110 1 | 0000 0001 101 | 0001 101 | 0111 10 | – | 0000 0000 0100 |
| 3 | 8 | 0000 0001 00 | 0000 100 | 0110 1 | 0111 11 | – | 0000 0000 100 |
| 0 | 9 | 0000 0000 0011 11 | 0000 0000 1111 | 0000 1011 | 1000 00 | – | – |
| 1 | 9 | 0000 0000 0011 10 | 0000 0001 010 | 0000 1110 | 1000 01 | – | – |
| 2 | 9 | 0000 0000 0100 1 | 0000 0001 001 | 0001 010 | 1000 10 | – | – |
| 3 | 9 | 0000 0000 100 | 0000 0010 0 | 0011 00 | 1000 11 | – | – |
| 0 | 10 | 0000 0000 0010 11 | 0000 0000 1011 | 0000 0111 1 | 1001 00 | – | – |
| 1 | 10 | 0000 0000 0010 10 | 0000 0000 1110 | 0000 1010 | 1001 01 | – | – |
| 2 | 10 | 0000 0000 0011 01 | 0000 0000 1101 | 0000 1101 | 1001 10 | – | – |
| 3 | 10 | 0000 0000 0110 0 | 0000 0001 100 | 0001 100 | 1001 11 | – | – |
| 0 | 11 | 0000 0000 0001 111 | 0000 0000 1000 | 0000 0101 1 | 1010 00 | – | – |
| 1 | 11 | 0000 0000 0001 110 | 0000 0000 1010 | 0000 0111 0 | 1010 01 | – | – |
| 2 | 11 | 0000 0000 0010 01 | 0000 0000 1001 | 0000 1001 | 1010 10 | – | – |
| 3 | 11 | 0000 0000 0011 00 | 0000 0001 000 | 0000 1100 | 1010 11 | – | – |
| 0 | 12 | 0000 0000 0001 011 | 0000 0000 0111 1 | 0000 0100 0 | 1011 00 | – | – |
| 1 | 12 | 0000 0000 0001 010 | 0000 0000 0111 0 | 0000 0101 0 | 1011 01 | – | – |
| 2 | 12 | 0000 0000 0001 101 | 0000 0000 0110 1 | 0000 0110 1 | 1011 10 | – | – |
| 3 | 12 | 0000 0000 0010 00 | 0000 0000 1100 | 0000 1000 | 1011 11 | – | – |
| 0 | 13 | 0000 0000 0000 1111 | 0000 0000 0101 1 | 0000 0011 01 | 1100 00 | – | – |
| 1 | 13 | 0000 0000 0000 001 | 0000 0000 0101 0 | 0000 0011 1 | 1100 01 | – | – |
| 2 | 13 | 0000 0000 0001 001 | 0000 0000 0100 1 | 0000 0100 1 | 1100 10 | – | – |
| 3 | 13 | 0000 0000 0001 100 | 0000 0000 0110 0 | 0000 0110 0 | 1100 11 | – | – |
| 0 | 14 | 0000 0000 0000 1011 | 0000 0000 0011 1 | 0000 0010 01 | 1101 00 | – | – |
| 1 | 14 | 0000 0000 0000 1110 | 0000 0000 0010 11 | 0000 0011 00 | 1101 01 | – | – |
| 2 | 14 | 0000 0000 0000 1101 | 0000 0000 0011 0 | 0000 0010 11 | 1101 10 | – | – |
| 3 | 14 | 0000 0000 0001 000 | 0000 0000 0100 0 | 0000 0010 10 | 1101 11 | – | – |
| 0 | 15 | 0000 0000 0000 0111 | 0000 0000 0010 01 | 0000 0001 01 | 1110 00 | – | – |
| 1 | 15 | 0000 0000 0000 1010 | 0000 0000 0010 00 | 0000 0010 00 | 1110 01 | – | – |
| 2 | 15 | 0000 0000 0000 1001 | 0000 0000 0010 10 | 0000 0001 11 | 1110 10 | – | – |
| 3 | 15 | 0000 0000 0000 1100 | 0000 0000 0000 1 | 0000 0001 10 | 1110 11 | – | – |
| 0 | 16 | 0000 0000 0000 0100 | 0000 0000 0001 11 | 0000 0000 01 | 1111 00 | – | – |
| 1 | 16 | 0000 0000 0000 0110 | 0000 0000 0001 10 | 0000 0001 00 | 1111 01 | – | – |
| 2 | 16 | 0000 0000 0000 0101 | 0000 0000 0001 01 | 0000 0000 11 | 1111 10 | – | – |
| 3 | 16 | 0000 0000 0000 1000 | 0000 0000 0001 00 | 0000 0000 10 | 1111 11 | – | – |
Levels
level_prefix is the count of zero bits before a 1 (Table 9-6): 1
is 0, 01 is 1, and so on, up to 15 zeros then a 1 for 15. Baseline,
Constrained Baseline, Main and Extended streams never exceed 15; other profiles may go
higher (it has been reported to stay at or below 11 + bit depth).
suffixLength starts at 1 if TotalCoeff > 10 and
TrailingOnes < 3, otherwise 0. For each level (clause 9.2.2):
levelSuffixSizeis 4 iflevel_prefixis 14 andsuffixLengthis 0;level_prefix − 3if the prefix is 15 or more; otherwisesuffixLength.level_suffixis read as an unsigned number of that many bits (0 when the size is 0).levelCode = (Min(15, level_prefix) << suffixLength) + level_suffix; add 15 if the prefix is 15 or more andsuffixLengthis 0; add(1 << (level_prefix − 3)) − 4096if the prefix is 16 or more; add 2 to the first level after the trailing ones when there are fewer than 3 of them.- Level =
(levelCode + 2) >> 1iflevelCodeis even,(−levelCode − 1) >> 1if odd. - Then
suffixLengthbecomes 1 if it was 0, and grows by 1 (up to 6) when the level’s magnitude exceeds3 << (suffixLength − 1).
total_zeros
The number of zero coefficients before the last non-zero one in scan order. Columns
are tzVlcIndex (= TotalCoeff). 4 × 4 blocks (and 8 × 8 blocks,
which are sent as four 4 × 4 blocks) use Tables 9-7 and 9-8:
| total_zeros | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 111 | 0101 | 0001 1 | 0101 | 0000 01 | 0000 01 |
| 1 | 011 | 110 | 111 | 111 | 0100 | 0000 1 | 0000 1 |
| 2 | 010 | 101 | 110 | 0101 | 0011 | 111 | 101 |
| 3 | 0011 | 100 | 101 | 0100 | 111 | 110 | 100 |
| 4 | 0010 | 011 | 0100 | 110 | 110 | 101 | 011 |
| 5 | 0001 1 | 0101 | 0011 | 101 | 101 | 100 | 11 |
| 6 | 0001 0 | 0100 | 100 | 100 | 100 | 011 | 010 |
| 7 | 0000 11 | 0011 | 011 | 0011 | 011 | 010 | 0001 |
| 8 | 0000 10 | 0010 | 0010 | 011 | 0010 | 0001 | 001 |
| 9 | 0000 011 | 0001 1 | 0001 1 | 0010 | 0000 1 | 001 | 0000 00 |
| 10 | 0000 010 | 0001 0 | 0001 0 | 0001 0 | 0001 | 0000 00 | – |
| 11 | 0000 0011 | 0000 11 | 0000 01 | 0000 1 | 0000 0 | – | – |
| 12 | 0000 0010 | 0000 10 | 0000 1 | 0000 0 | – | – | – |
| 13 | 0000 0001 1 | 0000 01 | 0000 00 | – | – | – | – |
| 14 | 0000 0001 0 | 0000 00 | – | – | – | – | – |
| 15 | 0000 0000 1 | – | – | – | – | – | – |
| total_zeros | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|
| 0 | 0000 01 | 0000 01 | 0000 1 | 0000 | 0000 | 000 | 00 | 0 |
| 1 | 0001 | 0000 00 | 0000 0 | 0001 | 0001 | 001 | 01 | 1 |
| 2 | 0000 1 | 0001 | 001 | 001 | 01 | 1 | 1 | – |
| 3 | 011 | 11 | 11 | 010 | 1 | 01 | – | – |
| 4 | 11 | 10 | 10 | 1 | 001 | – | – | – |
| 5 | 10 | 001 | 01 | 011 | – | – | – | – |
| 6 | 010 | 01 | 0001 | – | – | – | – | – |
| 7 | 001 | 0000 1 | – | – | – | – | – | – |
| 8 | 0000 00 | – | – | – | – | – | – | – |
Chroma DC uses Table 9-9: (a) for the 2 × 2 block of 4:2:0, (b) for the 2 × 4 block of 4:2:2.
| total_zeros | 2 × 2: 1 | 2 | 3 |
|---|---|---|---|
| 0 | 1 | 1 | 1 |
| 1 | 01 | 01 | 0 |
| 2 | 001 | 00 | – |
| 3 | 000 | – | – |
| total_zeros | 2 × 4: 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 000 | 000 | 110 | 00 | 00 | 0 |
| 1 | 010 | 01 | 001 | 00 | 01 | 01 | 1 |
| 2 | 011 | 001 | 01 | 01 | 10 | 1 | – |
| 3 | 0010 | 100 | 10 | 10 | 11 | – | – |
| 4 | 0011 | 101 | 110 | 111 | – | – | – |
| 5 | 0001 | 110 | 111 | – | – | – | – |
| 6 | 0000 1 | 111 | – | – | – | – | – |
| 7 | 0000 0 | – | – | – | – | – | – |
run_before (Table 9-10)
The number of zeros directly before each coefficient, read from the last coefficient
backwards while zeros remain. Columns are zerosLeft.
| run_before | 1 | 2 | 3 | 4 | 5 | 6 | > 6 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 11 | 11 | 11 | 11 | 111 |
| 1 | 0 | 01 | 10 | 10 | 10 | 000 | 110 |
| 2 | – | 00 | 01 | 01 | 011 | 001 | 101 |
| 3 | – | – | 00 | 001 | 010 | 011 | 100 |
| 4 | – | – | – | 000 | 001 | 010 | 011 |
| 5 | – | – | – | – | 000 | 101 | 010 |
| 6 | – | – | – | – | – | 100 | 001 |
| 7 | – | – | – | – | – | – | 0001 |
| 8 | – | – | – | – | – | – | 0000 1 |
| 9 | – | – | – | – | – | – | 0000 01 |
| 10 | – | – | – | – | – | – | 0000 001 |
| 11 | – | – | – | – | – | – | 0000 0001 |
| 12 | – | – | – | – | – | – | 0000 0000 1 |
| 13 | – | – | – | – | – | – | 0000 0000 01 |
| 14 | – | – | – | – | – | – | 0000 0000 001 |