Base64 is a way to write any binary data, such as an image, a key or a whole file, as plain text made of 64 characters: A to Z, a to z, 0 to 9, + and /, with = as padding. Every 3 bytes (24 bits) are cut into four 6-bit pieces and each piece becomes one character, so the text is about a third larger than the data and anyone can turn it back.
It exists to carry bytes through places built for text, such as email, JSON, URLs and HTML, and it is neither encryption nor compression. To try it, paste a value into the Base64 Encoder & Decoder, which runs in your browser, so nothing you paste is uploaded.
How to Base64 encode and decode with Zutilium
- Open the Base64 Encoder & Decoder and set Alphabet to Standard Base64, or to Base64URL if the text contains
-or_, as JSON Web Tokens often do. - To decode, paste the Base64 into the Base64 or plain text box and select Decode. Spaces, line breaks and missing
=padding are fine. - Readable UTF-8 text appears in the Result box. Anything else, such as an image or a PDF, is offered as a download: select Download result to save it as decoded.bin.
- To encode, type or paste text, or choose a file under File to encode (optional, up to 1 MiB), which clears the text box. Then select Encode.
- Select Copy result, or Download result to save the Base64 as encoded.txt.
The result is a single unbroken line, and any data: prefix is yours to add. Typed text is encoded from its UTF-8 bytes, the web's standard, so é or an emoji comes back exactly when decoded. The limit is 1 MiB for text, files and decoded results alike.
Decoding stops with an error rather than guessing when a value looks damaged: a + or / in Base64URL mode (or - or _ in standard), an = in the middle, a length no encoder produces, or non-zero leftover bits. The troubleshooting section below explains each message. Paste one part of a JWT at a time, without the dots.
What is Base64 encoding? 3 bytes become 4 characters
Email, JSON, XML and URLs are built for characters, and many of the 256 possible byte values are control codes or invalid as text, so raw bytes get rejected or changed in transit. Base64 uses 6-bit pieces instead, because 6 bits give exactly 64 values, each mapped to a safe character. RFC 4648 sets the alphabet: 0 to 25 are A to Z, 26 to 51 are a to z, 52 to 61 are 0 to 9, 62 is + and 63 is /.
Here is the word Cat, three bytes, encoded by hand:
Text C a t
Byte 0x43 0x61 0x74
Bits 01000011 01100001 01110100
6-bit 010000 110110 000101 110100
Value 16 54 5 52
Base64 Q 2 F 0
So Cat encodes to Q2F0. Decoding reverses the steps: each character gives back 6 bits, and every 8 bits form a byte again. The Binary Translator shows the bytes behind any other word, and the guide to converting binary to text explains how characters become bytes.
Padding: what = and == mean
Input rarely splits evenly into 3-byte groups. With 2 bytes left over, the encoder adds two zero bits, writes three characters and one =. With 1 byte left, it adds four zero bits, writes two characters and ==:
| Input | Bytes | Base64 |
|---|---|---|
| Cat | 3 | Q2F0 |
| Ca | 2 | Q2E= |
| C | 1 | Qw== |
A trailing = tells the decoder the last group held 2 bytes, and == means it held 1. Padded Base64 is always a multiple of 4 characters long, and no valid value is 1 character longer than a multiple of 4, because a single character holds only 6 of the 8 bits a byte needs.
The added bits must be zero. Q2F= differs from Q2E= only in those bits: lenient decoders such as Python's return Ca for both, while strict ones, including Zutilium's and the macOS base64 command, reject it. RFC 4648 allows either behavior.
Text becomes bytes before encoding
Base64 encodes bytes, not letters, so the same word gives different Base64 in different character encodings:
| "café" encoded as | Bytes (hex) | Base64 |
|---|---|---|
| UTF-8 | 63 61 66 C3 A9 | Y2Fmw6k= |
| Latin-1 | 63 61 66 E9 | Y2Fm6Q== |
| UTF-16LE | 63 00 61 00 66 00 E9 00 | YwBhAGYA6QA= |
Zutilium, like most of the web, uses UTF-8. UTF-16LE is what PowerShell's [System.Text.Encoding]::Unicode produces and what pwsh -EncodedCommand expects; for English text its Base64 is full of A characters, as in QwBhAHQA for Cat.
Why Base64 output is about 33% larger
Each character carries 6 bits but takes a whole byte to store, so every 3 bytes need 4 characters: a ratio of 4 to 3, or 33% more. For n bytes, padded Base64 is n ÷ 3 rounded up, times 4, characters long; unpadded Base64 is 4n ÷ 3 rounded up.
| Original size | Padded Base64 | Unpadded |
|---|---|---|
| 1,000 bytes | 1,336 characters | 1,334 |
| 6,144 bytes (6 KiB) | 8,192 characters | 8,192 |
| 1,048,576 bytes (1 MiB) | 1,398,104 characters | 1,398,102 |
Line breaks add more. MIME email wraps Base64 at 76 characters per line, and PEM files, which hold certificates and keys, at 64. With a two-byte line break after every 76 characters, each 57 bytes of an attachment take 78 bytes in the message, about 37% more than the file itself.
Base64URL: the URL-safe alphabet
Three standard characters cause trouble in web addresses: + can mean a space in a query string, / separates path segments and = separates a parameter's name from its value. Base64URL, defined in section 5 of RFC 4648, replaces + with - and / with _, and is usually written without padding, because the decoder can work out the size of the last group from the length.
| Standard Base64 | Base64URL | |
|---|---|---|
| Characters 62 and 63 | + and / |
- and _ |
| Padding | = |
Usually left off |
<<???>> encodes to |
PDw/Pz8+Pg== |
PDw_Pz8-Pg |
| Typical uses | Email, PEM, data URIs, Basic auth | JWTs, URL parameters, file names |
The other 62 characters are shared, so a value without +, /, - or _ decodes the same either way; - or _ means Base64URL, and + or / means standard.
JSON Web Tokens are the Base64URL most people meet: three unpadded parts joined by dots, as RFC 7515 requires. The header {"alg":"HS256","typ":"JWT"} encodes to eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9, and a value that starts with eyJ is almost always JSON, because {" followed by a letter encodes to those three characters.
Paste a whole token into the JWT Expiry Checker to see its header, payload and expiry and, with the key, whether the signature is valid; the guide to checking whether a JWT is expired explains the dates. Decoded JSON is often one long line, which the JSON Formatter & Validator indents.
Base64 decode and encode in a terminal, JavaScript and Python
macOS and Linux terminal
printf '%s' 'Cat' | base64 # Q2F0
echo 'Q2F0' | base64 --decode # Cat
base64 --decode < image.txt > image.png # Base64 text back to a file
Encode with printf or echo -n: plain echo 'Cat' | base64 also encodes the newline at the end and prints Q2F0Cg==. --decode works with both GNU coreutils on Linux and the macOS command. GNU wraps encoded output at 76 characters unless you add -w 0, while macOS writes one line by default (GNU base64 manual).
Windows PowerShell
[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes('Cat')) # Q2F0
[System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('Q2F0')) # Cat
FromBase64String skips spaces and line breaks but needs the padding and the standard alphabet, so pad Base64URL and swap - and _ back to + and / first. Use UTF8 here, because Unicode gives UTF-16LE.
JavaScript
// Browsers and Node.js: btoa() and atob() work on bytes, so convert through UTF-8
const bytes = new TextEncoder().encode("café");
const encoded = btoa(String.fromCharCode(...bytes)); // "Y2Fmw6k="
// Spreading is fine for short text; for files use Buffer or toBase64(), or convert in chunks
const text = new TextDecoder().decode(
Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0))); // "café"
// Node.js
Buffer.from("café").toString("base64"); // "Y2Fmw6k="
Buffer.from("PDw_Pz8-Pg", "base64url").toString(); // "<<???>>"
btoa() throws an InvalidCharacterError for characters above U+00FF, such as € or emoji, and quietly encodes é as Latin-1 (Y2Fm6Q==), which is why the UTF-8 step matters (MDN's btoa reference). Chrome and Edge 140, Firefox 133, Safari 18.2, Node.js 25 and later versions also have Uint8Array.fromBase64() and toBase64(), which accept { alphabet: "base64url" }. Node's Buffer does not throw on malformed Base64; it returns whatever it can decode, so a pasted data: prefix becomes junk bytes without an error.
Python
import base64
base64.b64encode("café".encode("utf-8")) # b'Y2Fmw6k='
base64.b64decode("Y2Fmw6k=").decode("utf-8") # 'café'
part = "eyJ1c2VyIjoiYWRhIiwiYWRtaW4iOmZhbHNlfQ" # a JWT payload, no padding
base64.urlsafe_b64decode(part + "=" * (-len(part) % 4))
# b'{"user":"ada","admin":false}'
Adding the padding avoids binascii.Error: Incorrect padding in Python 3.14 and earlier; from 3.15, urlsafe_b64decode accepts unpadded input. By default b64decode silently drops characters outside the standard alphabet, so - and _ disappear and Base64URL decodes to the wrong bytes. Pass validate=True to get an error instead, as the Python base64 documentation describes.
Base64 in data URIs
A data URI puts a whole file inside a URL, so a page can use it without a separate request. The format is data:[<media-type>][;base64],<data>, as MDN's data URL reference shows:
<img alt="" width="16" height="16" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA4IDgiPjxjaXJjbGUgY3g9IjQiIGN5PSI0IiByPSI0IiBmaWxsPSIjMGE3Ii8+PC9zdmc+">
That 105-byte SVG circle becomes 140 characters, and a 6,144-byte PNG icon becomes 8,192 characters plus the 22-character data:image/png;base64, prefix. The image is part of the HTML or CSS file, so it cannot be cached on its own and is downloaded again with every page that embeds it. Data URIs suit small icons and single-file pages; keep larger images as separate files.
To build one with Zutilium, encode the file and type the data: prefix in front of the result. To decode one, delete everything up to and including the comma after base64, then paste the rest.
Base64 is not encryption
Decoding needs no key, so anyone who sees Base64 can read it. RFC 4648 itself says the encoding hides easily recognized text but "does not provide any computational confidentiality." Three places where it gets mistaken for protection:
- HTTP Basic authentication. The header
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==from RFC 7617 decodes toAladdin:open sesame, a user name and password, so Basic authentication belongs on HTTPS only. The .htpasswd guide covers storing those passwords as bcrypt hashes, and the .htpasswd Generator creates the entries. - Kubernetes Secrets. Values in a Secret's
datafield are just Base64, and the Kubernetes documentation points out that Secrets are stored unencrypted by default. - JWT payloads.
eyJ1c2VyIjoiYWRhIiwiYWRtaW4iOmZhbHNlfQreads{"user":"ada","admin":false}to anyone who decodes it. The signature stops changes but hides nothing, so keep secrets out of tokens.
Nor is Base64 compression: it always makes data bigger. Protect data with real encryption, and store passwords as slow hashes such as bcrypt.
Troubleshooting Base64 decode errors
Unexpected character or padding
Zutilium shows this for a character outside the chosen alphabet, or for = anywhere but the last one or two places. Usually the value uses the other alphabet, so switch Alphabet, or something was copied with it: quotes, a data: prefix, a trailing comma or the dots between JWT parts.
In Base64 from a URL, %2B, %2F and %3D are the percent-encoded +, / and =, and a space is usually a + that form decoding changed. Restore them first, because decoders, this one included, skip spaces.
Invalid Base64 length or padding
The value was cut short, or something was added to its end, such as an extra =, so compare the end with the source. Unlike Zutilium, Python's b64decode and .NET also reject values that only lack padding, with binascii.Error: Incorrect padding and a FormatException; add = until the length is a multiple of 4.
Invalid trailing Base64 bits
The last character carries bits that should be zero, as explained under padding above. That usually means the value was edited or truncated: cutting Q2F0 to Q2F gives this error, so copy it again from the source.
The text comes out garbled
café instead of café means UTF-8 bytes were read as Latin-1, which is what atob() alone does; pass its output through TextDecoder as shown above. Text encoded as UTF-16, or as Latin-1 with accents, does not decode to clean UTF-8, so Zutilium offers it as a download.
The result is a download instead of text
The bytes are not readable text, which is normal for images, PDFs, archives and keys. The first characters of the Base64 identify the file, so you know what to rename decoded.bin to:
| Base64 starts with | File type | Extension |
|---|---|---|
iVBORw0KGgo |
PNG image | .png |
/9j/ |
JPEG image | .jpg |
R0lGOD |
GIF image | .gif |
JVBERi0 |
PDF document | |
UEsDB |
ZIP, DOCX or XLSX | .zip, .docx, .xlsx |
H4sI |
gzip-compressed data | .gz |
UklGR |
WebP, WAV or AVI (RIFF) | .webp, .wav, .avi |
The end is missing after decoding in a terminal
On macOS 26, base64 --decode silently drops a last group that has no padding, so the JWT payload above prints without its closing brace. GNU coreutils older than 9.5 stops with an error instead. Pad the value and convert the Base64URL characters first:
s='eyJ1c2VyIjoiYWRhIiwiYWRtaW4iOmZhbHNlfQ'
while [ $(( ${#s} % 4 )) -ne 0 ]; do s="$s="; done
printf '%s' "$s" | tr '_-' '/+' | base64 --decode # {"user":"ada","admin":false}
Frequently asked questions
What is Base64 used for?
Base64 carries binary data through formats made for text. Common uses are email attachments, data URIs in HTML and CSS, JSON Web Tokens, HTTP Basic authentication headers, PEM certificates and keys, and binary fields in JSON or XML APIs.
Why does Base64 end with = or ==?
The equals signs are padding that brings the length to a multiple of 4. One = means the last group held 2 bytes and == means it held 1. Base64URL usually leaves the padding off, because the length already tells the decoder the same thing.
How much bigger does Base64 make a file?
About 33%, because every 3 bytes become 4 characters: a 300,000-byte image becomes 400,000 characters. Line breaks, as in email, push the overhead to about 37%.
Is Base64 encoding secure?
No. Decoding needs no key or password, so a Base64 value is as readable as plain text to anyone who copies it. Treat encoded credentials, tokens and secrets like the originals, and use HTTPS, encryption or password hashing to protect them.
How can I tell if a string is Base64?
Base64 uses only letters, digits, + and / (or - and _), with = only at the end and, when padded, a length that is a multiple of 4. Passing those checks proves little: the word Cats passes and decodes to three meaningless bytes. The real test is whether decoding gives text or a file that makes sense.