Huffman’s coding method provides an optimal prefix code, which is optimal in the sense that the average codeword length is minimal. An example is given in the table.
The method begins by combining the least likely source words—here beginning with N and S—and effectively reducing the number of sourcewords at each stage. So with 5 source words there are necessarily 4 combination stages (C1–C4). The codeword for each source word is then read back from the right. The average codeword length is
which cannot be bettered.