This page was translated from Spanish with AI. The original version is in Spanish: read the original.

Decoding and encoding base64 with pen and paper

June 13, 20241 minute

Base64 is well known and widely used, but have you ever wondered how to decode/encode it by hand?

Decoding and encoding base64 with pen and paper

Base64 is well known and widely used, but have you ever wondered how to decode/encode it by hand?

First we pick a sample string, for example “Hola” (“Hello” in Spanish), which is the one used in the images.

Then we convert each character of the string Hola to ASCII. We can do this by looking it up in an ASCII table

Once we have the ASCII values, we can convert them to binary. It is important that the bytes are 8 bits long

Then we split the bits into groups of 6. In this case the last group is left with only 2 bits, so we add 4 zeros on the right to pad it

We convert the binary to decimal

Finally, using the base64 table, we convert the decimal values to characters. Note that the number of characters in the final encoded string has to be a multiple of 4; if it isn’t, we have to add “=” until it is

To decode the message by hand, you would simply follow the same process in reverse