What is Base64?
Base64 is a way to represent arbitrary binary data using only 64 printable ASCII characters — A–Z, a–z, 0–9, + and / — plus = for padding (RFC 4648). It lets you move bytes safely through channels that only handle text, such as:
- Email attachments (MIME)
- Images embedded in HTML or CSS (
data:image/png;base64,...) - HTTP Basic authentication (
Authorization: Basic dXNlcjpwYXNzisuser:pass) - The header and payload of a JWT (URL-safe Base64)
- Binary fields in JSON or XML APIs
How it works
The encoder takes the input three bytes (24 bits) at a time and splits them into four 6-bit groups. Each group (0–63) maps to one character of the alphabet. If the last group has only one or two bytes, the output is padded with == or =. Text is first converted to bytes — UTF-8 by default — so the same text can produce different Base64 under a different charset.
| Input | Base64 | URL-safe |
|---|---|---|
M | TQ== | TQ |
Ma | TWE= | TWE |
Man | TWFu | TWFu |
Hello, World! | SGVsbG8sIFdvcmxkIQ== | SGVsbG8sIFdvcmxkIQ |
hi?> | aGk/Pg== | aGk_Pg |
| café (UTF-8) | Y2Fmw6k= | Y2Fmw6k |
| 😀 (UTF-8) | 8J+YgA== | 8J-YgA |
URL-safe Base64
Standard Base64 uses + and /, which have special meanings in URLs and file names. The URL-safe variant (“base64url”) replaces them with - and _, and the trailing = padding is usually dropped. JWTs and many web APIs use it. This tool's decoder accepts both variants, with or without padding.
Base64 in code
| Language | Encode | Decode |
|---|---|---|
| JavaScript (browser) | btoa(s) — Latin-1 only | atob(b64) |
| Node.js | Buffer.from(s).toString('base64') | Buffer.from(b64, 'base64').toString() |
| Python | base64.b64encode(s.encode()) | base64.b64decode(b64).decode() |
| PHP | base64_encode($s) | base64_decode($b64) |
| Java | Base64.getEncoder().encodeToString(bytes) | Base64.getDecoder().decode(b64) |
| Go | base64.StdEncoding.EncodeToString(b) | base64.StdEncoding.DecodeString(s) |
| Shell | printf '%s' 'Hello' | base64 | echo 'SGVsbG8=' | base64 -d |
In the browser, btoa() throws on characters outside Latin-1 (such as emoji). Convert the string to UTF-8 bytes with TextEncoder first. For URL-safe output, use base64.urlsafe_b64encode in Python, Base64.getUrlEncoder() in Java or base64.RawURLEncoding in Go.
Size overhead: about 33%
Because every 3 bytes become 4 characters, Base64 output is roughly 4/3 the size of the input, plus padding and any line breaks. Embedding large images as data URIs makes HTML and CSS heavier and prevents separate caching, so it is best reserved for small icons.
Frequently asked questions
Is Base64 encryption?
No. Base64 is a reversible encoding that anyone can decode without a key. Never rely on it to protect passwords, tokens or personal data.
Decoding says the result is not valid text
The original data is probably binary (an image, a PDF, a zip file) or text in a different character encoding. Try switching the charset, or click “Save input Base64 as file” to download the raw bytes.
Are my files uploaded?
No. Files are read and converted entirely in your browser with JavaScript and are never sent to a server.
Why are there Shift_JIS and EUC-JP options?
They are legacy Japanese encodings. Older Japanese systems sometimes Base64-encode text in them; if decoded text looks garbled, try another charset. For everything else, keep UTF-8.