What is Base64?
Base64 is a way to write any bytes (text, an image, a PDF, a compressed file) using only 64 safe characters: A–Z, a–z, 0–9, + and /, with = as padding at the end. Every 3 bytes become 4 characters, so the encoded text is about a third larger than the original. It is an encoding, not encryption: anyone can decode it, and it hides nothing.
You meet Base64 everywhere bytes have to travel through a channel made for text: email attachments, data: URLs that embed an image in HTML or CSS, the Authorization: Basic header, API fields that carry a file, certificates and keys in PEM files, and the three parts of a JWT (which use the Base64URL variant, with - and _ instead of + and /).
This Base64 encoder and decoder works in your browser, so the text and files you paste are never uploaded. When decoding, it does more than turn Base64 back into text: it looks inside the result and opens the layers it recognises. A gzip-compressed payload is unzipped, JSON is pretty-printed, images are previewed, PDFs can be downloaded, and anything else is shown as a hex dump, with a label such as Base64 → gzip → JSON that tells you what was found.
How to encode or decode Base64
- Choose Encode or Decode at the top. Switching carries the result over: what you just encoded becomes the input to decode, and the other way round.
- To encode, type or paste text in Text to encode, or drop a file on the upload area (you can also paste a copied file or a screenshot with Ctrl+V / Cmd+V). With Input is: Hex you can paste raw bytes such as
48 65 6c 6c 6finstead of text. - Pick the Character set for text: UTF-8 (the right choice almost always), UTF-16 LE, UTF-16 BE or Latin-1 (ISO-8859-1). The same letter gives different Base64 in each.
- Tick URL-safe (- and _) for Base64URL, and untick Padding (=) if the receiver expects no
=at the end (JWTs and many URL parameters do). - To decode, paste the Base64 in Base64 to decode. Spaces and line breaks are ignored, both alphabets are accepted, missing padding is fine, and a whole
data:...;base64,URL works too. - Read the Result: the layer label, the type and size, then the decoded text, the image preview or the hex dump. Use Show result as: Hex to see the bytes.
- Press Copy, or Download to save the result as a file (
decoded.json,decoded.png, … orname.base64.txtwhen encoding).
Examples
Text with accents (UTF-8 and Latin-1)
| Input | Character set | Base64 |
|---|---|---|
Hello, world! | UTF-8 | SGVsbG8sIHdvcmxkIQ== |
Olá, mundo! | UTF-8 | T2zDoSwgbXVuZG8h |
Olá, mundo! | Latin-1 | T2zhLCBtdW5kbyE= |
The á takes two bytes in UTF-8 and one in Latin-1, which is why the two results differ. If a decoded text shows á instead of á, it was encoded in one character set and decoded in the other.
Standard Base64 vs Base64URL
With Input is: Hex and the bytes fb ff bf:
Standard: +/+/
URL-safe: -_-_The URL-safe form can go in a URL or a file name without escaping, which is why JWTs use it.
Decoding a JSON payload
Input:
eyJ1c2VyIjoiYW5hIiwiZXhwIjoxNzY3MjI1NjAwfQ==Result, labelled Base64 → JSON (application/json · 31 B):
{
"user": "ana",
"exp": 1767225600
}Base64 that hides a gzip file
Some APIs and message queues send compressed JSON as Base64. This input starts with H4sI, the Base64 of the gzip signature:
H4sIAAAAAAAAE6tWSi1LzStRslLKyU/PzFPSUcrPVrIqKSpNrQUA1zarKxsAAAA=The tool unzips it and shows Base64 → gzip → JSON:
{
"event": "login",
"ok": true
}Common errors and how to fix them
- Character 16 is not valid Base64. Use letters, digits, + / (or - _) and = only.: the input has a character outside the Base64 alphabet, such as
#, a quote or an accented letter. Often the copy included part of the surrounding JSON or a trailing symbol; remove it. - The length is not valid Base64: it looks cut or has an extra character.: the text was truncated or has one character too many. Copy it again from the source, paying attention to the end.
- Character 3 cannot be written in Latin-1 (it is above U+00FF).: you chose Latin-1 and the text has a character it does not have (an emoji,
€, a Cyrillic letter). Choose UTF-8. - The command line gives a different result than the tool:
echo "Hello, world!" | base64encodes a line break too and givesSGVsbG8sIHdvcmxkIQo=. Useprintf '%s'(orecho -n) to getSGVsbG8sIHdvcmxkIQ==. - Decoded text shows strange characters like
é: a character set mismatch. Switch the Character set (usually to UTF-8) and the text appears correctly.
Frequently asked questions
Is Base64 encryption?
No. Base64 only changes the representation of the bytes; anyone can decode it in a second, as this page shows. To protect data, encrypt it; to check integrity, use a hash.
How do I convert an image to Base64?
Choose Encode and drop the image file: the result is the Base64 of its bytes, ready to download or copy. To get a complete data:image/png;base64,... URL and an HTML or CSS snippet, use image to Base64.
How do I decode a Base64 string to a file?
Paste it in Decode mode and press Download. The tool recognises PNG, JPEG, GIF, WebP, PDF, gzip, JSON and text, and names the file with the right extension. There is also a dedicated Base64 decode page.
What is the difference between Base64 and Base64URL?
Base64URL replaces + with - and / with _, and usually drops the = padding, so the result fits in URLs and file names. JWTs are made of three Base64URL parts; to read one, use the JWT decoder.
Why does Base64 end with = or ==?
Base64 works in groups of 3 bytes. When the input length is not a multiple of 3, one or two = fill the last group of 4 characters. They carry no data, which is why many formats leave them out.
How do I create a Basic Auth header?
Encode user:password in UTF-8: admin:s3cret gives YWRtaW46czNjcmV0, so the header is Authorization: Basic YWRtaW46czNjcmV0. The Basic Auth generator builds the whole header for you.
How to encode and decode Base64 in code
JavaScript
In the browser, btoa only accepts characters up to U+00FF, so encode the text to UTF-8 bytes first. In Node.js, Buffer handles both Base64 and Base64URL.
// Browser and Node.js
const bytes = new TextEncoder().encode('Olá, mundo!');
const encoded = btoa(String.fromCharCode(...bytes)); // T2zDoSwgbXVuZG8h
const decoded = new TextDecoder().decode(Uint8Array.from(atob(encoded), c => c.charCodeAt(0)));
// Node.js
Buffer.from('Olá, mundo!').toString('base64'); // T2zDoSwgbXVuZG8h
Buffer.from('T2zDoSwgbXVuZG8h', 'base64').toString('utf8'); // Olá, mundo!
Buffer.from([0xfb, 0xff, 0xbf]).toString('base64url'); // -_-_Python
The base64 module works on bytes, so encode and decode the text explicitly.
import base64
encoded = base64.b64encode("Olá, mundo!".encode("utf-8")).decode("ascii") # T2zDoSwgbXVuZG8h
text = base64.b64decode(encoded).decode("utf-8") # Olá, mundo!
url_safe = base64.urlsafe_b64encode(bytes([0xFB, 0xFF, 0xBF])).decode() # -_-_Go
encoding/base64 has four encodings: StdEncoding, URLEncoding and their Raw versions without padding.
encoded := base64.StdEncoding.EncodeToString([]byte("Olá, mundo!")) // T2zDoSwgbXVuZG8h
decoded, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
fmt.Println("invalid Base64:", err)
}
fmt.Println(string(decoded))
fmt.Println(base64.RawURLEncoding.EncodeToString([]byte{0xFB, 0xFF, 0xBF})) // -_-_Bash
base64 ships with Linux and macOS. Use printf so no line break is encoded, and tr for Base64URL.
printf '%s' 'Olá, mundo!' | base64 # T2zDoSwgbXVuZG8h
echo 'T2zDoSwgbXVuZG8h' | base64 --decode # Olá, mundo!
printf '%s' 'Olá, mundo!' | base64 | tr '+/' '-_' | tr -d '=' # Base64URL
base64 < photo.png > photo.txt # a file