encoding.info
You are hereSourcePredictionTransformEntropy codingFiltersFramesDecisionsRate controlPerceptionQualityBitstreamSettingsEncoder map
Page 4 of 6 in Entropy coding

Variable-length versus arithmetic coding

Entropy coding · concept · added 2026-11-14

In Brief:
A variable-length code spends whole bits, and gets below one bit per symbol only by letting symbols share a codeword. An arithmetic coder spends fractions without grouping. This page measures both against the entropy that bounds them.

A variable-length code spends whole bits on codewords, and gets below one bit per symbol only by letting symbols share a codeword. An arithmetic coder narrows one interval and spends fractions. This page puts the two side by side on the same flags, against the entropy that bounds them both.

Group the flags

Group the flags

A flag here is a symbol with two possible values, zero or nonzero. The demo prices 1,024 invented flags under a model that treats each flag as independent. The slider fixes how many are zero; a fixed shuffle fixes where. The first three readouts are bits per flag; the last counts codewords.

Grouped, expected is a variable-length code: a Huffman code built for the model, with one codeword for each possible group of flags. The readout is its expected length under the model. With one flag per codeword it is exactly one bit.

Arithmetic, counted runs an arithmetic coder's integer arithmetic on the flags shown, with their share of zeros as its fixed probability, and counts the bits it would write. Entropy is the bound for the model.

90%
← 50%: even odds99%: almost always zero →
The flags
Bits per flag
coral: grouped, expectedteal: arithmetic, countedgray: entropy
Grouped, expected
Arithmetic, counted
Entropy
Codewords
Simplified demo: the flags are invented; gray is zero and teal is nonzero. The number of zeros is the slider's value rounded to a whole number of the 1,024 flags, 922 at 90%. The two coders are measured differently: the grouped code's figure is an expected length under the model, and the arithmetic coder's is a count for the sequence shown. The arithmetic coder is not any codec's. Its probability never changes, it keeps no bits, and its count ends with two bits plus any it had deferred, enough to pick a number inside the final interval. Neither figure includes telling the decoder the probabilities or the number of flags. These are bits per flag under the model, not a bitrate.

Measured:

The two coders in x264

x264 has both kinds. Its arithmetic coder, context-adaptive binary arithmetic coding (CABAC), is on by default. --no-cabac selects context-adaptive variable-length coding (CAVLC) instead, and so do the ultrafast preset, the fastdecode tuning and the Baseline profile.

EncoderCoderCodes
x264, --no-cabacVariable-lengthWhole codewords
x264, defaultArithmeticTwo-valued decisions
x265ArithmeticTwo-valued decisions
libaomArithmeticSymbols of up to 16 values

x265's Entropy::encodeBin is an arithmetic coder of the same kind as x264's, and its option list has no switch for another. libaom's od_ec_encode_cdf_q15 codes a symbol of up to 16 values in one step.

Trade-offs

Sources

Read 2026-11-14 and 2026-11-15, at the commits linked.