Skip to main content

Base64 Encoder / Decoder

Convert Unicode text and files with standard Base64 or Base64URL, including Data URLs, optional padding, and binary download after decoding.

Variant

Base64 Result

The converted result appears here.

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.
  • Encoding and decoding run in this browser tab without uploading the entered text or selected file.

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. Yes. Select Base64URL to use URL-safe characters and choose whether trailing padding should be included.

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

A. Yes. Choose a file to produce raw Base64 or a Data URL. Decoding reconstructs the original bytes, including non-UTF-8 data, for download.

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 '/', while Base64URL (RFC 4648 §5) substitutes '-' and '_'. This tool produces either variant with optional padding and automatically normalizes both variants when decoding.

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).

Data Handling & Security Notes

Base64 conversion uses TextEncoder, TextDecoder, btoa(), and atob() in the browser. The conversion action does not upload the entered text or selected file.

Base64 is not encryption. Avoid exposing secrets through screenshots, clipboard history, downloaded files, browser extensions, or shared-device sessions.

Text input and output are held in React state for the current page session. Selected files and downloads remain subject to the browser, operating system, backup, and shared-device controls.

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.