# How do I calculate Base64 conversion rate?

Basically I need to have a base64 encoded signature that has to be 96 characters long. However, I do not know what length I need to have the signature at so when I encode it, it can be that exact size. Does anyone know how to convert it? Also, does anyone know how to convert it in base64 encoding or any byte size encoding?

However, I do not know what length I need to have the signature at so when I encode it, it can be that exact size.

Well, base64 uses 4 characters (from an alphabet of size 64) to encode 3 bytes (3 bits contain 24 bits; 24/4 = 6 bits per base64 character).

Hence, if the signature was 72 bytes long, that would translate to 72/3*4 = 96 characters you require.

Now, base64 typically has a === trailer to signify the end of the encoding; are you counting that?

• Okay, thanks a lot for clearing it up poncho. – John Chen Sep 14 at 22:35
• Some base64 (mostly PEM and MIME and derivatives thereof) has padding which can be 1 or 2 equalsign but never 3, and is not present if the input is an exact multiple of 3. PGP 'armor' does have a trailer with 1 equalsign followed by 4 base64 chars (exactly) encoding CRC24. – dave_thompson_085 Sep 15 at 2:44
• Per Base64, $b>0$ byte(s) encode to $c=4\,\left\lceil b/3\right\rceil$ characters ending in $n=2-(b+2\bmod 3)=(-b)\bmod3$ time(s) the character =. And for decoding, $c$ characters with $c$ multiple of $4$, ending in $n$ times the character = with $0\le n<3$, decode to $b=3\,c/4-n$ byte(s). – fgrieu Sep 15 at 5:18
• – kelalaka Sep 15 at 7:46

base64 is defined on rfc4648

As poncho mentions, it has an overhead of 33%, and thus 96 / 4 × 3 = 72 bytes needed

• In this answer, it is meant bytes where there now is characters. – fgrieu Sep 15 at 5:19
• Indeed. Fixed. Thanks @fgrieu – Ángel Sep 15 at 22:30