Variable-Length Strings Store Information in their Length
Posted Nov 3, 2025 | ~2 minute read
In a traditional fixed-length base-64 string of length , you can represent unsigned integers, corresponding to the range:
But when you allow variable-length strings (including the empty string), each additional character position opens up a whole new tier of representable values. The total number of distinct encodable integers using up to characters is computed by this geometric series:
We can expand as:
By comparing this to the first expression, we can see that:
The second expression is equal to the first plus a bunch of positive terms , making it larger than alone. That added information is encoded by the string's length.
Another way to think of this is that your typical numeral permits leading zeros, meaning that "12" is equal to "012" is equal to "0012", etc. Using a bijective base-64 encoding, each string of characters maps uniquely to a natural number. Leading zeros are therefore not semantically void. Because "12", "012" and "0012" are different strings, they represent different integers.

