Base64 Encoding Explained: What, Why, and How

7 min readEncoding & Security

Introduction

Base64 is one of the most fundamental encoding schemes in computing. It's everywhere - from email attachments to API credentials, from embedded images to cryptographic operations. Understanding Base64 is essential for anyone working with data transmission, web development, or system integration. This guide explains what Base64 is, why it exists, and how to use it effectively.

What is Base64?

Base64 is a binary-to-text encoding scheme that converts binary data into ASCII characters. It uses 64 characters (plus padding) to represent any binary data as text:

The 64 Characters

A-Z(26 chars)
a-z(26 chars)
0-9(10 chars)
+ /(2 chars)

Plus padding character = for alignment

Every 3 bytes of input data become 4 Base64 characters. This 33% size increase is the tradeoff for converting binary data into safe, printable text.

How Base64 Works

The encoding process is straightforward:

  • Input data is grouped into 3-byte chunks (24 bits)
  • Each 24-bit chunk is divided into 4 groups of 6 bits
  • Each 6-bit group maps to one Base64 character (0-63)
  • If input isn't divisible by 3, padding (=) is added

Example

Input:  "Hello"
Output: "SGVsbG8="

Breakdown:
"H" → S
"e" → G
"l" → V
"l" → s
"o" → b
8= (padding)

Why Do We Use Base64?

Base64 exists because many systems were designed to handle only text characters:

  • Email Systems: SMTP was designed for text. Attachments (images, PDFs) need Base64 to transmit safely.
  • URLs and Query Strings: Some characters have special meaning in URLs. Base64 avoids these conflicts.
  • JSON and XML: These formats are text-based. Binary data (images, files) must be Base64 encoded to embed.
  • API Credentials: HTTP Basic Auth uses Base64 to encode username:password (not for security, just for encoding).

Security Warning

Base64 is NOT encryption! Base64 is encoding - anyone can decode it. Never use Base64 to "protect" passwords, secrets, or sensitive data. It's like writing a secret message in a different font - anyone who knows the font can read it.

For security, use proper encryption (AES, RSA) or secure hashing (bcrypt, Argon2) for passwords.

Common Use Cases

Embedding Images in HTML/CSS

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

Email Attachments (MIME)

Content-Transfer-Encoding: base64

JWT Tokens

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9

HTTP Basic Auth

Authorization: Basic dXNlcjpwYXNz

Related Tools

Conclusion

Base64 is a fundamental encoding scheme that enables binary data to travel through text-only systems. It's essential for web development, email, APIs, and many other applications. Remember that Base64 is for encoding, not security - use proper encryption for sensitive data. Our free Base64 tools make encoding and decoding instant and private, all running in your browser.