About this tool
Base64 is a widely used binary-to-text encoding scheme based on 64 printable ASCII characters (RFC 4648). Because legacy networking protocols like HTTP and SMTP were originally designed to transfer standard ASCII text, sending raw binary bytes directly risks truncation or character corruption. Base64 translates every 3 bytes into 4 printable characters to guarantee lossless transport across any text-based channel.
How to Use This Tool (Step-by-Step)
Enter Text or Encoded String
Paste raw text or an existing Base64 string into the input area. Full UTF-8 support handles Chinese, Japanese, symbols, and emoji seamlessly.
Select Encode or Decode Mode
Click 'Encode' to generate the Base64 ASCII representation, or click 'Decode' to restore the encoded string back into readable plain text.
Copy Result with One Click
The converted output displays instantly. Click copy to embed it into Data URLs, Basic Auth headers, or backend configuration files.
Flawless UTF-8 & CJK Support
Fixes the common browser window.btoa pitfall that throws InvalidCharacterError when encountering Unicode characters like Chinese or emojis.
Zero Server Uploads
All string and byte conversions run strictly in your browser memory. Safely encode Basic Auth credentials or private tokens with peace of mind.
Padding & Error Resilient
Automatically handles '=' padding characters according to RFC 4648 and verifies syntax before decoding to prevent runtime crashes.
Key Concepts & Common Misconceptions
- •Base64 is encoding, NOT encryption: Base64 has zero cryptographic protection. Anyone can decode it without a key. Never use it to protect raw passwords.
- •33% size overhead: Mapping 3 bytes (24 bits) into 4 characters (6 bits each) increases payload size by roughly 33%. Keep this in mind for large image embeds.
- •URL safety differences: Standard Base64 uses '+' and '/', which can be ambiguous in URLs. Use the Base64URL variant ('-' and '_') when embedding inside query strings.
Code & Transformation Examples
Text to Base64 Encoding Example
Hello, 世界! 🚀SGVsbG8sIOS4lueVjCEg8J+agA==* The trailing '==' indicates padding added when the input length is not a multiple of 3 bytes.
Native Implementation across Languages
// 编码 (UTF-8 安全)
const encoded = btoa(unescape(encodeURIComponent("Hello 世界")));
// 解码
const decoded = decodeURIComponent(escape(atob(encoded)));import base64
# 编码
encoded = base64.b64encode("Hello 世界".encode('utf-8')).decode('ascii')
# 解码
decoded = base64.b64decode(encoded).decode('utf-8')* Always encode text to UTF-8 bytes prior to Base64 transformation when dealing with multibyte characters.
Frequently Asked Questions
Q: Why do Base64 strings often end with '=' or '=='?
A: Base64 processes data in 3-byte blocks. If the input is not divisible by 3, '=' padding characters are appended to indicate how many filler bits were added.
Q: Is Base64 suitable for embedding large images via Data URI?
A: It is ideal for tiny icons (< 10KB) to save HTTP roundtrips. For larger assets, the 33% size penalty and lack of independent image caching hurt performance.
Q: Why does window.btoa throw a 'character out of range' error?
A: window.btoa only accepts Latin1 (bytes 0-255). Feeding it Unicode, Chinese, or emoji causes an exception. Our tool handles Unicode-to-UTF8 byte streams automatically.