Base64 Encoder/Decoder

Conversion between Base64 and plaintext.


Example: Q29udmVydGVyc0hvbWU= (Base64) or ConvertersHome (plaintext)









Base64 Definition

In computer programming, Base64 is a group of binary-to-text encoding schemes that transforms binary data into a sequence of printable characters, limited to a set of 64 unique characters. More specifically, the source binary data is taken 6 bits at a time, then this group of 6 bits is mapped to one of 64 unique characters.

Characters Used

Base64 encoding uses a set of 64 characters: the uppercase and lowercase letters A-Z, the numbers 0-9, plus two more characters which vary by system, commonly + and / for the last two. For URL-safe encoding, these last two characters are often replaced with - and _.

Encoding Process

  1. Binary Conversion: The original data is converted into binary.
  2. Divide into Chunks: The binary data is divided into chunks of 6 bits because 6 bits (2^6) can represent 64 different values, which matches the Base64 character set.
  3. Mapping to Characters: Each 6-bit chunk is then mapped to a corresponding character in the Base64 alphabet.
  4. Padding: ince Base64 encoding requires the input to be divisible by 3 bytes (24 bits), padding is added if the input is not of the right length. The = character is used as padding at the end of the encoded data.

Example

Let's take the text "Hi" as an example:

  1. "Hi" in ASCII is 72 105 in decimal, 48 69 in hexadecimal, and 01001000 01101001 in binary.
  2. These binary bytes are split into 6-bit chunks: 010010 000110 1001.
  3. Since the last group is only 4 bits, it's padded with two zeros: 010010 000110 100100.
  4. These chunks are then converted to decimal: 18 6 36.
  5. Using the Base64 index table, these numbers correspond to the characters SGk=.
                  
    Value:     0   1  ...   25  26   ...   51   52   ...   61   62   63
    Character: A   B  ...   Z   a    ...   z    0    ...   9    +    /
                  
                
  6. The final Base64-encoded string is SGk=, where the = indicates padding was added.