{
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-19",
  "slug": "huffman-coding",
  "term": "Huffman coding",
  "aliases": [
    "Huffman code"
  ],
  "definition": "Huffman coding constructs a prefix code that minimizes average codeword length for given symbol frequencies.",
  "note": "Optimality: The 1952 construction repeatedly combines the two least likely messages. Its guarantee minimizes expected codeword length for the specified probabilities under the prefix-code model and equal cost per coding digit; it does not minimize every file or its metadata. Equal-frequency choices can yield different optimal codes. [huffman1952]\n\nDecoding: The symbol-to-code mapping and stream boundaries remain necessary. The lengths 1,2,3,3 alone do not distinguish swapping the codewords assigned to C and D; canonical reconstruction also needs symbol order and the format rules. DEFLATE describes canonical codes using ordered code lengths; length zero means an unused symbol. Its single used distance symbol still has a one-bit code. These are format rules, not a universal single-symbol policy. [rfc1951-prefix]\n\nAccounting: A shorter symbol payload need not yield a smaller file after codebook and framing costs. The linked four-symbol example uses 28 payload bits instead of 32 fixed-width bits. [hesela-prefix-rice]\n\nIntegrity: A changed bit can still form valid codewords with unchanged decoded length; prefix validity is not an integrity check. The linked exact example decodes ABCD as ABCC after one bit changes. [hesela-prefix-rice]",
  "related": [
    "prefix-free-code",
    "deflate",
    "finite-state-entropy",
    "lossless-compression",
    "rice-coding",
    "wavelet-tree",
    "wavelet-matrix",
    "tunstall-coding",
    "comma-free-code",
    "entropy-coding",
    "arithmetic-coding"
  ],
  "citations": [
    {
      "id": "huffman1952",
      "title": "David A. Huffman (1952), A Method for the Construction of Minimum-Redundancy Codes, Proceedings of the IRE 40(9), 1098-1101; DOI 10.1109/JRPROC.1952.273898",
      "url": "https://web.stanford.edu/class/ee398a/handouts/papers/Huffman%20-%20Min%20Redundancy%20Codes%20-%20IRE52.pdf",
      "accessed": "2026-11-17"
    },
    {
      "id": "rfc1951-prefix",
      "title": "RFC 1951: prefix codes and DEFLATE code descriptions, sections 3.2.1-3.2.2 and 3.2.7",
      "url": "https://www.rfc-editor.org/rfc/rfc1951.html",
      "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": [
    "Source synthesis and a synthetic prefix-code illustration; not a complete DEFLATE decoder, optimal-file-size guarantee or measured corruption rate."
  ]
}
