Base64 Encoder & Decoder

Encode text to Base64 or decode Base64 back to text. Supports URL-safe encoding for use in URLs and filenames.

About Base64

Base64 encodes binary data as ASCII text. Common uses include embedding images in CSS/HTML, encoding email attachments, and transmitting binary data in JSON. URL-safe Base64 replaces + with - and / with _ to avoid URL encoding issues.

What is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters. It’s commonly used when binary data needs to be transmitted over text-based protocols like email or HTTP, or stored in text formats like JSON or XML.

The name “Base64” comes from the 64 characters used in the encoding: A-Z, a-z, 0-9, plus two additional characters (typically + and /, with = for padding).

When to use Base64

Data URIs - Embed images directly in HTML or CSS:

<img src="data:image/png;base64,iVBORw0KGgo..." />

Email attachments - MIME encoding uses Base64 for binary attachments in email.

API payloads - Safely include binary data in JSON:

{
  "file": "SGVsbG8gV29ybGQ=",
  "filename": "hello.txt"
}

Basic authentication - HTTP Basic Auth encodes credentials as Base64:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

Standard vs URL-safe Base64

Standard Base64 uses + and / characters, which have special meaning in URLs. URL-safe Base64 replaces these:

  • + becomes -
  • / becomes _

Use URL-safe encoding when:

  • Including Base64 in URL parameters
  • Using Base64 as filenames
  • Storing in systems that treat + or / specially

Base64 is not encryption

Base64 is an encoding, not encryption. Anyone can decode a Base64 string - it provides no security. Never use Base64 to “hide” sensitive data. For actual security, use proper encryption like AES.

// This is NOT secure
const "hidden" = btoa("password123"); // cGFzc3dvcmQxMjM=
// Anyone can decode it
atob("cGFzc3dvcmQxMjM="); // "password123"

Base64 in JavaScript

Encoding:

// Simple ASCII
btoa("Hello World"); // "SGVsbG8gV29ybGQ="

// UTF-8 characters need special handling
const utf8 = new TextEncoder().encode("Hello 世界");
const base64 = btoa(String.fromCharCode(...utf8));

Decoding:

// Simple ASCII
atob("SGVsbG8gV29ybGQ="); // "Hello World"

// UTF-8
const bytes = Uint8Array.from(atob(base64), c => c.charCodeAt(0));
const text = new TextDecoder().decode(bytes);

Size overhead

Base64 increases data size by approximately 33%. Every 3 bytes of input become 4 characters of output. This is important when:

  • Embedding large images as data URIs
  • Sending files via JSON APIs
  • Working with bandwidth-limited connections

How this tool works

Enter text to encode it as Base64, or paste a Base64 string to decode it. Toggle URL-safe mode for encoding that’s safe to use in URLs. This tool handles UTF-8 characters correctly. Powered by a QuantCDN Edge Function.