Technology

Base64 Encoding Explained: What It Is and How It Works

6 min read  ·  Updated 2025

You have likely encountered Base64 strings — long strings of letters, numbers, and characters ending in ==. This guide explains what Base64 is, why it exists, how the algorithm works, and when to use it in real projects.

Why Does Base64 Exist?

Many systems (email protocols, URLs, JSON, XML) were designed to handle text, not arbitrary binary data. Binary data — like images, audio, or encrypted bytes — contains bytes that are either not printable ASCII characters or have special meaning in transport protocols (like newlines, null bytes, or control characters).

Base64 solves this: it converts any binary data into a safe string of 64 printable characters (A–Z, a–z, 0–9, +, /) that can travel safely through any text-based system.

How Base64 Encoding Works

Base64 works by processing input 3 bytes (24 bits) at a time:

  1. Take 3 bytes of binary data
  2. Split the 24 bits into four 6-bit groups
  3. Map each 6-bit group (0–63) to a Base64 character using the Base64 alphabet
  4. Output 4 characters for every 3 bytes of input

Worked Example: Encoding "Man"

TextMan
ASCII (decimal)7797110
Binary010011010110000101101110
Combined: 010011 010110 000101 101110
Base64 index1922546
Base64 characterTWFu

Result: TWFu — exactly 4 characters for 3 input bytes.

The = Padding

If the input is not a multiple of 3 bytes, Base64 pads the output with = signs:

  • 1 remaining byte → 2 Base64 chars + ==
  • 2 remaining bytes → 3 Base64 chars + =
  • 3 remaining bytes → 4 Base64 chars (no padding)

Size Overhead

Base64-encoded data is approximately 33% larger than the original binary (4 characters for every 3 bytes). This trade-off is acceptable when the alternative is data corruption during transport.

Common Use Cases

  • Inline images in CSS/HTML: background: url("data:image/png;base64,iVBOR...")
  • JSON Web Tokens (JWT): The header and payload are Base64Url encoded
  • Email attachments: MIME uses Base64 to embed binary attachments
  • API keys and credentials: HTTP Basic Auth encodes user:password as Base64
  • Data URIs: Embedding fonts or small images directly in HTML/CSS

Base64 Is NOT Encryption

Anyone can decode a Base64 string with no key required. Never use Base64 to "hide" sensitive data. Use it only for safe binary-to-text transport.

Encode and decode Base64 instantly with BrainBoost's Base64 Encoder/Decoder. Also try the Binary/Hex Converter and HTML Entity Encoder.

Frequently Asked Questions

Base64 is a binary-to-text encoding scheme that converts binary data into a string of 64 printable ASCII characters. Used to safely transmit binary data over systems designed to handle text.

No. Base64 is encoding, not encryption. It is fully reversible with no key required. It provides zero security.

Base64 works in groups of 3 bytes. If the input length isn't a multiple of 3, padding (= signs) is added to make the output length a multiple of 4.