Base64 Encoder / Decoder

Encode text to Base64 or decode Base64 back to text. Full Unicode and Japanese character support.

How to use the Base64 Converter

  1. 1

    Select 'Encode' or 'Decode' from the mode tabs at the top.

  2. 2

    Type or paste your input text — the result appears immediately in the output area below.

  3. 3

    Click 'Copy' to copy the result to your clipboard.

  4. 4

    Use 'Swap input & output' to feed the current output as the next input — useful for verifying a round-trip encode then decode.

Features

  • Full Unicode support: Uses TextEncoder (UTF-8) and TextDecoder APIs for accurate handling of Japanese, Chinese, emoji, and all multilingual text.
  • Real-time conversion: Results update instantly as you type — no submit button needed.
  • Swap feature: Transfer the output directly to the input with one click to quickly reverse the conversion.
  • 100% browser-based: Input text is never sent to any server. Safe for sensitive or private data.

FAQ

Q. Why does encoding Japanese text require special handling?

A. JavaScript's built-in btoa() only supports ASCII. Multi-byte characters like Japanese cause errors if passed directly. This tool uses TextEncoder to convert text to a UTF-8 byte array first, handling all Unicode characters correctly.

Q. Decoded text looks garbled — what's wrong?

A. This tool assumes UTF-8 encoding when decoding. If the Base64 string was created from text encoded in Shift-JIS or another legacy encoding, the decoded output may appear as garbled characters.

Q. Where is Base64 commonly used?

A. Base64 is widely used in email attachments (MIME), embedding images in HTML/CSS as Data URLs, JWT (JSON Web Token) payloads, and transmitting binary data over text-based APIs.

Q. Does this tool support URL-safe Base64 (Base64url)?

A. The tool uses standard Base64 (RFC 4648 §4). URL-safe Base64 (Base64url) substitutes + with -, / with _, and omits = padding. After encoding, you can manually apply those substitutions to convert to Base64url format.

Q. Can I encode binary files like images or PDFs?

A. The tool accepts text input only and is not designed for binary file encoding. To Base64-encode a file in JavaScript, use FileReader.readAsDataURL() in the browser, or Buffer.from(data).toString('base64') in Node.js.

Technical Deep Dive: Base64 Encoding & Unicode Handling

Base64 encodes arbitrary binary data as printable ASCII text. The algorithm groups the input into 3-byte (24-bit) blocks, splits each block into four 6-bit values, and maps each to one of 64 characters: A–Z, a–z, 0–9, +, and /. If the input length is not a multiple of 3, one or two '=' padding characters are appended. This transformation expands data size by approximately one-third (4 output bytes per 3 input bytes) in exchange for ASCII-safe portability.

JavaScript's built-in btoa() function only accepts characters in the Latin-1 range (U+0000–U+00FF). Passing multi-byte text like Japanese directly causes a 'InvalidCharacterError'. This tool routes encoding through the TextEncoder API (part of the WHATWG Encoding Living Standard): new TextEncoder().encode(text) produces a Uint8Array of UTF-8 bytes, which is then chunked, converted to a binary string via String.fromCharCode(), and passed to btoa(). Decoding reverses this: atob() → binary string → Uint8Array → new TextDecoder('utf-8').decode().

Standard Base64 (RFC 4648 §4) uses '+' and '/' which are special characters in URLs and HTTP query strings. URL-safe Base64 (Base64url, RFC 4648 §5) solves this by substituting '+' with '-' and '/' with '_', and omitting the '=' padding. JWT (JSON Web Token) headers and payloads use Base64url encoding. This tool implements standard Base64; manual character substitution converts the output to Base64url when needed.

A common use case for Base64 is embedding binary assets in text-based contexts: inline images in HTML/CSS as Data URLs (data:image/png;base64,...), MIME-encoded email attachments, JWT payload inspection, and transporting binary blobs over text APIs that lack native binary support (e.g., some WebSocket or Server-Sent Events implementations).

Security & Privacy Guarantee

All Base64 encoding and decoding is performed using browser-native synchronous APIs: TextEncoder, TextDecoder, btoa(), and atob(). None of these APIs involve network communication. Input text never leaves the browser's JavaScript runtime.

API keys, JWT tokens, OAuth authorization codes, and other sensitive strings can be safely encoded or decoded without any risk of server-side exposure. You can verify the absence of network traffic at any time using your browser's DevTools Network tab.

Input and output data are held only in React state (browser memory) and are released immediately when you click 'Clear', navigate away, or close the tab. This service performs no logging or analysis of content entered into the encoder or decoder.

Examples, Cautions, and Common Mistakes

Examples

  • Encode credentials for an API Basic Authentication header.
  • Check small image strings or configuration values before embedding them in JSON or Data URLs.
  • Decode Base64 snippets from logs or sample data to inspect the original content.

Cautions

  • Base64 is not encryption. Anyone can decode it and read the original content.
  • Confirm UTF-8 handling when encoding or decoding text that includes non-ASCII characters.
  • Base64 output is larger than the original data, so avoid using it blindly for large files.

Common Mistakes

  • Publishing tokens or passwords because they look hidden after Base64 encoding.
  • Including extra line breaks or spaces and then wondering why decoding fails.
  • Mixing standard Base64 with URL-safe Base64 and mishandling `+` or `/` characters.