Base64 Encode & Decode

What is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data using a 64-character set consisting of uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and two additional symbols (+ and /). It's widely used to transmit data over media that are designed to handle text, ensuring the data remains intact without modification during transport.

A Base64 URL variant exists which replaces + and / with - and _ respectively, to avoid issues in filenames and URLs.

Read more about Base64

How It Works

Encoding: Input binary data is processed in 24-bit groups (3 bytes). Each 24-bit group is divided into four 6-bit chunks. Each 6-bit chunk is then used as an index into the 64-character Base64 alphabet. If the input data length is not a multiple of 3 bytes, padding characters (`=`) are added to the end of the output.

Decoding: Each character in the Base64 input string is converted back to its 6-bit value. These 6-bit chunks are reassembled into 8-bit bytes. Padding characters (`=`) indicate the original data length and are ignored during the bit reconstruction.

  • Uses characters A-Z, a-z, 0-9, +, /.
  • Case-sensitive.
  • Encoded output is approximately 33% larger than the original binary data.
  • Uses `=` for padding (one or two `=` characters may appear at the end).
  • Requires correct handling of UTF-8 or other character encodings when converting text to/from binary before Base64 processing.

Use Cases

Base64 is ubiquitous in web and internet standards:

  • Email Attachments: Encoding binary files for transmission via SMTP (as part of MIME).
  • Data URLs: Embedding images or other resources directly into HTML or CSS files (e.g., `data:image/png;base64,...`).
  • HTTP Basic Authentication: Encoding username and password credentials.
  • Storing Binary Data: Representing binary data in text-based formats like XML, JSON, or YAML where raw bytes are not allowed.
  • Certificates: PEM format for SSL/TLS certificates often uses Base64 encoding.

Why is Base64 Important?

It provides a reliable way to handle binary data in text-based environments:

  • Compatibility: Ensures binary data can be safely transmitted through systems designed primarily for text.
  • Simplicity: Relatively simple encoding/decoding process, widely implemented.
  • Standardization: Defined in RFC 4648, ensuring interoperability.

Note: Base64 is an *encoding*, not encryption. It provides no security and can be easily reversed.

How to Use This Tool

  1. Select either "Encode" or "Decode" mode.
  2. Enter the text (UTF-8 for encoding) or Base64 string (for decoding) into the top input field.
  3. The result will appear automatically in the bottom output field. This tool handles multi-byte UTF-8 characters correctly.
  4. Use the swap button () to switch the input and output, automatically changing the mode.
  5. Click the copy icon () next to the output label to copy the result.
  6. Error messages will appear for invalid input (e.g., non-Base64 characters, incorrect padding) or if the decoded data is not valid UTF-8.