All processing happens in your browser — no data is sent to any server
Plain Text
0 chars
Invalid Base64 — contains characters outside the Base64 alphabet.
Base64
0 chars
File Encoder

Drop any file here to encode as Base64

or

Base64 Output

What Is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters: A–Z, a–z, 0–9, +, and /. The name comes from the 64-character alphabet.

It was designed to safely transmit binary data (like images or executables) over channels that only handle plain text — such as email (MIME), HTTP headers, and JSON APIs. Base64 is an encoding, not encryption: anyone can decode it instantly.

Common Use Cases

🔑
API Tokens & Auth Headers
HTTP Basic Auth encodes username:password as Base64 in the Authorization header. Many API keys are Base64-encoded byte sequences.
🪙
JWT Tokens
JSON Web Tokens (JWTs) use URL-safe Base64 to encode the header, payload, and signature. The three parts are separated by dots.
🖼️
Data URIs (Inline Images)
CSS and HTML can embed images directly using data:image/png;base64,… — no separate HTTP request needed for small icons and logos.
📧
Email Attachments (MIME)
Email protocols (SMTP) are text-only. MIME encodes binary attachments as Base64 so they survive transmission through mail servers.
📦
JSON Payloads
APIs that need to include binary data (certificates, keys, file bytes) in a JSON body Base64-encode the binary into a string field.
🔒
Cryptographic Keys
PEM certificates and SSH public keys are Base64-encoded DER structures wrapped in -----BEGIN … ----- headers.

Standard vs. URL-safe Base64

Standard Base64 uses + and / as the 62nd and 63rd characters, and = for padding. These characters have special meaning in URLs, so URL-safe Base64 (RFC 4648 §5) swaps them:

  • +- (hyphen)
  • /_ (underscore)
  • = padding is omitted

URL-safe Base64 is used in JWTs, OAuth tokens, and any situation where the encoded string appears in a URL or filename.

How Base64 Works

Base64 groups input bytes into 3-byte chunks and converts each chunk into 4 Base64 characters (each representing 6 bits). This is why the output is always 4/3 ≈ 33% larger than the input.

When the input length is not a multiple of 3, one or two = padding characters are appended to keep the output length a multiple of 4.

How to Use Base64 in Code

JavaScript

// Encode (handles ASCII only — for Unicode use TextEncoder) const encoded = btoa('Hello, World!'); // "SGVsbG8sIFdvcmxkIQ==" // Decode const decoded = atob('SGVsbG8sIFdvcmxkIQ=='); // "Hello, World!" // Unicode-safe encode function encodeUnicode(str) { const bytes = new TextEncoder().encode(str); let binary = ''; bytes.forEach(b => binary += String.fromCharCode(b)); return btoa(binary); }

Python

import base64 # Encode encoded = base64.b64encode(b'Hello, World!').decode('utf-8') # 'SGVsbG8sIFdvcmxkIQ==' # Decode decoded = base64.b64decode('SGVsbG8sIFdvcmxkIQ==').decode('utf-8') # 'Hello, World!' # URL-safe variant url_encoded = base64.urlsafe_b64encode(b'Hello!').decode().rstrip('=')

PHP

// Encode $encoded = base64_encode('Hello, World!'); // 'SGVsbG8sIFdvcmxkIQ==' // Decode $decoded = base64_decode('SGVsbG8sIFdvcmxkIQ=='); // 'Hello, World!' // URL-safe encode $urlSafe = rtrim(strtr(base64_encode($data), '+/', '-_'), '=');

Command Line (Linux / macOS)

# Encode a string echo -n 'Hello, World!' | base64 # SGVsbG8sIFdvcmxkIQ== # Decode echo 'SGVsbG8sIFdvcmxkIQ==' | base64 --decode # Encode a file base64 image.png > image.b64