Prelimiaries:
- Binary strings, that is, strings being built from language {0, 1}.
- A set S of strings is prefix-free if no string in S is a proper prefix of a string in S.
How to prove that for every prefix-free set S, $\sum_{p \in S}{2^{-|p|}} \leq 1$.
First assume that $S$ is finite, and the longest string in $S$ has length $n$. For each $s \in S$, denote by $A_s$ the set of strings $x \in \{0,1\}^n$ that have $s$ as a prefix. Clearly $|A_s|=2^{n-|s|}$, and the hypothesis that $S$ is prefix free implies that the $A_s \cap A_p =\emptyset$ for $ s \ne p$ in $S$. Therefore $$2^n=|\{0,1\}^n| \ge \sum_{s \in S} |A_s|= \sum_{s \in S} 2^{n-|s|} \,,$$ so $1 \ge \sum_{s \in S} 2^{ -|s|}$, as required.
Finally, if $S$ is infinite, let $S_m$ denote the set of strings in $S$ of length at most $m$. We already know that $\sum_{s \in S_m} 2^{-|s|} \le 1$. Letting $m \to \infty$ concludes the proof.
Edit: The inequality is a special case of the Kraft-Mcmillan inequality, which is valid for uniquely decodable codes, see https://en.wikipedia.org/wiki/Kraft%E2%80%93McMillan_inequality#:~:text=Kraft's%20inequality%20limits%20the%20lengths,than%20or%20equal%20to%20one.