DeveloperMay 30, 2026·4 min read

Base64 Encoding Explained: What It Is and When to Use It

Base64 shows up everywhere — email attachments, API authentication headers, embedded images in HTML, and JWT tokens. Yet many developers use it without fully understanding what it does or why. This guide demystifies Base64, explains exactly how it works, and shows you when and when not to use it.

Try the free Base64 Encoder / Decoder

Encode any text or decode any Base64 string instantly — no signup.

Open tool →

What is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data using only 64 printable ASCII characters: the uppercase letters A–Z, lowercase letters a–z, digits 0–9, and the symbols + and /. An equals sign = is used as padding.

The name comes directly from the number of characters used: base 64. It was designed to safely transmit binary data — like images or files — through systems that were originally built to handle only text, such as email protocols (SMTP) and HTTP headers.

How Base64 Encoding Works

Base64 works by taking every 3 bytes (24 bits) of binary input and splitting them into four 6-bit groups. Each 6-bit group maps to one of the 64 characters in the Base64 alphabet. This is why Base64-encoded output is always roughly 33% larger than the original input — 3 bytes become 4 characters.

Let's walk through a simple example. Encoding the word Man:

StepValue
Input charactersM · a · n
ASCII values77 · 97 · 110
Binary (24 bits)01001101 01100001 01101110
Split into 6-bit groups010011 · 010110 · 000101 · 101110
Decimal values19 · 22 · 5 · 46
Base64 outputT · W · F · u → TWFu

If the input is not a multiple of 3 bytes, padding characters (= or ==) are added to make the output length a multiple of 4.

A Quick Example

Plain text input

Hello, ToolingDock!

Base64 encoded output

SGVsbG8sIFRvb2xpbmdEb2NrIQ==

Where is Base64 Used in the Real World?

1. Email attachments (MIME)

Email was originally designed to carry only 7-bit ASCII text. Attachments like PDFs and images are binary files. MIME (Multipurpose Internet Mail Extensions) uses Base64 to encode these binary files as text so they can travel safely over email protocols without corruption.

2. Basic Authentication in HTTP

When an API uses HTTP Basic Auth, the credentials are sent as username:password encoded in Base64 inside the Authorization header:

Authorization: Basic dXNlcjpwYXNzd29yZA==

Note: Base64 is not encryption. Anyone who intercepts this header can decode it instantly. Basic Auth should only ever be used over HTTPS.

3. Embedding images in HTML and CSS

Small images can be embedded directly into HTML or CSS as Base64 data URIs, eliminating an extra HTTP request:

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

4. JWTs

Each of the three parts of a JSON Web Token (header, payload, and signature) is Base64URL-encoded — a URL-safe variant that replaces + with - and / with _ so the token is safe to use in URLs and headers.

5. Storing binary data in JSON or databases

JSON only supports text. If you need to include binary data — like a file or a cryptographic key — inside a JSON payload, Base64 encoding is the standard approach.

Base64 is Encoding, Not Encryption

This is the most important thing to understand about Base64. It is completely reversible with no key or secret. Anyone who sees a Base64 string can decode it in seconds. Base64 does not protect your data — it only makes it safe to transmit over text-based systems.

If you need to protect sensitive data, use proper encryption (AES, RSA) — not Base64.

Base64 vs Base64URL

VariantCharactersUse case
Standard Base64A–Z, a–z, 0–9, +, /Email, file encoding, general use
Base64URLA–Z, a–z, 0–9, -, _JWTs, URL parameters, filenames

How to Encode or Decode Base64 Instantly

No installation or code needed. With the free Base64 Encoder / Decoder:

  1. Paste any plain text to encode it to Base64
  2. Or paste any Base64 string to decode it back to plain text
  3. The result updates instantly as you type
  4. Copy the output with one click

Encode or decode Base64 now

Free, instant, no signup needed.

Open Base64 Tool →