In this article
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.
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
| Use | Example |
|---|---|
| Email attachments | Every attachment is Base64 inside the message |
| Data URIs in HTML and CSS | data:image/png;base64,iVBORw0… |
| HTTP Basic authentication | Authorization: Basic dXNlcjpwYXNz |
| JSON Web Tokens | Header 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
- Open the Base64 Encoder.
- Type text, or switch to file mode and drop in any file.
- Choose standard or URL-safe output, and for files whether to add a
data:URI prefix. - 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.