The cross entropy of discrete probability distributions and
on the same countable set
, for
, is
where a term is infinite when and
. In terms of the Shannon
entropy
and relative entropy
,
When
is finite, it therefore equals
exactly when
.
For binary coding, suppose a prefix-free code assigns the codeword for a length of
bits, which is possible when
on its support and each
positive
is a power of
by the Kraft inequality. If the source instead
generates
with probability
and
whenever
, the expected length
is
bits
per symbol (3Blue1Brown 2026).