{
  "status": "unknown",
  "advantages": [],
  "limitations": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-17",
  "slug": "rice-coding",
  "term": "Rice coding",
  "aliases": [
    "Rice code",
    "Golomb-Rice coding"
  ],
  "definition": "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.",
  "note": "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. [rice-costs]\n\nFLAC: 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. [flac-rice]\n\nZero-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. [rice-costs]\n\nInterpretation: 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. [flac-rice]",
  "related": [
    "prefix-free-code",
    "golomb-coding",
    "zigzag-encoding",
    "lossless-compression",
    "huffman-coding"
  ],
  "citations": [
    {
      "id": "flac-rice",
      "title": "RFC 9639: FLAC, sections 4.4 and 9.2.7 (Rice codes and escaped partitions)",
      "url": "https://www.rfc-editor.org/rfc/rfc9639.html#section-9.2.7",
      "accessed": "2026-11-17"
    },
    {
      "id": "rice-costs",
      "title": "Hesela: exact Golomb/Rice bit-cost examples and partition accounting",
      "url": "https://hesela.dev/research/golomb-rice.mjs",
      "accessed": "2026-11-17"
    },
    {
      "id": "hesela-prefix-rice",
      "title": "Hesela: prefix decoding, Rice parameters and payload accounting",
      "url": "https://hesela.com/analyses/compressed-archives-dictionary-dependencies/#prefix-rice",
      "accessed": "2026-11-17"
    }
  ],
  "provenance": [
    "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."
  ]
}
