Base64 is an encoding scheme that converts binary data
(like images, files, or any non-text data)
into a text representation using a set of 64 different characters
(letters, digits, and symbols).
This is useful for transmitting binary data over media that are designed to handle text,
such as email or URLs.
It works by dividing the binary data into chunks of 6 bits and then
mapping each 6-bit chunk to a character from the Base64 alphabet.
This ensures that the encoded data is always ASCII text,
which can be safely transmitted in environments that may not support binary.
Example:
Let's take the text "Man" and encode it in Base64:
The ASCII values for "M", "a", "n" are:
'M' = 77
'a' = 97
'n' = 110
Convert these values to binary:
77 = 01001101
97 = 01100001
110 = 01101110
Combine all the binary data:
010011010110000101101110
Split into 6-bit groups:
010011 010110 000101 101110
Map each 6-bit group to the Base64 alphabet:
010011 → 'T'
010110 → 'W'
000101 → 'F'
101110 → 'u'
So, the Base64 encoding of "Man" is "TWFu".
Decoding:
To decode Base64, the reverse process is applied, converting the Base64 characters back into their original binary form and then into the corresponding data (text, image, etc.).