⚠️ JavaScript is required to use Black Claaw Tools. Please enable it in your browser settings.
Skip to main content

Base64 Encoder & Decoder

Instantly encode plain text into Base64 or decode Base64 back into readable text. Processed securely within your browser.

Input
0 Chars 0 B
Output
Ready
Out: 0 chars Size: 0 B

Advertisement

Text In, Safe Alphabet Out: What Base64 Actually Solves

Suppose you need to drop a configuration file, an SSH public key, or a multi line JSON snippet into an environment variable or an HTTP header. Raw newlines, quotes, backslashes, and non ASCII bytes break parsers quickly. Base64 exists to get raw bytes past systems that only trust plain printable text. Type Hello into the encoder above and it turns into SGVsbG8=. Every character in that output comes from a safe 64 symbol alphabet plus optional trailing equals signs.

This encoder and decoder runs entirely inside your browser using native UTF-8 text encoding and decoding APIs. You can switch between Encode and Decode, flip the result back into the input box with Swap, watch exact character and byte counts change live, or download the result as a plain text file without sending payloads to a remote server.

Inside the 64 Character Alphabet and Padding

Computers store bytes in chunks of 8 bits, giving 256 possible byte values from 0 to 255. Many early transport layers, including original SMTP email servers, could only forward 7 bit US ASCII reliably and stripped or mangled the highest bit. Base64 sidesteps that problem by grouping three 8 bit bytes together into a 24 bit block, then slicing that 24 bit block into four smaller 6 bit chunks.

Because six bits hold 64 possible values (from 0 to 63), each chunk maps directly to one safe ASCII character:

  • Indices 0 to 25 map to uppercase letters A through Z.
  • Indices 26 to 51 map to lowercase letters a through z.
  • Indices 52 to 61 map to digits 0 through 9.
  • Indices 62 and 63 map to + and / in standard Base64.

What happens if your input byte length is not divisible by three? Say you encode just one letter, M (1 byte, or 8 bits). The encoder pads the missing bits with zeros to fill two 6 bit groups (producing TQ), then appends two = padding characters (TQ==) so the decoder knows the output stops after one real byte rather than three. Two leftover bytes leave one = at the end, and any input divisible by three needs no padding at all.

That 3 bytes into 4 characters math explains why Base64 always expands data by roughly 33 percent. You can watch that exact expansion in the byte counters beneath both boxes on this page: a 300 byte note becomes roughly 400 bytes of Base64 text (ignoring line breaks).

Standard Base64 vs Base64URL

Standard Base64 (defined in RFC 4648 Section 4) works cleanly inside JSON strings and email bodies, yet causes headaches inside web addresses. In a URL query string, a + sign often decodes as a space, a / looks like a path separator, and trailing = signs conflict with parameter key and value boundaries.

To keep tokens safe inside links, JSON Web Tokens (JWTs), and OAuth callbacks, RFC 4648 Section 5 defines a URL safe variant called Base64URL. It keeps letters and digits identical, replaces + with - (hyphen), replaces / with _ (underscore), and usually strips trailing = padding.

Many strict decoders throw an error when handed a Base64URL token missing its padding. This tool's Decode mode normalizes whitespace, converts - and _ back to + and /, and restores any omitted = padding automatically. That means you can paste either standard Base64 payloads or raw Base64URL segments from a token header and read them right away. (If you want full header and claim inspection for tokens, our JWT Decoder splits all three token parts for you.)

The UTF-8 Trap in JavaScript

Developers who write quick Base64 helpers in browser code almost always hit the same bug. JavaScript's built in window.btoa() function predates modern Unicode handling and treats strings as raw single byte Latin1 characters. Pass an emoji, an Arabic word, a Japanese kanji, or even a curly quotation mark into plain btoa() and the browser immediately throws an InvalidCharacterError.

Going in the other direction with plain atob() causes silent corruption (often called mojibake): multi byte UTF-8 characters get decoded as separate garbage Latin1 symbols like é instead of é.

Fixing that requires converting text into a UTF-8 byte stream first via TextEncoder before Base64 encoding, and running decoded bytes back through TextDecoder('utf-8') on the way out. That is exactly how this page encodes and decodes input, so multi language text, accents, and emojis survive round trips cleanly without throwing browser exceptions.

Advertisement

Base64 Is Not Encryption

One mistake shows up again and again in production audits: treating Base64 as a way to hide passwords, API keys, or customer IDs. Base64 uses zero secret keys, zero salts, and zero randomness. Anyone who glances at a string ending in = or == can decode it in seconds, and automated scanners decode Base64 blocks inside client JavaScript bundles automatically.

Even HTTP Basic Authentication sends username:password encoded in plain Base64 inside the Authorization header. That header only stays safe when wrapped inside TLS (HTTPS) transport encryption. Never store Base64 encoded credentials in a database or embed Base64 encoded private keys inside frontend code assuming users cannot read them. Use proper one way password hashing for stored logins and real authenticated encryption when secrecy matters.

Fixing Common Decoding Errors

When a decoder throws an Invalid Base64 string error, three tiny copy mistakes account for almost every failure:

  1. Extra quotes or commas from JSON or logs: Copying a token inside JSON often grabs a trailing quotation mark or comma. Base64 only permits letters, digits, +, / (or - and _ in Base64URL), whitespace, and trailing = signs.
  2. Truncated strings: Every valid Base64 block represents groups of 4 characters, or 2 or 3 unpadded characters for the final incomplete group. A string whose stripped length leaves a remainder of 1 character when divided by 4 is mathematically impossible in Base64 and usually means characters were cut off at the start or end.
  3. Data URI prefixes left attached: If someone sends you data:text/plain;base64,SGVsbG8=, strip everything up to and including the comma before decoding, because the MIME prefix itself is not Base64 data.

Where Developers Use Base64 Every Day

Even with binary HTTP/2 framing and multipart uploads available everywhere, text safe Base64 payloads remain common across modern tools:

  • API file uploads inside JSON: JSON has no native binary type. APIs like GitHub's repository contents endpoint accept a Base64 string inside a JSON content field so you can create or update files with a single JSON request.
  • Kubernetes Secrets and configuration maps: Kubernetes stores secret keys as Base64 strings inside YAML manifests to preserve arbitrary bytes and newlines cleanly across YAML parsers (which is another case where Base64 handles formatting, not secrecy).
  • Small inline assets and Data URIs: Embedding tiny 1 KB SVG or PNG icons directly inside HTML or CSS avoids an extra network round trip, while larger images hurt load speed because of the 33 percent size overhead. If you need to convert an image file into a ready made Data URI, use the Image to Base64 converter rather than pasting raw binary text here.
  • Safe query strings vs Base64: If you only need to escape spaces, ampersands, and punctuation inside a short query parameter without inflating the string by a third, percent encoding via the URL Encoder and Decoder is usually cleaner than Base64.