What Is Base64?
Base64 turns binary data into plain text made of 64 characters: the letters A–Z and a–z, the
digits 0–9, and two symbols, usually + and /. Every 3 bytes become 4
characters, and an = sign pads the end when the length does not divide evenly. The format
is defined in RFC 4648. It exists so that data such as images, files and keys can travel through systems
that only handle text: email, JSON, HTML, CSS and URLs.
How to Decode a Base64 Image
Switch to the Image tab, paste the string and press Decode to image. You can paste the
full data URI (data:image/png;base64,...) or only the part after the comma. The decoder
reads the first bytes of the result to find the real format, so it still works when the prefix is
missing or wrong. You then see a preview, the pixel dimensions and the file size, and you can download
the picture as a normal file.
To go the other way, choose an image in the Image to Base64 box. You can copy the
plain Base64, a ready-to-use data URI, or a complete <img> tag.
Base64 Is Not Encryption
Base64 only changes how data is written. It does not need a key, and anyone can reverse it. A password stored as Base64 is as exposed as one stored in plain text. If you need a secret value, create a random one with the Strong Password Generator or, for API keys and tokens, the Developer Credential Generator, which can output Base64URL.
Standard vs URL-Safe Base64
| Standard | URL-safe (Base64URL) | |
|---|---|---|
| Characters 62 and 63 | + and / | - and _ |
| Padding | Usually = | Often left out |
| Used in | Email, data URIs, most APIs | JWTs, URLs, file names |
The decoder accepts both forms automatically and does not need the padding. Tick the URL-safe box when you encode if the result is going into a URL or a token.
Base64 in Your Own Code
// JavaScript in the browser (UTF-8 safe)
const bytes = new TextEncoder().encode("héllo");
const b64 = btoa(String.fromCharCode(...bytes));
const text = new TextDecoder().decode(Uint8Array.from(atob(b64), c => c.charCodeAt(0)));
// Node.js
Buffer.from("hello").toString("base64") // aGVsbG8=
Buffer.from("aGVsbG8=", "base64").toString() // hello
# Python
import base64
base64.b64encode(b"hello").decode() # aGVsbG8=
base64.b64decode("aGVsbG8=") # b'hello'
# Linux / macOS terminal
echo -n hello | base64
echo aGVsbG8= | base64 --decode
# PowerShell
[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("hello"))
[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("aGVsbG8="))
The plain btoa() function in browsers only accepts Latin-1 characters and throws an error
on emoji or most non-English text, so convert the text to UTF-8 bytes first, as in the first example.
When Not to Use a Base64 Image
Inlining an image as a data URI saves one request, but it makes the data about 33 percent bigger, the browser cannot cache it separately, and it bloats your HTML or CSS. It suits small icons and tiny placeholders. For photos, use a normal image file.