encyclopegia.org

Golomb coding

Golomb coding is a lossless data compression method using a family of data compression codes invented by Solomon W. Golomb in the 1960s. Alphabets following a geometric distribution will have a Golomb code as an optimal prefix code, making Golomb coding highly suitable for situations in which the occurrence of small values in the input stream is significantly more likely than large values.

Golomb coding is a lossless data compression method using a family of data compression codes invented by Solomon W. Golomb in the 1960s. Alphabets following a geometric distribution will have a Golomb code as an optimal prefix code, making Golomb coding highly suitable for situations in which the occurrence of small values in the input stream is significantly more likely than large values. ===Construction of codes=== Golomb coding uses a tunable parameter to divide an input value into two parts: , the result of a division by , and , the remainder. The quotient is sent in unary coding, followed by the remainder in truncated binary encoding. When M=1 , Golomb coding is equivalent to unary coding. Golomb–Rice codes can be thought of as codes that indicate a number by the position of the bin ( ), and the offset within the bin ( ). The example figure shows the position and offset for the encoding of integer using Golomb–Rice parameter , with source probabilities following a geometric distribution with . Formally, the two parts are given by the following expression, where is the nonnegative integer being encoded: q = \left \lfloor \frac{x}{M} \right \rfloor and r = x - qM. Both and will be encoded using variable numbers of bits: by a unary code, and by bits for Rice code, or a choice between and bits for Golomb code (i.e. is not a power of 2), with b = \lfloor\log_2(M)\rfloor . If r , then use bits to encode ; otherwise, use +1 bits to encode . Clearly, b=\log_2(M) if is a power of 2 and we can encode all values of with bits. The integer treated by Golomb was the run length of a Bernoulli process, which has a geometric distribution starting at 0. The best choice of parameter is a function of the corresponding Bernoulli process, which is parameterized by p = P(x=0) the probability of success in a given Bernoulli trial. is either the median of the distribution or the median ±1. It can be determined by these inequalities: (1-p)^M + (1-p)^{M+1} \leq 1 which are solved by M = \left\lceil -\frac{\log(2 -p)}{\log(1-p)}\right\rceil. For the example with : M = \left\lceil -\frac{\log(1.8)}{\log(0.8)}\right\rceil = \left\lceil 2.634 \right\rceil = 3. The Golomb code for this distribution is equivalent to the Huffman code for the same probabilities, if it were possible to compute the Huffman code for the infinite set of source values. ===Use with signed integers=== Golomb's scheme was designed to encode sequences of non-negative numbers. However, it is easily extended to accept sequences containing negative numbers using an overlap and interleave scheme, in which all values are reassigned to some positive number in a unique and reversible way. The sequence begins: 0, −1, 1, −2, 2, −3, 3, −4, 4, ... The n-th negative value (i.e., ) is mapped to the n th odd number ( ), and the m th positive value is mapped to the m-th even number ( ). This may be expressed mathematically as follows: a positive value is mapped to ( x' = 2|x| = 2x,\ x \ge 0 ), and a negative value is mapped to ( y' = 2|y| - 1 = -2y - 1,\ y ). Such a code may be used for simplicity, even if suboptimal. Truly optimal codes for two-sided geometric distributions include multiple variants of the Golomb code, depending on the distribution parameters, including this one. quotient = q = floor(N/M) remainder = r = N modulo M Generate codeword The code format : , where Quotient code (in unary coding) Write a q-length string of 1 bits (alternatively, of 0 bits) Write a 0 bit (respectively, a 1 bit) Remainder code (in truncated binary encoding) Let b = \lfloor\log_2(M)\rfloor If r code r in binary representation using b bits. If r \ge 2^{b+1}-M code the number r+2^{b+1}-M in binary representation using b + 1 bits. Decoding: Decode the unary representation of q (count the number of 1 in the beginning of the code) Skip the 0 delimiter Let b = \lfloor\log_2(M)\rfloor Interpret next b bits as a binary number r. If r' holds, then the remainder r = r' Otherwise interpret b + 1 bits as a binary number r, the remainder is given by r = r' - 2^{b+1} + M Compute N = q * M + r Set . Thus b = \lfloor\log_2(10)\rfloor = 3 . The cutoff is 2^{b+1} - M = 16 - 10 = 6 . | |} For example, with a Rice–Golomb encoding using parameter , the decimal number 42 would first be split into = 4 and = 2, and would be encoded as qcode( ),rcode( ) = qcode(4),rcode(2) = 11110,010 (you don't need to encode the separating comma in the output stream, because the 0 at the end of the code is enough to say when ends and begins; both the qcode and rcode are self-delimited). Given an alphabet of two symbols, or a set of two events, P and Q, with probabilities p and ( ) respectively, where , Golomb coding can be used to encode runs of zero or more P′s separated by single Q′s. In this application, the best setting of the parameter M is the nearest integer to - \frac{1}{\log_{2}p} . When p = 1/2, M = 1, and the Golomb code corresponds to unary ( P′s followed by a Q is encoded as n ones followed by a zero). If a simpler code is desired, one can assign Golomb–Rice parameter (i.e., Golomb parameter M=2^b ) to the integer nearest to - \log_2(-\log_2 p) ; although not always the best parameter, it is usually the best Rice parameter and its compression performance is quite close to the optimal Golomb code. (Rice himself proposed using various codes for the same data to figure out which was best. A later JPL researcher proposed various methods of optimizing or estimating the code parameter. ) Consider using a Rice code with a binary portion having bits to run-length encode sequences where P has a probability . If \mathbb{P}[\text{bit is part of }k\text{-run}] is the probability that a bit will be part of an -bit run ( k-1 Ps and one Q) and (\text{compression ratio of }k\text{-run}) is the compression ratio of that run, then the expected compression ratio is \begin{align} \mathbb{E}[\text{compression ratio}] &= \sum_{k=1}^\infty (\text{compression ratio of }k\text{-run}) \cdot \mathbb{P}[\text{bit is part of }k\text{-run}] \\ &= \sum_{k=1}^\infty \frac{b+1+\lfloor 2^{-b}(k-1) \rfloor}{k} \cdot kp^{k-1} (1-p)^2 \\ &= (1-p)^2 \sum_{j=0}^\infty (b+1+j) \cdot \sum_{i=j2^b+1}^{(j+1)2^b} p^{i-1} \\ &= (1-p)^2 \sum_{j=0}^\infty (b+1+j) \cdot \left(p^{2^b j} - p^{2^{b} (j+1)}\right) \\ &= (1-p) \cdot \left (b + \sum_{m=0}^\infty p^{2^b m} \right ) \\ &= (1-p) \cdot \left(b + {\left (1-p^{2^b} \right )}^{-1}\right ) \\ \end{align} Compression is often expressed in terms of 1-\mathbb{E}[\text{compression ratio}] , the proportion compressed. For p \approx 1 , the run-length coding approach results in compression ratios close to entropy. For example, using Rice code b=6 for p=0.99 yields compression, while the entropy limit is . ==See also== Elias delta coding Variable-length code Exponential-Golomb coding ==Further reading== Golomb, Solomon W. (1966). Run-length encodings. IEEE Transactions on Information Theory, IT--12(3):399--401 Robert F. Rice (1979), "Some Practical Universal Noiseless Coding Techniques", Jet Propulsion Laboratory, Pasadena, California, JPL Publication 79—22, March 1979. Witten, Ian Moffat, Alistair Bell, Timothy. "Managing Gigabytes: Compressing and Indexing Documents and Images." Second Edition. Morgan Kaufmann Publishers, San Francisco CA. 1999 David Salomon. "Data Compression", . H. S. Malvar, Adaptive run-length/Golomb–Rice encoding of quantized generalized Gaussian sources with unknown statistics, Proc. Data Compression Conference, 2006. RLGR Entropy Encoding, Microsoft MS-RDPRFX Open Specification, RemoteFX codec for Remote Desktop Protocol. S. Büttcher, C. L. A. Clarke, and G. V. Cormack. Information Retrieval: Implementing and Evaluating Search Engines . MIT Press, Cambridge MA, 2010.

References

No reference rows published for this article.

Cite this article

MLA

"Golomb coding." encyclopegia.org, 2026, https://encyclopegia.org/wiki/golomb-coding. Accessed 25 November 2026.

Chicago

"Golomb coding." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/golomb-coding.

APA

encyclopegia.org. (2026). Golomb coding. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/golomb-coding

Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

arithmetic coding

stub · references available

Advanced Video Coding

stub · references available

Golomb sequence

stub · references available

Coding Technologies

stub · references available

entropy coding

stub · references available

Golomb

stub · references available

superdense coding

stub · references available

Unified Speech and Audio Coding

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1345943629 · 0.5 · snapshot enwiki-001345943629

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.