Base64 Encode
Input
Output

Base64 encoding is a method used to encode binary data into ASCII characters. It is commonly used for transmitting data over protocols that can only handle ASCII characters, such as email or storing binary data in formats designed for text-based data.

Here's how the Base64 encoding process works:

1. Divide the input data into 6-bit groups: The binary data is divided into groups of 6 bits each. If the length of the binary data is not a multiple of 6, padding is added to make it so.

2. Map each 6-bit group to a character: Each 6-bit group is then mapped to a corresponding character in the Base64 alphabet. The Base64 alphabet consists of 64 characters, typically represented as A-Z, a-z, 0-9, '+', and '/'. These characters represent the values 0 to 63.

3. Padding: If the length of the input data is not divisible by 3, padding characters '=' are added to make the length a multiple of 4.

Let's illustrate this process with an example:

Example: Encode "Hello" into Base64

1. Convert "Hello" into binary:

• H: 01001000
• e: 01100101
• l: 01101100
• l: 01101100
• o: 01101111

Concatenate these binary representations: 01001000 01100101 01101100 01101100 01101111

2. Group the binary data into 6-bit groups:

• 010010 000110 010101 101100 110011 011011 110011 011011 110111
3. Convert each 6-bit group into its corresponding Base64 character:

• 010010 -> S
• 000110 -> G
• 010101 -> l
• 101100 -> u
• 110011 -> z
• 011011 -> b
• 110011 -> z
• 011011 -> b
• 110111 -> v
4. Concatenate the Base64 characters: SGxuZmJv

5. If the length of the input data is not divisible by 3, add padding '=' characters:

• In this case, the length of the input data "Hello" is 5, which is not divisible by 3. So, one '=' padding character is added.

So, the Base64 encoding of "Hello" is "SGxuZmJv".

That's how the Base64 encoding process works! It converts binary data into a human-readable format using a set of 64 ASCII characters.