Guide

Understanding Base64 Encoding and Decoding

January 18, 2025 8 min read

What is Base64?

Base64 is an encoding scheme that converts binary data into an ASCII string format. It's commonly used to encode binary data (images, files, etc.) for transmission over text-based protocols like HTTP, email, or JSON/XML.

Why Use Base64?

  • Text-safe transmission - Converts binary data to text for protocols that only support text
  • Embedding data - Embed images directly in HTML/CSS/JSON
  • Data URIs - Include files inline without external requests
  • Email attachments - MIME email encoding

How Base64 Works

Base64 uses 64 characters: A-Z, a-z, 0-9, +, /

Encoding Process

  1. Convert input to binary (8-bit bytes)
  2. Group into 6-bit chunks
  3. Map each 6-bit value to Base64 character
  4. Add padding (=) if needed

Example

Text: "Hi"
Binary: 01001000 01101001
6-bit groups: 010010 000110 1001
Base64: S G l =
Result: "SGk="

Common Use Cases

1. Data URIs in HTML

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA..." />

2. JSON with Binary Data

{
  "filename": "photo.jpg",
  "data": "base64encodedstring..."
}

3. API Authentication

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

Important Notes

  • Base64 increases size by ~33%
  • Not encryption - easily reversible
  • Use for encoding, not security

Try It Yourself

Use our free tools: JSON to Base64 | Base64 to JSON | Base64 to Image


Back to Blog