Base64 Ting (230313)

Shiewhun
2 min readMar 13, 2023
Go

As a backend programmer, you’d be doing a lot of base64 encoding, I bet.
Base64 encoding means your data to be transmitted/stored is transformed into a set of characters with each one belonging to a 64-character set amongst ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

that’s:

a — z = 26
A — Z = 26
0–9 = 10
+ and / = 2
26 + 26 + 10 + 2 = 64 (characters)

you will sometimes find = or == at the end, this is because the result of a Base64 encoded string has to be a multiple of 4.

E.g the word “apple” in base64 is actually YXBwbGU but YXBwbGU is 7 characters, and 7 isn’t a multiple of 4. Therefore you need to add some padding, which is usually the “=” character; now go google and find a random base64 encoder that tells you “apple” in base64 isn’t YXBwbGU=

********

Trivia: Base64 encoding was invented so that we could send things in emails other than text because when emails were first invented, the machines that used them were only text-display readers. Nothing like images or video could be displayed, but then machines got better and we needed to send things other than text in emails. And it turned out that encoding your data (in its binary form. remember everything gets turned to binary in order to be transmitted [Layer 1 of the OSI]) in base64 encoding was optimal to solve the problem.

Now, if you wish you can go figure out how “apple” is encoded to “YXBwbGU=” cus it is something you can actually do by hand (aided with the Base64 character set reference and an ability to turn decimal numbers to binary)

--

--