rice-coding · also Rice code, Golomb-Rice coding

Rice coding

Rice coding is Golomb coding with a power-of-two divisor, storing an unsigned integer as a unary quotient followed by a fixed-width remainder.

Bit cost: With parameter k, the divisor is 2^k and the codeword length for x is floor(x/2^k) + 1 + k bits. A poor k makes the unary part expensive; smaller inputs alone do not guarantee a smaller complete record. [2]

FLAC: Signed prediction residuals are folded with ZigZag before coding. Partitions have their own 4-bit or 5-bit parameter field. Its all-ones value escapes to fixed-width signed residuals, with a further 5-bit width field; width zero represents an all-zero partition. [1]

Zero-run arithmetic: For one partition of N zero residuals, k = 0 costs N bits after the parameter field; the zero-width escape costs 5. Escape wins when N > 5, ties at 5 and loses below 5. This compares residual modes with the same surrounding structure, not complete FLAC files; a constant subframe is another choice. [2]

Interpretation: Decoding needs k and the residual count. A valid codeword is not an integrity check, and the Rice payload omits prediction state and container metadata. [1]

Relations

related
Prefix-free code, Golomb coding, ZigZag encoding, Lossless compression, Huffman coding

Citations

  1. RFC 9639: FLAC, sections 4.4 and 9.2.7 (Rice codes and escaped partitions) (accessed 2026-11-17)
  2. Hesela: exact Golomb/Rice bit-cost examples and partition accounting (accessed 2026-11-17)

Further reading

  1. Hesela: prefix decoding, Rice parameters and payload accounting (accessed 2026-11-17)
Sources & caveats
  • The partition threshold is exact format arithmetic, not a measured audio compression ratio or an encoder-policy recommendation.
  • The worked model accounts for method, partition order and parameter fields separately; frame headers, warm-up samples, padding and checksums are excluded.
  • Tests and generated examples: https://hesela.dev/research/golomb-rice.test.mjs and https://hesela.dev/research/golomb-rice.json.

JSON: /data/terms/rice-coding.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. Rice coding. Hesela. 2026-11-17. https://hesela.dev/terms/rice-coding/