Input
Output
The result appears here as you type.
Working…
Image preview
Shown from the decoded data on your device. Nothing was loaded from the internet.
Ctrl+Enter run / or Ctrl+K search tools Press Ctrl+D to bookmark this page
How to encode or decode Base64
- Choose Encode or Decode. The result updates as you type.
- To encode, type or paste text, or press Encode a file (or drop one onto the input). Pick the alphabet, padding and line breaks the receiving system expects.
- To decode, paste the Base64. Line breaks, spaces, quotes and a
data:prefix are removed for you and listed under the result. Text appears as text; anything else appears as hex, with a preview for images. - Copy the result or download it. Decoded files get a name that matches their real type, such as
decoded.png, ordecoded.binwhen the type is unknown.
What Base64 is, and what it is not
Base64 writes any bytes using only 64 characters that survive almost anywhere: A–Z, a–z, 0–9, + and /. Every 3 bytes become 4 characters. That lets you put an image inside JSON, a file inside an email, or binary data inside an HTTP header, where raw bytes would break.
Base64 is not encryption. There is no key: anyone can decode it in a second. An Authorization: Basic header, a Kubernetes secret or a "hidden" value in a config file is as readable as plain text. When the tool decodes something shaped like user:password, it reminds you of this.
Examples
| Text | Base64 | Note |
|---|---|---|
Hi | SGk= | Two bytes: one = of padding |
Hi! | SGkh | Three bytes: no padding needed |
Café | Q2Fmw6k= | é is two UTF-8 bytes |
தமிழ் | 4K6k4K6u4K6/4K604K+N | Tamil: three UTF-8 bytes per character |
👋 | 8J+Riw== | An emoji is four UTF-8 bytes |
~~ok?? | fn5vaz8/ | Standard alphabet uses / |
~~ok?? | fn5vaz8_ | URL-safe alphabet uses _ instead |
Standard, URL-safe and padding
The + and / of standard Base64 mean something in URLs and file names, so URL-safe Base64 (Base64URL, RFC 4648) swaps them for - and _. JSON Web Tokens and many APIs use it.
Padding is the = at the end. It fills the last group of 4 when the data is not a multiple of 3 bytes. It carries no data, so URL-safe Base64 usually drops it. This decoder accepts both alphabets and missing padding, and tells you what it found, for example "URL-safe, no padding". If an input mixes both alphabets, or has extra bits in its last character, it still decodes it and points that out, because both usually mean the data was edited or joined from two sources.
Why decoded text comes out garbled
Base64 holds bytes, not letters. Text has to be turned into bytes first, and the usual way today is UTF-8, where é is 2 bytes and a Tamil or Hindi letter is 3. A tool that skips this step, such as the browser's bare btoa(), fails on anything outside Latin-1, and decoding with the wrong character set turns Café into Café.
This tool encodes text as UTF-8 and decodes it strictly. If the bytes are not valid UTF-8, it does not show garbage: it switches to hex and, when the bytes read correctly as Windows-1252 (the older "Latin-1"), offers that. You can also choose another character set, such as Shift_JIS, GBK, Big5, EUC-KR or UTF-16.
Line breaks, MIME and PEM
Some formats split Base64 into lines. Email attachments (MIME, RFC 2045) use 76 characters per line with CRLF endings. PEM files, such as certificates and keys, use 64. JSON, URLs, HTTP headers and most APIs expect one unbroken line, which is the default here. When decoding, line breaks are always removed and counted, so a PEM body or a wrapped email part pastes straight in.
Data URLs
A data URL puts a whole file in one string: data:image/png;base64,iVBORw0…. Turn on Output as data URL when encoding a file, and the type is taken from the file's own first bytes rather than its name. Paste a data URL to decode it: the prefix is removed and its declared type is checked against the real one, so a "PNG" that is really a JPEG is pointed out.
Size and large files
Base64 is about 33% larger than the original, plus line breaks if you add them: a 3 MB image becomes 4 MB of text. Files up to 50 MB are processed in a background thread in your browser, so the page stays responsive, with progress and a Cancel button. Very long results are shown in part; Copy and Download always use the full result.
On the command line
- Linux:
base64 file.pngto encode (76-character lines; add-w 0for one line),base64 -d file.txtto decode. - macOS:
base64 -i file.pngandbase64 -D -i file.txt. - Windows PowerShell:
[Convert]::ToBase64String([IO.File]::ReadAllBytes("file.png")), and[Convert]::FromBase64String($text)to decode.
Your data stays in your browser
Everything runs on your device. Text and files are never uploaded, and this tool saves nothing, not even your last input, because Base64 so often contains passwords, keys and tokens. Your input is never put in the page address or in shared links. You can confirm this in your browser's Network tab.
Frequently asked questions
Is Base64 encryption?
No. Base64 only changes how bytes are written, and anyone can decode it without a key. A Basic-auth header or a Kubernetes secret in Base64 is as readable as plain text. Use real encryption to protect data.
Is my input uploaded or saved?
No. Encoding and decoding run in your browser, files are read on your device, and this tool never saves your input or puts it in a link, because Base64 so often holds passwords, keys and tokens.
Why does my decoded text look garbled?
The bytes were probably written in another character set than UTF-8, or the data is not text at all. The tool switches to a hex view when the bytes are not text, and suggests Windows-1252 when that would read correctly. You can pick the character set yourself.
What is the difference between standard and URL-safe Base64?
Standard Base64 uses + and /, which have special meanings in URLs. URL-safe Base64 (Base64URL) uses - and _ instead and usually leaves out the = padding. JWTs use it. The decoder accepts both and tells you which it found.
Why is Base64 about a third larger?
Every 3 bytes become 4 characters, so the output is about 33% bigger, plus line breaks if you add them. That is the price of using only 64 safe characters.
How large can a file be?
Up to 50 MB. Large files are processed in a background thread in your browser, so the page stays responsive, and you can cancel at any time. Very large results are shown in part, and Copy and Download use the full result.
Base64 encode and decode in your code
Encoding UTF-8 text, URL-safe Base64 without padding, decoding with line breaks, and rejecting invalid input in Java, JavaScript, Python and Go, using each standard library.
Java
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class Base64Demo {
public static void main(String[] args) {
PrintStream out = new PrintStream(System.out, true, StandardCharsets.UTF_8);
String text = "Hello, தமிழ் 👋!";
byte[] data = text.getBytes(StandardCharsets.UTF_8);
out.println(Base64.getEncoder().encodeToString(data));
// URL-safe: - and _ instead of + and /, here without = padding.
String urlSafe = Base64.getUrlEncoder().withoutPadding().encodeToString(data);
out.println(urlSafe);
// Java's decoders accept missing padding.
out.println(new String(Base64.getUrlDecoder().decode(urlSafe), StandardCharsets.UTF_8));
// The MIME decoder skips line breaks (and, careful, any other character
// outside the alphabet). getMimeEncoder() writes 76-character lines with CRLF.
out.println(new String(Base64.getMimeDecoder().decode("SGVsbG8s\nIHdvcmxk"), StandardCharsets.UTF_8));
// The basic decoder rejects anything outside the alphabet.
try {
Base64.getDecoder().decode("SGVs!G8=");
} catch (IllegalArgumentException e) {
out.println("error: not valid Base64");
}
}
} Standard library only (java.util.Base64, Java 8 or later; the PrintStream charset overload needs Java 10).
JavaScript
// Base64 in JavaScript (browsers and Node.js), standard library only.
const text = 'Hello, தமிழ் 👋!';
// btoa() only accepts Latin-1 characters, so turn the text into UTF-8 bytes first.
const bytes = new TextEncoder().encode(text);
let binary = '';
for (const b of bytes) binary += String.fromCharCode(b);
const b64 = btoa(binary);
console.log(b64);
// URL-safe: - and _ instead of + and /, usually without = padding.
const urlSafe = b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
console.log(urlSafe);
// Decode: map back to the standard alphabet; atob() accepts missing padding.
const fromBase64 = (s) => new TextDecoder().decode(Uint8Array.from(atob(s), (c) => c.charCodeAt(0)));
console.log(fromBase64(urlSafe.replace(/-/g, '+').replace(/_/g, '/')));
// atob() skips spaces and line breaks, so MIME and PEM bodies decode as they are.
console.log(fromBase64('SGVsbG8s\nIHdvcmxk'));
// Anything outside the alphabet throws.
try {
atob('SGVs!G8=');
} catch {
console.log('error: not valid Base64');
}
// Newer browsers also have Uint8Array.prototype.toBase64() and Uint8Array.fromBase64(),
// with { alphabet: 'base64url', omitPadding: true } options. Check support first. Python
# Base64 in Python, standard library only.
import base64
import binascii
text = "Hello, தமிழ் 👋!"
data = text.encode("utf-8")
print(base64.b64encode(data).decode("ascii"))
# URL-safe: - and _ instead of + and /. Strip the = padding if you do not want it.
url_safe = base64.urlsafe_b64encode(data).decode("ascii").rstrip("=")
print(url_safe)
# urlsafe_b64decode needs the padding back.
padded = url_safe + "=" * (-len(url_safe) % 4)
print(base64.urlsafe_b64decode(padded).decode("utf-8"))
# Without validate=True, b64decode drops every character outside the alphabet,
# including line breaks (fine for MIME and PEM) but also real mistakes.
print(base64.b64decode("SGVsbG8s\nIHdvcmxk").decode("utf-8"))
# validate=True rejects anything outside the alphabet instead.
try:
base64.b64decode("SGVs!G8=", validate=True)
except binascii.Error:
print("error: not valid Base64") Go
// Base64 in Go, standard library only.
package main
import (
"encoding/base64"
"fmt"
)
func main() {
text := "Hello, தமிழ் 👋!"
data := []byte(text) // Go strings are already UTF-8
fmt.Println(base64.StdEncoding.EncodeToString(data))
// RawURLEncoding: - and _ instead of + and /, no = padding.
urlSafe := base64.RawURLEncoding.EncodeToString(data)
fmt.Println(urlSafe)
decoded, err := base64.RawURLEncoding.DecodeString(urlSafe)
if err != nil {
panic(err)
}
fmt.Println(string(decoded))
// The decoders skip \r and \n, so MIME and PEM bodies decode as they are.
mime, err := base64.StdEncoding.DecodeString("SGVsbG8s\nIHdvcmxk")
if err != nil {
panic(err)
}
fmt.Println(string(mime))
// Anything else outside the alphabet is an error (a CorruptInputError with its offset).
if _, err := base64.StdEncoding.DecodeString("SGVs!G8="); err != nil {
fmt.Println("error: not valid Base64")
}
} Last verified . Each example is run automatically and its output checked.