On this page
Huffman coding gives every symbol its own whole number of bits, so even a very common symbol costs at least one bit. Arithmetic coding drops that rule: it turns the entire message into one fraction between 0 and 1, and the more predictable the message, the fewer binary digits that fraction needs.
How does arithmetic coding work?
An early paper on the method is Jorma Rissanen's Generalized Kraft Inequality and Arithmetic Coding (1976). The 1987 paper by Ian Witten, Radford Neal and John Cleary, Arithmetic coding for data compression, says in its abstract that arithmetic coding "gives greater compression, is faster for adaptive models, and clearly separates the model from the channel encoding."
The method has three rules:
Start with the interval [0, 1).
For each symbol, split the current interval into pieces whose widths are proportional to the symbol probabilities, and keep the piece for the symbol you saw.
At the end, send the shortest binary fraction that lies inside the final interval.
A worked example: encoding AAAAB
Take a source with two symbols: A with probability 0.8 and B with probability 0.2. Give A the bottom 0.8 of any interval's width and B the top 0.2. Encode the five-symbol message AAAAB:
A: [0, 1) becomes [0, 0.8).
A: [0, 0.8) becomes [0, 0.64).
A: [0, 0.64) becomes [0, 0.512).
A: [0, 0.512) becomes [0, 0.4096).
B: the top 0.2 of [0, 0.4096) is [0.32768, 0.4096).
The final width is 0.8 × 0.8 × 0.8 × 0.8 × 0.2 = 0.08192, exactly the probability of the message. Now look for a short binary fraction inside [0.32768, 0.4096). No 1-bit or 2-bit fraction (0, 0.25, 0.5, 0.75) fits. Three bits give 0.375, which is 0.011 in binary (1/4 + 1/8), and 0.32768 ≤ 0.375 < 0.4096. So the whole message is sent as 011: three bits, where Huffman, with one bit per symbol, needs five.
How do you decode an arithmetic code?
The decoder knows the same probabilities and the message length (real coders send it or reserve an end-of-message symbol). It repeats one step: find the piece the number falls in, output that symbol, then stretch that piece back to [0, 1). For A the stretch is x ÷ 0.8; for B it is (x − 0.8) ÷ 0.2.
0.375 is below 0.8, so A. Rescale: 0.375 ÷ 0.8 = 0.46875.
Below 0.8, so A. Rescale: 0.5859375.
Below 0.8, so A. Rescale: 0.732421875.
Below 0.8, so A. Rescale: 0.91552734375.
At least 0.8, so B. Out comes AAAAB.
Why does arithmetic coding beat Huffman for skewed probabilities?
David Huffman's 1952 paper, A Method for the Construction of Minimum-Redundancy Codes, builds a minimum-redundancy code in which each symbol gets its own codeword of whole bits. That constraint is the weakness. Claude Shannon's A Mathematical Theory of Communication (1948) defines the entropy of a source, H = −Σ p log₂ p bits per symbol, which is the floor for the average length of any uniquely decodable code.
For our source, H = −0.8 log₂ 0.8 − 0.2 log₂ 0.2 ≈ 0.722 bits per symbol. Huffman spends 1 bit per symbol, about 38% more than that floor. The more skewed the probabilities, the worse it gets: a symbol with probability 0.99 carries only −log₂ 0.99 ≈ 0.0145 bits of information, yet Huffman still charges it a full bit. Arithmetic coding has no per-symbol rounding, so a very likely symbol costs a tiny fraction of a bit. New to entropy? Read why a fair coin carries 1 bit.
How is arithmetic coding linked to entropy?
Each symbol multiplies the width by its probability, so the final width is the message's probability P. Binary fractions with k bits are spaced 2^−k apart, so k = ⌈−log₂ P⌉ bits always reach inside. And −log₂ P is the sum of −log₂ p over the symbols: the message's information content.
For AAAAB, −log₂ 0.08192 ≈ 3.61, so 4 bits are guaranteed; we found 3 because the interval sat well. Real coders add a small overhead to mark where the code ends and to use whole-number arithmetic, but it stays small, so over long messages the bits per symbol approach the entropy H.
A checklist for arithmetic coding problems
Write each symbol's cumulative range first: A = [0, 0.8), B = [0.8, 1).
Update: new low = low + width × range start; new high = low + width × range end.
Check the final width equals the product of the probabilities.
Try 1-bit, 2-bit, 3-bit binary fractions until one lands inside.
Decode by finding the piece, then rescaling with (x − range start) ÷ p.
If binary feels shaky, warm up with logs and binary numbers and the binary reflected Gray code. For logarithms, probability and information, the Fermi Concept Library covers every concept in mathematics and computing, and Fermi's AI tutor can work out what you already know and build a plan for the session, so you sit down to a clear next step.



