Base64 Encode / Decode

Convert text to Base64 and back, including UTF-8 and URL-safe variants.

Direction
0 characters

Or drop a .txt file onto the box above.

Encoding options

How to use

  1. Choose Encode (text to Base64) or Decode (Base64 to text). The box labels change to match.
  2. Paste or type into the left box; the result appears on the right as you type.
  3. When encoding, tick URL-safe alphabet for anything that will live in a URL, and Omit "=" padding if the receiving system does not expect it.
  4. Copy to clipboard, or press ⇄ Swap to send the result back through in the other direction and confirm it round-trips.

What Base64 is for

Base64 turns arbitrary bytes into text made up of only 64 printable ASCII characters (A–Z, a–z, 0–9, "+", "/"), plus "=" for padding. That makes it safe to embed binary data (or text using characters some systems can't handle) inside formats that only guarantee plain ASCII will survive: email (MIME attachments), URLs, JSON strings, and configuration files. The trade-off is size: every 3 bytes become 4 characters, so the output is roughly a third larger than the input.

It is not encryption. Encoding and decoding require no secret, so Base64 should never be used as a way to hide sensitive data, only to safely transport it through systems that would otherwise mangle raw bytes. The alphabet, padding and URL-safe variant used here are the ones defined in RFC 4648.

Example

Encoding Hello, world! produces:

SGVsbG8sIHdvcmxkIQ==

The two trailing = signs are padding: 13 bytes is not a multiple of 3, so the last group is filled out. Decoding SGVsbG8sIHdvcmxkIQ== (with or without the padding) gives Hello, world! back.

Options explained

Edge cases and common errors

Where you'll run into Base64

Do the same thing in code

JavaScript

// Browser: go through UTF-8 bytes so non-ASCII text works
const bytes = new TextEncoder().encode(text);
const encoded = btoa(Array.from(bytes, (b) => String.fromCharCode(b)).join(""));
const decoded = new TextDecoder().decode(Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0)));

// Node.js
const encoded2 = Buffer.from(text, "utf8").toString("base64");
const urlSafe = Buffer.from(text, "utf8").toString("base64url");

Python

import base64
encoded = base64.b64encode(text.encode("utf-8")).decode("ascii")
decoded = base64.b64decode(encoded).decode("utf-8")
url_safe = base64.urlsafe_b64encode(text.encode("utf-8")).rstrip(b"=")

Shell

printf 'Hello, world!' | base64          # encode
printf 'SGVsbG8sIHdvcmxkIQ==' | base64 -d  # decode

Base64 Encode / Decode FAQ

Is Base64 encryption?

No. Base64 is a reversible encoding, not a cipher; anyone can decode it back to the original text with no key or password. It exists to safely represent binary or Unicode data using only the 64 characters that are guaranteed safe in contexts like email headers, URLs, and older text-only systems.

What is “URL-safe” Base64?

Standard Base64 uses "+" and "/", both of which have special meaning inside a URL. The URL-safe variant replaces them with "-" and "_" so the encoded text can be used directly in a URL path or query string without extra escaping.

Why does decoding sometimes fail?

Base64 text must be made up only of A–Z, a–z, 0–9, "+", "/" (or "-", "_" for the URL-safe variant) and optional "=" padding. If you paste text that includes a "data:" prefix, or the string was truncated to a length Base64 cannot produce, decoding reports exactly what looks wrong.

Does this handle emoji and non-English text?

Yes. Text is encoded as UTF-8 bytes before Base64, so accented letters, CJK text and emoji all round-trip correctly. Decoding a value that was not UTF-8 to begin with (an image, say) is reported as an error rather than shown as garbage.

Runs entirely in your browser: this page is a static file with no server behind it, so nothing you paste can be uploaded. Last reviewed by Parthesh Gupta. Implements RFC 4648 (Base64).