Logic behind the 63 character principal

I am reading the IC Interface Spec and came across this bit for the principal

Because the maximum size of a principal is 29 bytes, the textual representation will be no longer than 63 characters (10 times 5 plus 3 characters with 10 separators in between them).

Can someone explain the math for this? I can’t seem to understand it

29 bytes + 4 bytes checksum = 33 bytes = 264 bits of information need to be encoded

As the spec says, because of the grouping 63 characters offer 10*5+3=53 usable characters.

Since the characters are base32 this means 53*5=265 bits can be encoded.


Got it, and the hyphens are not encoded but shown when canonical principals are shown?

Hyphens are not part of the encoding in the sense that they don’t carry information about the encoded data. The grouping is applied (i.e. hyphens inserted) after the encoding to base32 is complete and first step of decoding is to drop them.

1 Like