How to use the Base64 encoder and decoder
- Choose Mode: Encode turns text into Base64, Decode turns Base64 back into text.
- Paste or type into the left pane. The result updates as you type.
- Pick an Alphabet when encoding: Standard (
+,/,=padding) or URL-safe (-,_, no padding). - Turn on Wrap at 76 chars if the output goes into an email body or another format that uses the MIME line length.
- Copy or Download the result.
UTF-8 done right
Base64 encodes bytes, not characters, so text has to be converted to bytes first. This tool always uses UTF-8, which is what nearly every API, database and programming language expects:
| Input | Mode | Output |
|---|---|---|
Hi?> |
Encode, Standard | SGk/Pg== |
Hi?> |
Encode, URL-safe | SGk_Pg |
aGVsbG8 |
Decode | hello (missing padding is fine) |
//79/A== |
Decode | hex dump: ff fe fd fc (not valid UTF-8) |
The sample text, Xin chào 👋 — …, is 72 bytes in UTF-8 and encodes to 96 Base64 characters. The status bar shows both numbers.
What the decoder accepts
- Both alphabets.
-and_are read as+and/, so Base64URL from JWTs and URLs decodes without changes. - Missing padding.
=characters are optional. When present, they may only appear at the end. - Whitespace and line breaks. These are ignored, so wrapped MIME bodies decode as-is. For PEM files, paste only the lines between
-----BEGINand-----END. - Data URIs. A
data:…;base64,prefix is stripped automatically.
Invalid input is reported precisely, for example Invalid Base64 character '$' at position 4. or Invalid length: Base64 input is truncated or has an extra character.
When to use Base64
Base64 exists to move binary data through channels that only accept text: email attachments, JSON and XML payloads, HTTP headers like Authorization: Basic, data URIs in CSS or HTML, and environment variables. It is not compression and not encryption. For large files, sending raw bytes (for example multipart/form-data) is usually better than inflating them by a third.
URL-safe Base64 is not the same as percent-encoding. To put ordinary text such as a search term into a query string, use URL Encode / Decode; use Base64URL when the data is binary or must survive as one opaque token.
Base64 in code
// Browser / Node.js 18+: UTF-8 safe
const b64 = btoa(String.fromCharCode(...new TextEncoder().encode(text)));
const back = new TextDecoder().decode(Uint8Array.from(atob(b64), (c) => c.charCodeAt(0)));
// Node.js
Buffer.from(text, 'utf8').toString('base64'); // or 'base64url'
Buffer.from(b64, 'base64').toString('utf8');
import base64
base64.b64encode(text.encode("utf-8")).decode("ascii")
base64.urlsafe_b64encode(data).rstrip(b"=")
base64.b64decode(b64).decode("utf-8")
printf '%s' 'hello' | base64 # aGVsbG8=
echo 'aGVsbG8=' | base64 --decode
Base64 is an encoding, not encryption: anyone can decode it. To inspect tokens built from Base64URL segments, use the JWT Decoder. To check integrity, compute a digest with the Hash Generator.
Frequently asked questions
Is my text uploaded when I encode or decode it?
No. Encoding and decoding run in your browser tab and nothing is uploaded, so it is safe to use with API keys, tokens and configuration snippets.
Why does btoa() fail on my text but this tool works?
The browser's btoa() only accepts characters in the Latin-1 range, so emoji, Vietnamese, Chinese or even curly quotes throw an error. This tool first converts your text to UTF-8 bytes and then encodes those bytes, which is what servers and other languages expect.
What is the difference between standard and URL-safe Base64?
Standard Base64 (RFC 4648) uses + and / and pads with =. The URL-safe alphabet, also called Base64URL, uses - and _ instead and drops the padding, so the result can go into URLs, file names and JWTs without escaping. The decoder accepts both alphabets automatically.
Why is the Base64 output longer than my input?
Base64 represents every 3 bytes as 4 characters, so encoded data is about 33% larger than the original bytes. Non-ASCII characters take 2 to 4 bytes in UTF-8, which is why the status bar shows the byte count as well as the character count.
What happens if the decoded data is not text?
If the bytes are not valid UTF-8, for example an image or a compressed file, the tool shows a hex dump with offsets and printable ASCII instead of garbled characters, and a warning explains why.
Last updated