Skip to the Base64 encoder

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 keeps working offline and has no size limit.

  • Encodes as you type
  • Text, files & images
  • URL-safe & MIME modes
  • No ads, no sign-up
0 characters · 0 B
0 characters · 0 B
Options
Encoding variants

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 and macOS, PowerShell, PHP, Java, Go, C# and Ruby.

Last updated

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 comparison between this Base64 encoder and typical server-based online Base64 tools
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
Keeps working if you go offline Yes, once the page has loaded 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 9 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, Bash, PowerShell 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()

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 Man
ASCII 7797110
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 =.

Base64 encode examples

What common strings look like once Base64 encoded as UTF-8. Paste any of them into the tool above to check.

Example strings and their Base64 encoding
Input Base64 Note
Hello, World! SGVsbG8sIFdvcmxkIQ== Two = because 13 bytes leave one spare
Hello World SGVsbG8gV29ybGQ= 11 bytes, so one =
hello aGVsbG8=
base64 YmFzZTY0 6 bytes divide by 3, so no padding
user:password dXNlcjpwYXNzd29yZA== An HTTP Basic auth header value
héllo 🎉 aMOpbGxvIPCfjok= UTF-8: é is 2 bytes, the emoji 4
{"alg":"HS256","typ":"JWT"} eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 A JWT header, URL-safe and unpadded

The Base64 alphabet (index table)

Each 6-bit value from 0 to 63 maps to one character. The URL-safe alphabet is identical except that 62 is - and 63 is _. = is padding, not part of the alphabet.

Base64 index table: values 0 to 63 and their characters
Value Char Value Char Value Char Value Char
0 A 16 Q 32 g 48 w
1 B 17 R 33 h 49 x
2 C 18 S 34 i 50 y
3 D 19 T 35 j 51 z
4 E 20 U 36 k 52 0
5 F 21 V 37 l 53 1
6 G 22 W 38 m 54 2
7 H 23 X 39 n 55 3
8 I 24 Y 40 o 56 4
9 J 25 Z 41 p 57 5
10 K 26 a 42 q 58 6
11 L 27 b 43 r 59 7
12 M 28 c 44 s 60 8
13 N 29 d 45 t 61 9
14 O 30 e 46 u 62 +
15 P 31 f 47 v 63 /

Base64 variants compared

“Base64” is a family. They share the same 62 letters and digits and differ in the last two characters, padding and line wrapping. The tool above produces the first three.

Comparison of Base64 variants: standard, URL-safe, MIME and PEM
VariantSpecChars 62 / 63PaddingLine breaksUsed for
Standard RFC 4648 §4 + / Required None General purpose, JSON, data URIs
URL-safe (base64url) RFC 4648 §5 - _ Usually omitted None JWTs, URLs, filenames
MIME RFC 2045 + / Required CRLF every 76 Email attachments
PEM RFC 7468 + / Required Every 64, with BEGIN/END TLS certificates, keys

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 three 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.

How do I Base64 encode a string?

A string is first turned into bytes with a character set — almost always UTF-8 — and those bytes are Base64 encoded. On this page that happens automatically: type the string and copy the result. For example, "Hello, World!" Base64 encodes to SGVsbG8sIFdvcmxkIQ==. In code it is one line in every major language; see the snippets for Python, JavaScript, Bash, PowerShell, PHP, Java, Go, C# and Ruby.

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 PowerShell or Windows?

In PowerShell run [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("hello")) to encode a string, or [Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\path\file.png")) to encode a file. From cmd.exe, certutil -encode in.png out.b64 works on every Windows install, though it adds BEGIN and END header lines. Use [Text.Encoding]::Unicode (UTF-16 LE) only for powershell -EncodedCommand.

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(Array.from(new TextEncoder().encode(str), (b) => String.fromCharCode(b)).join("")). Avoid the spread form String.fromCharCode(...bytes), which overflows the call stack on large inputs. 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 on a Mac?

macOS ships the BSD base64 command in Terminal. Encode a file with base64 -i file.png -o file.b64, a string with printf %s "hello" | base64, and decode with base64 -D -i file.b64 -o file.png. Unlike GNU base64 on Linux it does not wrap lines by default and has no -w flag. Pipe into pbcopy to put the result straight on the clipboard.

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. The exact padded length is 4 × ⌈n / 3⌉ characters for n input bytes, so 10 bytes encode to 16 characters and 1 MB encodes to about 1.33 MB. Line breaks in MIME mode add a further ~2.6% (a two-byte CRLF after every 76 characters). 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.