Follows from proof of Shannon’s noiseless coding theorem

Set and construct a prefix free code with word lengths by taking the in increasing order ensuring that previous codewords are not prefixes.
The Kraft’s inequality ensures there is enough room.