A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Arithmetic Coding

Graduate Depth 93 in the knowledge graph I know this Set as goal
3topics build on this
415prerequisites beneath it
See this on the map →
Shannon EntropySource Coding Theorem+1 moreData Compression Basics
arithmetic coding lossless compression entropy coding interval coding

Core Idea

Arithmetic coding represents an entire message as a single number in the interval [0, 1), achieving compression rates arbitrarily close to the source entropy. Unlike Huffman coding, which assigns a discrete codeword to each symbol, arithmetic coding encodes sequences by successively narrowing a subinterval: each symbol shrinks the current interval proportionally to its probability. The final interval width is the product of all symbol probabilities, and specifying a point within it requires approximately -log2 of that product = sum of -log2(p_i) bits — exactly the information content. Arithmetic coding is theoretically optimal and is the basis of modern entropy coders like ANS (asymmetric numeral systems).

Explainer

Huffman coding assigns integer-length codewords to individual symbols, which limits it to at most 1 bit above entropy per symbol. Arithmetic coding removes this limitation by encoding entire messages as single numbers, effectively achieving fractional bit lengths per symbol.

The idea is beautifully simple. The unit interval [0, 1) is partitioned among the alphabet symbols proportionally to their probabilities. The first symbol in the message selects the corresponding subinterval. That subinterval is then partitioned again in the same proportions, and the second symbol selects a sub-subinterval. This continues for every symbol. After processing the entire message, you have a tiny interval whose width equals the probability of the specific message (the product of all symbol probabilities for i.i.d. sources). To transmit the message, you send enough bits to uniquely identify a point inside that interval — approximately -log2(width) bits.

The magic is that -log2(product of probabilities) = sum of -log2(p_i), which is exactly the information content of the message. More probable messages produce wider intervals requiring fewer bits; improbable messages produce narrow intervals requiring more bits. Over many symbols, the average rate converges to the entropy H(X). The overhead is at most 2 bits for the entire message (to handle interval boundaries and termination), making the per-symbol overhead negligible for long sequences.

In practice, arithmetic coding operates on integers using finite-precision arithmetic, with a "renormalization" step that outputs bits as the interval narrows and shifts, keeping the working precision manageable. Modern variants like ANS (asymmetric numeral systems), used in Facebook's Zstandard and Apple's LZFSE, achieve the same theoretical optimality with higher throughput by encoding the state as a single integer rather than maintaining interval endpoints. Context-adaptive arithmetic coding (as in H.265/HEVC video compression) pairs the arithmetic coder with a sophisticated context model, achieving compression rates that track the conditional entropy given recent context — far surpassing what per-symbol Huffman can achieve.

Practice Questions 3 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersDividing IntegersUnit RatesProportionsPercent ConceptConverting Between Fractions, Decimals, and PercentsOperations with Rational NumbersTwo-Step EquationsSolving Multi-Step EquationsEquations with Variables on Both SidesAngle Pairs: Complementary, Supplementary, and VerticalParallel Lines and TransversalsCorresponding AnglesAlternate Interior AnglesTriangle Angle Sum TheoremExterior Angle TheoremTriangle Inequality TheoremSimilar Triangles: AA SimilaritySimilar Triangles: SSS and SAS SimilarityProportions in Similar TrianglesRight Triangle Trigonometry IntroductionSine, Cosine, and Tangent RatiosTrigonometric Ratios ReviewRadian MeasureConverting Between Degrees and RadiansThe Unit CircleGraphing Sine and CosineGraphing Tangent and Reciprocal Trigonometric FunctionsDerivatives of Trigonometric FunctionsAntiderivativesIndefinite IntegralsBasic Integration RulesRiemann SumsDefinite Integral DefinitionProbability Density Functions and Continuous DistributionsCumulative Distribution FunctionsContinuous Random VariablesProbability Density FunctionsExpected ValueShannon EntropySource Coding TheoremHuffman CodingArithmetic Coding

Longest path: 94 steps · 415 total prerequisite topics

Prerequisites (3)

Leads To (1)