Skip to content
← All questions

What is the definition of a variable-length code in information theory?

A variable-length code is a code whose codewords do not all have the same length. The condition requires that at least two codewords in the code have different bit lengths.

Conditions

  • Applies to a single code mapping across all symbols in its alphabet.
  • At least two codewords in the code have different bit lengths.

Reasoning, step by step

  1. Identify the set of codewords assigned to the source symbols under a specific code.
  2. Measure the bit length of each codeword.
  3. Check if there is any variation in the lengths.
  4. Conclude that the code is variable-length if at least one pair of codewords has different lengths.

Example

In the displayed example table, Codes 3, 4, 5, and 6 are marked as variable-length because different symbols receive binary strings of different sizes, such as 1-bit, 2-bit, or 4-bit words.

Common misconceptions

  • Assuming that variable-length means every codeword must have a unique length.
  • Confusing variable-length codes with prefix-free codes, which impose a structural constraint on the codewords.

Watch the explanation

Explore next

Answers are generated from source material and independently checked. Consult the original video or creator if something is unclear.