What is Base64 encoding?

Base64 is a binary-to-text encoding scheme that represents binary data in ASCII string format.

How Base64 Works:

Base64 encodes binary data using 64 different ASCII characters:

  • Letters A-Z (uppercase)
  • Letters a-z (lowercase)
  • Digits 0-9
  • Special characters + and /
  • Padding character =

Why Use Base64?

  • Data transmission: Safely transmit binary data over text-only protocols (email, JSON, XML)
  • Embedding: Include images or files directly in HTML, CSS, or JSON
  • API authentication: Encode credentials in HTTP Basic Authentication
  • URL safety: Make binary data URL-safe (with Base64URL variant)
  • Data storage: Store binary data in text-based databases or configuration files

Example:

Text: Hello World Base64: SGVsbG8gV29ybGQ=

Important Notes:

  • Base64 is NOT encryption - it's encoding for transport
  • Encoded data is about 33% larger than the original
  • Anyone can decode Base64 - never use it to hide secrets
  • Use Base64URL variant for URLs (replaces + with -, / with , removes padding)

Common Use Cases:

  • Encoding images as data URIs in CSS/HTML
  • Transmitting binary files in JSON APIs
  • Basic Authentication headers in HTTP requests
  • Storing binary data in text-based formats
  • Email attachments (MIME encoding)

Related Questions