What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format by translating it into a radix-64 representation. It's commonly used when there's a need to encode binary data that needs to be stored and transferred over media designed to deal with textual data.

Key Insight: Base64 encoding converts binary data into a text format using 64 different ASCII characters (A-Z, a-z, 0-9, +, /, and = for padding). This ensures that the data remains intact without modification during transport.

Interactive Base64 Encoder/Decoder Tool

Try our tool below to instantly encode text to Base64 or decode Base64 back to its original form:

How Base64 Encoding Works

The Base64 algorithm works by taking groups of 3 bytes (24 bits) of binary data and splitting them into 4 groups of 6 bits each. Each 6-bit group is then mapped to a specific character in the Base64 alphabet.

// Example: Encoding "Man" to Base64
// Text: M (77) a (97) n (110)
// Binary: 01001101 01100001 01101110
// 6-bit groups: 010011 010110 000101 101110
// Decimal: 19 22 5 46
// Base64 chars: T W F u
// Result: "TWFu"

Common Use Cases for Base64

Image Embedding

Embed images directly in HTML or CSS files using data URIs, reducing HTTP requests.

File Attachments

Email systems use Base64 to encode binary attachments as text for transmission.

Security & Tokens

JWT (JSON Web Tokens) and other security tokens often use Base64 encoding.

Data Storage

Store binary data in databases or configuration files that only accept text.

Base64 Character Set

The Base64 alphabet consists of 64 characters:

  • A-Z (26 uppercase letters)
  • a-z (26 lowercase letters)
  • 0-9 (10 digits)
  • + (plus sign)
  • / (forward slash)
  • = (equals sign for padding)

Note about padding: The '=' character is used for padding at the end of the encoded string to ensure its length is a multiple of 4. This is necessary because Base64 encodes 3 bytes into 4 characters.

Examples of Base64 Encoding

Original: "Hello, World!"
Base64: "SGVsbG8sIFdvcmxkIQ=="
Original: "Base64 encoding"
Base64: "QmFzZTY0IGVuY29kaW5n"
Original: "12345"
Base64: "MTIzNDU="
Original: "A"
Base64: "QQ=="

Limitations and Considerations

While Base64 is incredibly useful, it's important to understand its limitations:

  1. Increased Size: Base64 encoded data is approximately 33% larger than the original binary data.
  2. Not Encryption: Base64 is an encoding scheme, not encryption. It provides no security or confidentiality.
  3. Character Sets: Some Base64 variants use different characters for the last two values (like -_ instead of +/ for URL safety).
  4. Line Length: Some implementations limit line length to 76 characters with CRLF line breaks.