Base64 Encoder/Decoder

Encode and decode Base64, including UTF-8, URL-safe alphabet, and MIME wrap.

Encode and decode Base64

Convert UTF-8 text to Base64 and back. Toggle the URL-safe alphabet or MIME wrap. Everything stays in your browser.

Runs in your browser. Nothing is uploaded.

Paste text above to encode it as Base64, or paste Base64 to decode it back to UTF-8. URL-safe alphabet and MIME wrap are toggles — nothing is uploaded. This Base64 encoder is part of the programming tools on TechOpt.io, next to the UUID generator.

What this Base64 encoder actually does

Base64 turns bytes into ASCII so they can travel through systems that expect text: email bodies, JSON, query strings, and HTML data: URIs. The alphabet is 64 characters — A–Z, a–z, 0–9, plus + and / — so every three input bytes become four output characters (a 4/3 size increase), as specified in RFC 4648. It is encoding, not encryption. Anyone who sees the string can decode it.

UTF-8 vs Latin-1 (why btoa throws)

JavaScript’s btoa() only accepts Latin-1: each character must be a single byte, 0–255. Type café or 日本語 and the browser throws. The right sequence is UTF-8 bytes first, then Base64 those bytes. This tool uses TextEncoder / TextDecoder, so Unicode round-trips. Decode of bytes that are not valid UTF-8 is rejected rather than silently mojibake’d.

URL-safe alphabet and padding

Standard Base64’s + and / are special in URLs and filenames. RFC 4648 defines a URL-safe alphabet that uses - and _ instead. JWTs and many APIs also drop the trailing = padding. Turn on URL-safe to emit that form. Decode still accepts both alphabets, with or without padding, and ignores whitespace.

Padding exists because Base64 groups input into 3-byte blocks. A short final block is padded with one or two = characters so the output length is a multiple of four. If you see ==, the last block had one byte; a single = means two bytes.

MIME wrap at 76 characters

RFC 2045 (MIME) requires Base64 bodies in email to wrap at 76 characters per line. Data URIs, JWTs, and most HTTP APIs want a single line. Turn on Wrap at 76 characters for email-style output; leave it off otherwise. Decode strips whitespace, so wrapped input still works.

Typical uses

You will mostly meet Base64 in three places:

  • Data URIsdata:image/png;base64,... inlines a file in HTML or CSS. This page is a text encoder; for a whole file, encode the bytes in your own code.
  • JWTs — header and payload are URL-safe Base64 (no padding). The signature is binary, also Base64url. Anyone can read the payload; the signature is what you verify.
  • Email (MIME) — attachments and 8-bit bodies travel as wrapped Base64 so they survive 7-bit relays.

Encode and decode in code

The widget above is for a quick copy. In application code, use the standard library:

const bytes = new TextEncoder().encode('café');
const b64 = btoa(String.fromCharCode(...bytes));
const roundTrip = new TextDecoder().decode(
  Uint8Array.from(atob(b64), (c) => c.charCodeAt(0))
);
import base64
base64.b64encode('café'.encode()).decode()
base64.urlsafe_b64encode('café'.encode()).decode()
base64_encode('café');
base64_decode($b64);

FAQ

What is Base64 encoding?

Base64 turns binary data into ASCII using 64 characters (A–Z, a–z, 0–9, +, /) so it can travel through systems that expect text — email, JSON, URLs, and HTML data URIs. Every three bytes become four characters. It is encoding, not encryption: anyone can decode it.

Why does JavaScript btoa() fail on Unicode?

btoa() only accepts Latin-1 (bytes 0–255). A character like é or 漢 is outside that range, so the browser throws. This tool encodes UTF-8 bytes first, then Base64, so café and CJK text round-trip correctly.

What is URL-safe Base64?

Standard Base64 uses + and / , which are special in URLs and filenames. The URL-safe alphabet (RFC 4648) replaces them with – and _ and often drops = padding. JWTs and many APIs use this form. Turn on URL-safe above; decode still accepts both alphabets.

What do the = padding characters mean?

Base64 groups input into 3-byte blocks. If the last block is short, the output is padded with one or two = characters so the length is a multiple of 4. URL-safe encodings often omit padding; this decoder accepts either.

Does this Base64 encoder upload my text?

No. It runs entirely in your browser. Plain text and Base64 never leave your machine.

When should I wrap Base64 at 76 characters?

MIME (email) requires Base64 bodies to wrap at 76 characters per line (RFC 2045). Data URIs, JWTs, and most APIs want a single line. Turn on Wrap at 76 for email-style output; leave it off for everything else.

Is Base64 encryption?

No. It is a reversible text encoding. Do not put secrets in Base64 and call them hidden. Use a real cipher (TLS, age, GPG) when the content must stay confidential.

Looking for more developer how-tos? Browse the programming guides or the rest of the tools.