RFC 4648 · Encoder & decoder
Base64 encode anything, without uploading anything.
A free online Base64 encoder and decoder for text, files and images — encoded by JavaScript in your own browser tab. Nothing is uploaded, so it works offline and has no size limit.
- Encodes as you type
- Text, files & images
- URL-safe & MIME modes
- No ads, no sign-up
Drop a file or image here
or . Nothing is uploaded — the file never leaves your computer.
Options
Ready to paste
Ctrl+Enter encode Ctrl+Shift+C copy result Ctrl+Shift+X swap direction
Base64 encode online — free, instant and private
This is a Base64 encode online tool that does the work in your browser rather than on a server. Type into the box above and the Base64 appears as you go: no button, no page reload, no upload. Switch to Decode to run it in reverse, or open the File & image tab to Base64 encode an image and get a data URI you can paste straight into HTML or CSS.
Everything the standard defines is here: the standard alphabet, URL-safe Base64 (RFC 4648 §5), MIME 76-character line splitting, LF and CRLF separators, per-line encoding, and six character sets from UTF-8 through ISO-8859-1 and UTF-16. If you would rather encode base64 in code than in a browser tab, the snippets below cover Python, JavaScript, Linux, PHP, Java, Go, C# and Ruby.
Why this one
The difference is where the encoding happens.
Most Base64 tools POST your file to a server, encode it there and hand back a download link. That means your data left your machine — for a transformation your browser can do in microseconds. This one never makes that request.
| Feature | freebase64encode.com | Typical online encoder |
|---|---|---|
| Where your data is processed | Your browser tab, always | Uploaded to a server |
| File size limit | Only your device memory | Typically capped at 100 MB |
| Files stored on a server | Never — there is no endpoint | Held temporarily, then deleted |
| Works offline | Yes, after the first visit | No |
| Live encoding as you type | On by default | Opt-in, or a button press |
| Encode and decode | One page, one click to swap | Two separate pages |
| Image → data URI + HTML/CSS/Markdown | Built in, with preview | Not offered |
| Code snippets for 8 languages | On the page | Not offered |
| Size overhead shown | Live byte counts and % | Not shown |
| Ads and cookie banners | None, and no tracking cookies | Usually present |
Do it in code
Base64 encode in Python, JavaScript, Linux and five more.
Copy-paste-ready encoding and decoding for the languages people actually search for — with the gotcha that costs everyone an afternoon called out in each one.
Python Base64 encode
Python ships Base64 in the standard library. The one thing that trips people up: b64encode takes bytes, not str, so text has to be encoded to UTF-8 first.
import base64
# Encode a string ─ note the .encode("utf-8"): b64encode takes bytes, not str
text = "Man is distinguished"
encoded = base64.b64encode(text.encode("utf-8")).decode("ascii")
print(encoded) # TWFuIGlzIGRpc3Rpbmd1aXNoZWQ=
# Decode it back
decoded = base64.b64decode(encoded).decode("utf-8")
# URL-safe, unpadded (RFC 4648 §5) ─ the JWT flavour
base64.urlsafe_b64encode(b"data").rstrip(b"=")
# Encode a file, wrapped at 76 characters for MIME
with open("photo.png", "rb") as f:
mime = base64.encodebytes(f.read()).decode("ascii")
# Build a data URI for an image
uri = "data:image/png;base64," + base64.b64encode(open("photo.png", "rb").read()).decode() JavaScript Base64 encode
btoa() is the classic browser API, but it throws a InvalidCharacterError on any character above U+00FF. For Unicode text, convert to bytes with TextEncoder first.
// Browser, ASCII only
btoa("hello"); // "aGVsbG8="
atob("aGVsbG8="); // "hello"
// Browser, Unicode-safe ─ btoa() throws above U+00FF
const bytes = new TextEncoder().encode("héllo 🎉");
const b64 = btoa(Array.from(bytes, (b) => String.fromCharCode(b)).join(""));
const text = new TextDecoder().decode(
Uint8Array.from(atob(b64), (c) => c.charCodeAt(0))
);
// Node.js
Buffer.from("hello", "utf8").toString("base64");
Buffer.from(b64, "base64").toString("utf8");
// Modern runtimes ─ no btoa() dance needed
new TextEncoder().encode("hello").toBase64(); // "aGVsbG8="
Uint8Array.fromBase64("aGVsbG8=");
// URL-safe: swap the two characters URLs reserve, then drop padding
const urlSafe = b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
// Encode a file the user picked, without uploading it
const buf = new Uint8Array(await file.arrayBuffer());
const fileB64 = btoa(Array.from(buf, (b) => String.fromCharCode(b)).join("")); Linux Base64 encode
GNU coreutils gives you a base64 command on every Linux box. macOS ships the BSD version, which uses different flags — both are covered below.
# Encode a file
base64 photo.png > photo.b64
# Encode a string ─ use printf, not echo, or you encode a trailing newline too
printf %s 'hello' | base64 # aGVsbG8=
echo 'hello' | base64 # aGVsbG8K ← the K is the newline
# One unbroken line (GNU): disable wrapping
base64 -w 0 photo.png
# MIME-compliant 76-character lines
base64 -w 76 photo.png
# Decode
base64 -d photo.b64 > photo.png
echo 'aGVsbG8=' | base64 --decode
# URL-safe output
base64 -w 0 photo.png | tr '+/' '-_' | tr -d '='
# macOS / BSD base64 ─ no -w flag; use -i / -o, and -D to decode
base64 -i photo.png -o photo.b64
base64 -D -i photo.b64 -o photo.png
# Also available almost everywhere
openssl base64 -A -in photo.png
xxd -p -c 0 file | xxd -r -p | base64 PHP Base64 encode
base64_encode() and base64_decode() are built in with no extension required. Pass strict mode to base64_decode() when the input is untrusted.
$encoded = base64_encode('hello'); // aGVsbG8=
$decoded = base64_decode($encoded);
// Strict mode returns false instead of silently skipping invalid characters
$safe = base64_decode($input, true);
if ($safe === false) { /* not valid Base64 */ }
// URL-safe, unpadded
$url = rtrim(strtr(base64_encode($raw), '+/', '-_'), '=');
// A file as a data URI
$uri = 'data:image/png;base64,' . base64_encode(file_get_contents('photo.png'));
// MIME, 76-character lines
$mime = chunk_split(base64_encode($raw), 76, "\r\n"); Java Base64 encode
java.util.Base64 has been in the JDK since Java 8 and offers three encoders — basic, URL-safe and MIME — so you rarely need a third-party library.
import java.util.Base64;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
// Always name the charset explicitly ─ the platform default is a portability bug
String encoded = Base64.getEncoder()
.encodeToString("hello".getBytes(StandardCharsets.UTF_8));
byte[] raw = Base64.getDecoder().decode(encoded);
String text = new String(raw, StandardCharsets.UTF_8);
// URL-safe, unpadded (RFC 4648 §5)
String jwtPart = Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
// MIME ─ 76-character lines separated by CRLF
String mime = Base64.getMimeEncoder()
.encodeToString(Files.readAllBytes(Path.of("photo.png"))); Go Base64 encode
encoding/base64 exposes four encodings. Std and URL are padded; RawStd and RawURL are the unpadded variants.
import (
"encoding/base64"
"os"
)
encoded := base64.StdEncoding.EncodeToString([]byte("hello")) // aGVsbG8=
decoded, err := base64.StdEncoding.DecodeString(encoded)
if err != nil { /* not valid Base64 */ }
// URL-safe and unpadded ─ what JWT libraries use
token := base64.RawURLEncoding.EncodeToString(raw)
// A file
data, _ := os.ReadFile("photo.png")
uri := "data:image/png;base64," + base64.StdEncoding.EncodeToString(data)
// Stream a large file instead of holding it all in memory
w := base64.NewEncoder(base64.StdEncoding, os.Stdout)
io.Copy(w, f)
w.Close() // Close() flushes the final partial group ─ don't skip it C# Base64 encode
Convert.ToBase64String() covers the common case. .NET 9 added System.Buffers.Text.Base64Url for the URL-safe variant.
using System;
using System.IO;
using System.Text;
string encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes("hello"));
string text = Encoding.UTF8.GetString(Convert.FromBase64String(encoded));
// MIME ─ inserts CRLF every 76 characters
Convert.ToBase64String(bytes, Base64FormattingOptions.InsertLineBreaks);
// URL-safe (.NET 9+)
System.Buffers.Text.Base64Url.EncodeToString(bytes);
// A file as a data URI
string uri = "data:image/png;base64," +
Convert.ToBase64String(File.ReadAllBytes("photo.png"));
// Validate untrusted input without throwing
if (Convert.TryFromBase64String(input, buffer, out int written)) { /* ok */ } Ruby Base64 encode
Reach for strict_encode64 rather than encode64 — the latter wraps output at 60 characters and appends a newline, which surprises people comparing hashes.
require 'base64'
encoded = Base64.strict_encode64('hello') # "aGVsbG8="
decoded = Base64.decode64(encoded)
# encode64 wraps at 60 chars and adds a trailing newline ─ rarely what you want
Base64.encode64('hello') # "aGVsbG8=\n"
# URL-safe (RFC 4648 §5)
Base64.urlsafe_encode64(raw, padding: false)
# A file ─ binread avoids any encoding conversion
Base64.strict_encode64(File.binread('photo.png')) The mechanics
How Base64 encoding actually works.
Base64 rewrites arbitrary bytes as 64 characters that every system on earth agrees on. It takes
three bytes — 24 bits — and re-cuts them into four 6-bit groups. Each group indexes the
alphabet A–Z a–z 0–9 + /.
Because 3 bytes always become 4 characters, the output is exactly one third larger.
Worked example: Man → TWFu
| Text | M | a | n |
|---|---|---|---|
| ASCII | 77 | 97 | 110 |
| Bit pattern | 01001101 01100001 01101110 | ||
| Re-cut into 6 bits | 010011 010110 000101 101110 | ||
| Index | 19 · 22 · 5 · 46 | ||
| Base64 | TWFu | ||
When the input length is not a multiple of three, the last group is padded with
= so the output stays a multiple of four. One leftover
byte gives ==, two leftover bytes give
=.
Where Base64 is used
Email attachments
SMTP was specified for 7-bit text. MIME (RFC 2045) Base64-encodes attachments and wraps the output at 76 characters so mail servers pass it through unchanged.
Data URIs
data:image/png;base64,… inlines a small image, font or SVG straight into HTML or CSS, saving a request. Worth it under a few kilobytes; beyond that the 33% bloat and the lost cacheability cost more than the round trip.
JSON and XML payloads
Neither format can hold arbitrary bytes. Base64 turns a file into a plain string that survives any JSON parser, which is how binary blobs travel through REST APIs.
JWTs and URLs
JSON Web Tokens use base64url — the RFC 4648 §5 variant with - and _ in place of + and / and no padding — so a token can sit safely in a URL, cookie or header.
HTTP Basic auth
Authorization: Basic is literally base64(username:password). It is encoding, not encryption — which is exactly why Basic auth is only acceptable over HTTPS.
Config and secrets files
Kubernetes Secrets, TLS certificates in PEM form and SSH keys all store binary as Base64 so the file stays a readable, diffable, copy-pasteable text file.
Six mistakes that cost people an afternoon
Base64 is not encryption
Anyone can decode it in one command. Never use it to hide a password, an API key or personal data — reach for real encryption instead.
Mismatched character sets garble text
Base64 encodes bytes, and text becomes bytes only after a character set is chosen. Encode as UTF-8 and decode as Latin-1 and you get mojibake. Keep both sides on UTF-8.
echo adds a newline
echo "hi" | base64 encodes four bytes, not two, because echo appends \n. Use printf %s to encode exactly what you typed.
Line wrapping changes the string
MIME output carries CRLF every 76 characters. Most decoders skip whitespace, but a strict comparison or hash of two "identical" strings will fail if one is wrapped.
+ and / break in URLs
+ becomes a space when a query string is form-decoded and / splits paths. Use the URL-safe variant whenever the value goes into a URL or a filename.
It grows your payload by a third
Every 3 bytes become 4 characters. Base64-ing a large upload into a JSON body inflates bandwidth and memory on both ends — send multipart/form-data instead.
Questions
Base64 encoding, answered.
What is Base64 encoding?
Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters (A–Z, a–z, 0–9, + and /). It exists so binary data can travel safely through channels that were designed for text — email bodies, JSON and XML documents, HTTP headers, URLs and HTML attributes. Base64 is an encoding, not encryption: anyone can decode it, so it provides no confidentiality.
How do I Base64 encode text online?
Paste or type your text into the input box on this page. The result appears in the output box immediately — there is no button to press and no page reload, because encoding runs in your browser as you type. Press the Copy button, or Ctrl+Shift+C, to put the Base64 string on your clipboard.
Is this Base64 encoder safe and private?
Yes. Every byte is encoded locally by JavaScript running in your own browser tab. Your text, files and images are never transmitted to a server, never written to a database and never logged — the site is a fully static page with no upload endpoint at all. You can verify this by opening your browser DevTools Network tab while encoding, or by disconnecting from the internet and confirming the tool still works.
How do I Base64 encode in Python?
Use the built-in base64 module. Encode with base64.b64encode(data.encode("utf-8")).decode("ascii") and decode with base64.b64decode(encoded).decode("utf-8"). Note that b64encode takes bytes, not str, which is why the input is encoded to UTF-8 first. For URL-safe output use base64.urlsafe_b64encode, and for MIME output with 76-character lines use base64.encodebytes.
How do I Base64 encode in JavaScript?
For ASCII text, btoa(str) encodes and atob(str) decodes. btoa throws on characters above U+00FF, so for Unicode text first convert to bytes: btoa(String.fromCharCode(...new TextEncoder().encode(str))). In Node.js use Buffer.from(str, "utf8").toString("base64"). Modern runtimes also expose Uint8Array.prototype.toBase64().
How do I Base64 encode a file on Linux?
Use the coreutils base64 command: base64 file.txt encodes it, and base64 -d file.b64 decodes it. Add -w 0 to disable line wrapping when you need a single unbroken line, or -w 76 for MIME-compliant output. To encode a string directly, pipe it: printf %s "hello" | base64 — use printf rather than echo so no trailing newline is included in the encoded bytes.
How do I Base64 encode an image?
Open the File & image tab on this page and drop your image in. You get the raw Base64 plus a ready-to-paste data URI (data:image/png;base64,...) and generated HTML, CSS and Markdown snippets. Base64 makes an image about 33% larger, so inline images are best kept small — under roughly 5 KB — and larger images are better served as normal files that the browser can cache.
What is URL-safe Base64?
Standard Base64 uses + and / which have reserved meanings in URLs and filenames. URL-safe Base64 (RFC 4648 §5, also called base64url) substitutes - for + and _ for /, and usually drops the = padding. It is what JSON Web Tokens use. Toggle the URL-safe option on this page to produce it.
Why does my Base64 string end with = signs?
Base64 processes input in 3-byte groups that map to 4 output characters. When the input length is not a multiple of 3, the final group is padded with = so the output length stays a multiple of 4. One leftover byte produces two = characters, two leftover bytes produce one. The padding carries no data and is optional in some variants such as base64url.
How much larger does Base64 make my data?
About 33% larger — every 3 bytes of input become 4 characters of output, a ratio of 4/3. Line breaks in MIME mode add a further ~1.4%. This tool shows the exact input size, output size and overhead percentage under the output box as you type.
Is there a file size limit?
There is no server-side limit because there is no server involved. The practical ceiling is your device memory and browser tab limits; files up to a few hundred megabytes generally work on desktop, and this tool streams large files in chunks so the browser stays responsive. Competing tools that upload to a server typically cap you at 100 MB.
Does Base64 encoding work with Unicode and emoji?
Yes. Text is converted to bytes first using the character set you select — UTF-8 by default, which covers every Unicode code point including emoji — and those bytes are then Base64 encoded. Mismatched character sets between the encoder and decoder are the usual cause of garbled output, so keep both on UTF-8 unless you have a specific reason not to.