https://en.wikipedia.org/wiki/Huffman_coding

As in other entropy encoding methods, more common symbols are generally represented using fewer bits than less common symbols. However, although optimal among methods encoding symbols separately, Huffman coding is not always optimal among all compression methods - it is replaced with arithmetic coding or asymmetric numeral systems if better compression ratio is required.

Example

Huffman tree generated from the exact frequencies of the text “this is an example of a huffman tree”.

Huffman Tree

Huffman Code