Developer Tools

What Is Base64 – and When Should You Use It?

Base64 shows up in emails, web pages, API keys and data URIs. It is simple once you see what problem it solves – and what it does not do.

In this article
  1. The problem Base64 solves
  2. How it works in one paragraph
  3. Where you will meet it
  4. Base64 is not encryption
  5. How to encode
  6. URL-safe Base64
  7. Data URIs: when inlining images makes sense
  8. Decoding

The problem Base64 solves

Many systems were designed to carry text, not raw binary data. Email, JSON, HTML attributes, URLs and some databases can be confused by arbitrary bytes – control characters, null bytes or line endings. Base64 converts any data into a string made only of 64 safe characters: A–Z, a–z, 0–9, “+” and “/” (with “=” for padding). Anything – an image, a PDF, a key – can then travel safely through text-only channels.

Base64 EncoderEncode text or any file to Base64, with UTF-8 support, URL-safe output and data URIs for images. Encoding happens in your browser – nothing uploads.
Open the free tool

How it works in one paragraph

Base64 takes the data three bytes (24 bits) at a time and splits them into four groups of 6 bits. Each 6-bit group (a number from 0 to 63) is written as one of the 64 characters. That is why the output is always about 4/3 of the original size: every 3 bytes become 4 characters – roughly 33% bigger.

Where you will meet it

UseExample
Email attachmentsEvery attachment is Base64 inside the message
Data URIs in HTML and CSSdata:image/png;base64,iVBORw0…
HTTP Basic authenticationAuthorization: Basic dXNlcjpwYXNz
JSON Web TokensHeader and payload use URL-safe Base64
APIs that accept files in JSON{"file": "JVBERi0xLjcK…"}

Base64 is not encryption

This is the most important point. Base64 hides nothing: anyone can decode it instantly. “dXNlcjpwYXNz” is simply “user:pass”. Never treat Base64 as a way to protect passwords or secrets. Use HTTPS to protect data in transit and proper encryption or hashing for storage.

How to encode

  1. Open the Base64 Encoder.
  2. Type text, or switch to file mode and drop in any file.
  3. Choose standard or URL-safe output, and for files whether to add a data: URI prefix.
  4. Copy the result; the tool shows its length and size.

Text is encoded as UTF-8 first, so accents, Urdu and emoji work correctly – a common source of bugs in simpler tools.

URL-safe Base64

Standard Base64 uses “+” and “/”, which have special meanings in web addresses, and “=” padding. The URL-safe variant uses “-” and “_” instead and usually drops the padding. Use it for tokens and IDs in URLs and file names.

Data URIs: when inlining images makes sense

Embedding a tiny icon as a data URI saves a separate request. But because Base64 is 33% bigger and cannot be cached separately, inlining large images slows pages down. A good rule: inline only images smaller than a few kilobytes, such as small icons; keep photos as normal files.

Decoding

To turn Base64 back into text or a file – and see what type of file it is – use the Base64 Decoder. For the different job of making text safe inside URLs, see the URL Encoder.

Base64 EncoderEncode text or any file to Base64, with UTF-8 support, URL-safe output and data URIs for images. Encoding happens in your browser – nothing uploads.
Open the free tool
Keep reading

Related articles

All articles
Dev

How to Decode Base64 into Text, an Image or a File

A long string of random-looking letters in a log, an email or an API response is often Base64. Here is how to see what is really inside.

3 min read
Dev

URL Encoding Explained – Why Spaces Become %20

Paste a link with spaces, “&” or Urdu text and it can break. URL encoding fixes this by turning special characters into safe % codes.

3 min read
Web

HTML Entities Explained – How to Show Code and Symbols Safely

Type “<b>” into a web page and it turns text bold instead of showing up. HTML entities are how you display special characters exactly as written.

3 min read