{ }
中文

Base64 Encode / Decode

Encode text to Base64 or decode Base64 strings instantly.

What is Base64?

Base64 is a binary-to-text encoding scheme that represents arbitrary binary data as an ASCII string using 64 printable characters: A–Z, a–z, 0–9, and the symbols + and /. The padding character = is appended so the encoded output length is always a multiple of four. Base64 was originally designed for safely embedding binary data in 7-bit channels such as email (MIME), where high-byte values would otherwise be corrupted by transport servers.

Modern uses of Base64 include data URIs in CSS and HTML, Basic Authentication tokens in HTTP headers, the payload section of JSON Web Tokens, and binary attachments in JSON or XML where a plain string is required. A URL-safe variant exists that replaces + with - and / with _ so the encoded string can travel inside a URL without further escaping.

This tool encodes and decodes Base64 entirely in your browser. Input is first converted to UTF-8 bytes via the standard TextEncoder, ensuring that Chinese, Japanese, Korean, emoji, and other multi-byte characters round-trip correctly. Whitespace inside Base64 input is tolerated during decoding.

Use cases

  • Embed small images or fonts inline in CSS or HTML using data URIs.
  • Encode binary payloads so they can travel safely inside JSON or XML.
  • Decode Basic Auth tokens (the value after "Basic " in the Authorization header).
  • Inspect the payload section of a JWT (the middle segment between the dots).
  • Encode credentials or short messages that need to survive a 7-bit text channel.

Best practices

  • Never treat Base64 as encryption — it is reversible by anyone with a few lines of code.
  • Use the URL-safe variant ("-" and "_") when the encoded string is placed inside a URL.
  • Strip whitespace before decoding if the source pasted in line breaks.
  • Be aware that Base64 grows the payload by roughly 33%, plus the overhead of MIME line wrapping.

Code examples

JavaScript
const encoded = btoa(unescape(encodeURIComponent("héllo")));
// 'aMOpbGxv'
const decoded = decodeURIComponent(escape(atob(encoded)));
Python
import base64
encoded = base64.b64encode("héllo".encode("utf-8")).decode("ascii")
decoded = base64.b64decode(encoded).decode("utf-8")
Bash
echo -n 'héllo' | base64        # encode
echo 'aMOpbGxv' | base64 -d    # decode

Frequently asked questions

Does Base64 encryption protect my data?
No. Base64 is an encoding, not encryption — anyone can decode it. Use it for transport, not for secrecy.
How much larger is Base64 output?
Base64 expands binary data by roughly 33% (every 3 bytes become 4 characters).
Does this tool support Chinese, Japanese, or emoji?
Yes. Input is first converted to UTF-8 bytes before encoding, so all Unicode characters round-trip correctly.
Why does my decoded result look garbled?
The input may be URL-safe Base64 (using - and _ instead of + and /) or may contain stray whitespace. Clean the string and try again.
What is the = sign at the end?
It is padding. Base64 output length is always a multiple of four; if the source bytes do not divide evenly the encoder appends one or two = characters.