{
  "slug": "prefix-free-code",
  "term": "Prefix-free code",
  "aliases": [
    "Prefix code",
    "Instantaneous code"
  ],
  "definition": "A prefix-free code assigns distinct codewords so that none is a prefix of another, allowing immediate symbol decoding from a known boundary.",
  "note": "Decoding: With the same codebook and a known starting boundary, a decoder can recognize each symbol without reading the next symbol. Huffman coding constructs prefix-free codes. Prefix freedom alone does not guarantee resynchronization after a lost bit. [huffman1952] [rfc1951]\n\nLengths: Binary codeword lengths l must satisfy sum(2^-l) <= 1 for unique decoding. This condition guarantees that a prefix-free assignment with those lengths exists, not that any assignment works. A=0, B=01, C=10 has sum 1, yet 010 represents either AC or BA. [mcmillan1956] [hesela-codebooks]\n\nScope: Prefix freedom is sufficient but not necessary for unique decoding. The codewords 1, 10 and 100 are uniquely decodable without being prefix-free. This broader property does not promise immediate left-to-right symbol decisions. [mcmillan1956]\n\nRecovery: Parsing valid codewords does not verify the intended message or its completeness. Canonical reconstruction still needs symbol order and the format's assignment rules; code lengths alone do not supply those conventions. Prefix-free parsing for BWT construction is a different technique. [rfc1951] [hesela-codebooks]",
  "related": [
    "uniquely-decodable-code",
    "huffman-coding",
    "rice-coding",
    "prefix-free-parsing"
  ],
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-18",
  "citations": [
    {
      "id": "huffman1952",
      "title": "David A. Huffman (1952): A Method for the Construction of Minimum-Redundancy Codes, pp. 1098-1099",
      "url": "https://web.stanford.edu/class/ee398a/handouts/papers/Huffman%20-%20Min%20Redundancy%20Codes%20-%20IRE52.pdf",
      "accessed": "2026-11-18"
    },
    {
      "id": "rfc1951",
      "title": "RFC 1951: prefix codes and canonical Huffman assignment, sections 3.2.1-3.2.2",
      "url": "https://www.rfc-editor.org/rfc/rfc1951.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "mcmillan1956",
      "title": "Brockway McMillan (1956): Two Inequalities Implied by Unique Decipherability, IRE Transactions on Information Theory 2(4), 115-116",
      "url": "https://doi.org/10.1109/TIT.1956.1056818",
      "accessed": "2026-11-18"
    },
    {
      "id": "hesela-codebooks",
      "title": "Hesela: equal codeword lengths can hide an ambiguous assignment",
      "url": "https://hesela.com/analyses/compressed-archives-dictionary-dependencies/#prefix-codebooks",
      "accessed": "2026-11-18"
    }
  ],
  "provenance": [
    "McMillan's Discussion was checked in indexed original-paper text; direct retrieval of the university PDF mirror timed out. The theorem and its converse are distinguished from the constructed example.",
    "The codebook examples are exact teaching arithmetic, not a native codec experiment, error-rate estimate or general unique-decodability tester."
  ]
}
