Encoding

Base64 Encoder / Decoder

Encode text to Base64 or decode it back, including URL-safe Base64. Runs entirely in your browser, so whatever you paste never leaves your machine.

Text in
Base64 out

What is Base64?

Base64 is a way to represent binary data using only 64 printable ASCII characters (A-Z, a-z, 0-9, +, /). It exists because many systems, email headers, URLs, JSON, HTTP basic auth, were built for text and will mangle raw bytes. Encoding to Base64 lets binary travel safely through a text-only channel, then decode back to the exact original bytes on the other side.

Why Base64 exists

The same need shows up all over the stack, any time bytes have to ride through something built for text:

  • Email (MIME): attachments are Base64 so 8-bit binary survives mail servers that expect text. See how SMTP works.
  • Data URIs: a small image or font embedded straight into HTML or CSS as data:image/png;base64,…, no extra request.
  • JSON & APIs: JSON has no binary type, so bytes (a file, a hash, an image) travel as a Base64 string. Pair it with JSON tools.
  • HTTP Basic auth: the Authorization header sends Base64(user:pass). See HTTP explained.
  • Tokens: a JWT is three Base64URL parts; its payload is just Base64-encoded JSON.

How Base64 works

Base64 takes 3 bytes (24 bits) at a time and splits them into 4 groups of 6 bits. Each 6-bit group is a number from 0 to 63, which maps to one character in the alphabet below. Three input bytes always become four output characters, which is why Base64 is about 33% larger than the original.

TextHel
3 bytes = 24 bits, regrouped into 4 × 6 bits
Base64SGVs

Encode the whole word Hello (5 bytes) and you get SGVsbG8=. The trailing = is padding: when the input is not a clean multiple of 3 bytes, one or two = keep the output length a multiple of 4. Try it in the tool above.

Standard vs URL-safe

  • Standard uses + and / and pads with =.
  • URL-safe (RFC 4648 §5) swaps + to - and / to _, and usually drops the =, so the string is safe inside a URL or filename. Toggle it above.

Base64 character table

The 64 values and the character each one maps to (index 0 to 63):

0A1B2C3D4E5F6G7H8I9J10K11L12M13N14O15P16Q17R18S19T20U21V22W23X24Y25Z26a27b28c29d30e31f32g33h34i35j36k37l38m39n40o41p42q43r44s45t46u47v48w49x50y51z52053154255356457558659760861962+63/ pad=

Common examples

  • Encode text: Hello becomes SGVsbG8=.
  • Decode: S0IgQ2FmZQ== becomes KB Cafe (load the sample above).
  • Data URI: data:text/plain;base64,SGVsbG8= renders as Hello.
  • JWT payload: the middle segment of a token is Base64URL JSON, decode it with the JWT decoder.

Base64 in code

JavaScript

// Browser, Unicode-safe (handles emoji and accents)
const bytes = new TextEncoder().encode("Hello");
const b64   = btoa(String.fromCharCode(...bytes));   // "SGVsbG8="

const bin  = atob(b64);
const text = new TextDecoder().decode(Uint8Array.from(bin, c => c.charCodeAt(0)));

// Node.js
Buffer.from("Hello", "utf8").toString("base64");      // "SGVsbG8="
Buffer.from("SGVsbG8=", "base64").toString("utf8");   // "Hello"

Python

import base64

base64.b64encode(b"Hello").decode()      # 'SGVsbG8='
base64.b64decode("SGVsbG8=").decode()    # 'Hello'

# URL-safe variant
base64.urlsafe_b64encode(b"Hello").decode()
base64.urlsafe_b64decode(data)

Base64 vs Hex

Both turn bytes into text. They trade size against readability:

Base64Hex
Alphabet64 chars (A-Z a-z 0-9 + /)16 chars (0-9 a-f)
Size~33% larger than input100% larger (2 chars per byte)
ReadabilityDense, hard to read by eyeEach byte is plainly visible
Typical useTransport, data URIs, JWT, emailHashes, color codes, debugging

Common mistakes

  • Treating it as security. Base64 is trivially reversible, this page decodes it in one click. It hides nothing; use real encryption for secrets.
  • Unicode with btoa(). Raw btoa("café") throws. Encode to UTF-8 bytes first (as the JavaScript example does).
  • Dropped or wrong padding. Some decoders reject a string whose length is not a multiple of 4. If you stripped =, add it back before decoding.
  • Forgetting URL-safe. Standard Base64’s + and / break inside URLs and filenames. Use the URL-safe variant there.
  • Double encoding. Encoding an already-Base64 string just makes it bigger and confusing.

FAQ

Is Base64 encryption?

No. Base64 is encoding, not encryption. Anyone can decode it instantly with no key, so it provides no confidentiality. Use it to move bytes safely through text channels, and use real encryption to protect secrets.

Why is my Base64 longer than the input?

Every 3 bytes become 4 characters, so the encoded output is about 33% larger than the original. That overhead is the price of being safe to send through text-only systems.

What are the = signs at the end?

They are padding. Base64 output length is always a multiple of 4, so when the input is not a multiple of 3 bytes, one or two = characters pad the final group. URL-safe Base64 often omits them.

What is URL-safe Base64?

A variant from RFC 4648 that replaces + with - and / with _, and usually drops the = padding, so the string is safe inside URLs and filenames. JSON Web Tokens use it.

Why does Base64 break on emojis or accented characters?

In browsers, btoa() only handles characters in the Latin1 range. For Unicode you must encode the text as UTF-8 bytes first (for example with TextEncoder), then Base64 those bytes. This tool does that for you.

Is a JWT encrypted because it is Base64?

No. A standard JWT is three Base64URL parts, and the payload is readable by anyone who decodes it. The signature proves it was not tampered with, but it does not hide the contents.

What is a data URI?

A way to embed a file inline as text, written data:[mediatype];base64,[data]. It lets you put a small image or font directly in HTML or CSS instead of making a separate request.

Base64 vs hex, which should I use?

Base64 is more compact, about 33% overhead versus 100% for hex, so it is better for size. Hex is simpler to read by eye. Use Base64 for transport and storage, hex for debugging and hashes.

Can I Base64 encode an image or file?

Yes. The bytes of any file can be Base64 encoded, which is how images get embedded as data URIs. The result is larger than the binary, so it suits small assets rather than big files.

Why did my decoded text come out as gibberish?

Usually a character-set mismatch or missing padding. Make sure the input is complete Base64, that you picked the right variant (standard vs URL-safe), and that the original bytes were UTF-8 text, not raw binary.

Does this tool upload my data?

No. Encoding and decoding happen entirely in your browser, so whatever you paste stays on your machine and the tool keeps working offline.

Is Base64 a kind of compression?

No, the opposite. Base64 makes data about a third larger. It exists to make bytes text-safe, not to make them smaller.

Related concepts

JWT decoder · JSON to TypeScript · HTTP explained · How SMTP works · What is RSS · all references.

☕ KB Cafe Classic

This guide is a modern restoration of one of kbcafe.com’s most-referenced technical resources from the early web era, rewritten for today’s development practices and kept fully client-side. The original Base64 how-to was linked across the developer web for years; this is its current home.