Back to Utilities

Base64 Encoder / Decoder

Encode and decode binary and text strings to and from Base64 with URL-safe support.

Advertisement
Settings

What this tool does

Base64 is a binary-to-text encoding scheme that represents arbitrary byte sequences using a restricted set of 64 ASCII characters (A-Z, a-z, 0-9, +, /). It is widely used to embed binary data in JSON, XML, and email, transmit files over text-only protocols, and store complex data in URL parameters. This tool encodes text and binary to Base64 and decodes Base64 back to its original form, with an option to use the URL-safe variant that replaces + and / with - and _.

The encoder operates on the byte representation of your input, so any text encoding (UTF-8, Latin-1, etc.) is preserved correctly during the round-trip. The URL-safe variant is essential for embedding Base64 in query strings or filenames, since the standard alphabet contains characters that have special meaning in URLs.

Usage Example

// Standard Base64
btoa("Hello, World!")  // "SGVsbG8sIFdvcmxkIQ=="

// URL-safe Base64 (no padding)
"hello+world/?".replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")
// "hello-world_"

// Round-trip in Node.js
const original = "résumé.json";
const encoded = Buffer.from(original, "utf-8").toString("base64");
// "csOpc3VtLmpxb24="
const decoded = Buffer.from(encoded, "base64").toString("utf-8");
// "résumé.json"

Common Edge Cases

  • Base64 is not encryption. Anyone with the encoded string can decode it, so never use it to hide secrets like API keys or passwords.
  • The standard alphabet uses + and /, which must be percent-encoded in URLs. Use the URL-safe variant (with - and _) for query parameters.
  • Padding with = characters is optional and typically stripped in URL-safe encodings. Decoders must reconstruct the padding before decoding.
  • Input length grows by approximately 33% when encoded, so a 1 MB binary file becomes about 1.33 MB of Base64 text.
  • Decoding invalid Base64 (wrong padding, illegal characters, or truncated input) throws an error. Always validate input before decoding.

FAQ

Is Base64 the same as encryption?
No. Base64 is an encoding, not encryption. It provides no security and is trivially reversible. Use a real encryption algorithm (AES-256-GCM, ChaCha20-Poly1305) for sensitive data.
Why is there padding (= characters) at the end?
Base64 groups input bytes into 6-bit chunks. When the input length is not divisible by 3, one or two = characters pad the output to a multiple of 4 characters.
Can I encode an image to Base64?
Yes, but the result will be about 33% larger than the original binary. For most use cases, hosting the image and referencing its URL is more efficient than embedding the Base64 in your HTML or CSS.
Advertisement