Skip to content

Base64 encode and decode

Encode text or a file to Base64, or decode it back.

0 characters · 0 lines

0 characters · 0 lines

Your files are open only in this tab. Nothing is uploaded.

How to use Base64 encode and decode

  1. Select your mode. Choose Encode to turn text or files into ASCII text, or Decode to turn encoded strings back into UTF-8 text or a downloadable file.
  2. Paste text or pick a file. Type into the input box, or click Encode a file… in Encode mode to load any local asset up to 25 MB.
  3. Adjust URL-safe or data URL options. Check URL-safe (- and _, no padding) for web tokens, or check As a data: URL after encoding a file.
  4. Copy or save the output. Use Copy for text results, Download for .b64.txt files, or Save decoded file when binary data is detected.

Everything runs in this browser tab. Nothing you paste or open is uploaded or logged, so it's safe for keys, tokens and private data.

How this Base64 encoder online handles UTF-8 text and btoa errors

Browser-native encoding turns raw bytes and Unicode strings into printable ASCII without sending API keys or payloads to a backend. Text is serialized to UTF-8 bytes before encoding, and pasted payloads are cleaned of whitespace and data: prefixes before decoding.

Fixing btoa Unicode errors with TextEncoder

Passing accented characters like wörld or symbols like ✓ directly into JavaScript’s btoa() throws a DOMException because btoa() rejects code points above 255. This encoder runs strings through the MDN Web Docs TextEncoder API first, converting every character into a standard UTF-8 Uint8Array before mapping 6-bit chunks to printable ASCII.

When you need to escape reserved characters inside query parameters rather than encoding binary payloads, use percent-encoding for query strings and full URLs instead.

Catching invalid characters and length remainder errors

During decoding, the parser trims surrounding spaces, strips any data:...;base64, header, and accepts both standard and URL-safe alphabets with or without = padding. If the cleaned string contains invalid characters or has a length % 4 === 1 remainder (impossible in valid 6-bit blocks), the tool pinpoints the exact offending character or truncation error.

Standard Base64 versus URL-safe Base64 and Base64 vs hex

Choosing the right binary-to-text alphabet prevents broken HTTP query strings and keeps payload bloat predictable. Checking URL-safe (- and _, no padding) switches between the two variants defined in IETF RFC 4648 Base64 Data Encodings.

When to enable URL-safe Base64 (- and _, no padding)

The standard alphabet (RFC 4648 Section 4) uses +, /, and =, all of which carry special meaning in URLs and shell arguments. Enabling URL-safe (- and _, no padding) applies RFC 4648 Section 5 (- instead of +, _ instead of /, and no trailing =), which is required for OAuth states and JSON Web Tokens.

If you are debugging an authorization token rather than raw strings, you can inspect Base64URL headers and claims inside a JWT directly.

Comparing Base64 vs hex size overhead

Grouping 6 bits per character (4 characters per 3 bytes) produces a 33% size expansion. Hexadecimal (Base16) encodes only 4 bits per character (2 characters per 1 byte), doubling payload size with a 100% overhead.

Encoding format Alphabet characters Padding Size overhead Common use case
Standard alphabet (RFC 4648 §4) A-Z, a-z, 0-9, +, / = ~33% Email MIME, JSON fields, data: URLs
URL-safe alphabet (RFC 4648 §5) A-Z, a-z, 0-9, -, _ Optional (stripped) ~33% JWT segments, URL params, filenames
Hex / Base16 (RFC 4648 §8) 0-9, a-f None 100% SHA-256 hashes, raw byte dumps
UTF-8 Plain Text Variable 1–4 bytes per char None 0% Source text before encoding

Encoding files to data URLs and decoding Base64 to file downloads

Developers often convert small icons into inline stylesheets or recover attached PDFs and images from API logs. The file pipeline supports both directions cleanly in browser memory without touching an external server.

Creating RFC 2397 data URLs up to 25 MB

In Encode mode, Encode a file… accepts any local file up to 25,000,000 bytes (25 MB) and displays the exact byte expansion alongside Copy and Download (.b64.txt). Checking As a data: URL prepends data:<mime-type>;base64, and forces the standard alphabet (+, /, =) as required by the IETF RFC 2397 Data URL Scheme.

For responsive UI icons, you can minify SVG markup before embedding it as a data URL so the inline string stays as small as possible. Output previews truncate visually at 2,000,000 characters to keep the browser responsive while Copy and Download always export the complete string.

Tip: Avoid embedding multi-megabyte photos as data: URLs in production CSS or HTML. Text encoding adds 33% overhead and prevents browsers from caching the image separately from the stylesheet.

Magic-byte sniffing for decoded PNG, JPG, and PDF files

In Decode mode, binary payloads that fail UTF-8 text validation trigger a 12-byte magic-number check. The decoder recognizes PNG (89504e47), JPG (ffd8ff), GIF (GIF8), WebP (RIFF...WEBP), PDF (%PDF), ZIP (504b0304), and GZIP (1f8b), rendering a live preview for images and enabling Save decoded file with the matching extension.

When no known signature matches, the panel still lets you save the raw bytes as decoded.bin so custom binary blobs, protocol buffers, or compiled assets remain recoverable.

Why Base64 is encoding, not encryption, for secrets and manifests

Text encoding makes binary data safe for text-only protocols like JSON, email, and YAML, but it provides zero confidentiality. Anyone who intercepts an encoded string can reverse it instantly with no password or cryptographic key.

Client-side execution for API tokens and Kubernetes secrets

Because Kubernetes Secret manifests and HTTP Basic authorization headers store encoded credentials, pasting them into server-hosted converters risks leaking production keys into third-party logs. Running every calculation inside your browser tab ensures secrets never cross the network, and you can prepare YAML configuration manifests without uploading secrets in the same local workspace.

Strict UTF-8 validation on decoded output

When decoding text, the tool applies new TextDecoder("utf-8", { fatal: true }) in accordance with the MDN Web Docs TextDecoder API. Rather than silently replacing corrupted bytes with replacement characters, strict validation flags non-UTF-8 payloads immediately and routes them to the binary file download panel.

Large text inputs also offload automatically to a background Web Worker when supported, keeping typing and pasting responsive even on multi-megabyte payloads.

Questions

Does Base64 encrypt or protect sensitive data?

No. It is a reversible text encoding, not encryption, and anyone can decode an encoded string back to its original bytes without a key. Always pair this transport format with HTTPS or real encryption when handling secrets.

What is the difference between standard and URL-safe Base64?

The standard alphabet uses + and / with = padding, which can break query parameters and file paths. The URL-safe variant replaces + with - and / with _, and strips trailing = characters so strings travel safely in URLs and JWT segments.

Why does browser btoa() fail on accents and emoji?

JavaScript's built-in btoa() function only accepts single-byte Latin-1 code points and throws an InvalidCharacterError on multi-byte Unicode characters. This tool converts text to UTF-8 bytes with TextEncoder first, so accents and emoji encode cleanly.

Why is Base64 output roughly 33 percent larger than the original file?

This 6-bit scheme maps every 3 binary bytes (24 bits) into 4 printable ASCII characters. That 4-to-3 ratio adds approximately 33% overhead, plus up to two = padding characters when the input length is not divisible by three.

What happens when you decode Base64 containing an image or PDF?

When decoded bytes are not valid UTF-8 text, the tool inspects the first 12 bytes for known magic signatures including PNG, JPG, GIF, WebP, PDF, ZIP, and GZIP. Images show an inline preview, and Save decoded file downloads the reconstructed binary.

Are files or API tokens uploaded to an external server during Base64 conversion?

No. All encoding, decoding, and file sniffing execute inside your browser tab and Web Worker memory. API keys, Kubernetes secrets, and private documents never leave your device.

Updated