🚧 App in Alpha. Features subject to change/break without notice.

EJ's Notebook - Variable-Length Strings Store Information in their Length

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 n, you can represent 64n unsigned integers, corresponding to the range:

[0,64n1]=[0,64n)

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 n characters is computed by this geometric series:

k=0n164k=64n+1163

We can expand 64n+1-163 as:

64n+1-163=1+64+642++64n

By comparing this to the first expression, we can see that:

64n<(1+64+642++64n-1)+64n

The second expression is equal to the first plus a bunch of positive terms 1+64++64n-1, making it larger than 64n 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.

609:07 AM