X114

Base64 Encoder & Decoder

API coming soon

Encode and decode Base64 strings with UTF-8 safety, URL-safe mode, and MIME/PEM line formatting. 100% client-side.

Base64 Encoder & Decoder

Preset Samples:
Wrap:
30 chars · 36 bytes
(+33% byte expansion)
48 chars · 48 bytes
UTF-8 Safe • RFC 4648 Compliant

API version coming soon

Get notified when the Base64 Encoder & Decoder API is available.

About

Base64 is the foundational binary-to-text encoding scheme standardized across modern internet protocols, web applications, and software engineering. It is designed to represent arbitrary binary sequences, byte arrays, and text payloads using a safe, universally transportable 64-character ASCII alphabet. Base64 is ubiquitous in everyday developer workflows: embedding inline images via Data URIs, transmitting HTTP Basic Authentication credentials, parsing JSON Web Tokens (JWT), formatting PEM cryptographic certificates, and routing binary blobs across legacy text-only channels.

Our Base64 Encoder & Decoder provides a high-performance, UTF-8 compliant translation workbench running 100% locally in your browser. Unlike traditional browser utilities that break on multibyte Unicode characters, our engine handles emoji, Asian CJK glyphs, and European accented letters with strict binary accuracy.


RFC 4648 Technical Specifications & Mathematics

  • Governing RFCs: Complies with IETF RFC 4648 (The Base16, Base32, and Base64 Data Encodings) and RFC 2045 (MIME Part One: Format of Internet Message Bodies).
  • Mathematical Bit Partitioning: Base64 takes groups of 24 bits (3 bytes of 8 bits each) and splits them into 4 groups of 6 bits each (2^6 = 64 unique indices). Each 6-bit index maps directly to a character in the Base64 alphabet table.
  • The +33.33% Byte Expansion Overhead: Because 3 raw bytes expand into 4 ASCII characters, Base64 transmission always incurs a deterministic 33.33% data size overhead (4/3 = 1.333).
  • Deterministic Padding (=): When input data is not divisible by 3 bytes, padding characters (=) are appended. If 1 byte remains, 2 padding characters (==) are appended; if 2 bytes remain, 1 padding character (=) is appended.
  • URL-Safe Base64 (RFC 4648 §5): Standard Base64 uses + and /, which conflict with URL query strings and URI paths. The URL-Safe variant substitutes - for + and _ for /, stripping trailing = padding characters for friction-free routing in web tokens and filenames.

Binary-to-Text Encodings: Architectural Comparison

Encoding Scheme Alphabet Size Bits per Char Byte Size Overhead URL / Filename Safe Standard Specification Primary Industry Use Cases
Standard Base64 64 characters 6 bits +33.33% No (contains +, /, =) RFC 4648 §4 / RFC 2045 HTTP Basic Auth, email attachments (MIME), Data URIs, PEM keys
URL-Safe Base64 64 characters 6 bits +33.33% Yes (uses -, _, no =) RFC 4648 §5 JSON Web Tokens (JWT), OAuth 2.0 PKCE, WebAuthn credentials
Base32 32 characters 5 bits +60.00% Yes (case-insensitive) RFC 4648 §6 2FA / TOTP Authenticator keys (Google Authenticator), Tor Onion URLs
Hex (Base16) 16 characters 4 bits +100.00% (2x) Yes RFC 4648 §8 SHA-256 / MD5 hash digests, MAC addresses, color hex codes
Ascii85 (Base85) 85 characters ~6.4 bits +25.00% No RFC 1924 / Adobe PDF compression streams, PostScript files, Git binary diffs

Developer Implementation Code Snippets

Integrate UTF-8 safe and URL-safe Base64 routines directly into your software:

1. JavaScript / TypeScript (Modern Web & Node.js)

export function toBase64(str: string, urlSafe = false): string {
  const bytes = new TextEncoder().encode(str);
  let bin = '';
  for (let i = 0; i < bytes.length; i++) bin += String.fromCharCode(bytes[i]);
  let b64 = btoa(bin);
  if (urlSafe) &#123;
    b64 = b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
  &#125;
  return b64;
&#125;

export function fromBase64(b64: string): string &#123;
  let clean = b64.replace(/\s+/g, '').replace(/-/g, '+').replace(/_/g, '/');
  while (clean.length % 4) clean += '=';
  const bin = atob(clean);
  const bytes = new Uint8Array(bin.length);
  for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
  return new TextDecoder('utf-8').decode(bytes);
&#125;

2. Python 3

import base64

def encode_payload(text: str, url_safe: bool = False) -> str:
    raw_bytes = text.encode("utf-8")
    if url_safe:
        return base64.urlsafe_b64encode(raw_bytes).decode("ascii").rstrip("=")
    return base64.b64encode(raw_bytes).decode("ascii")

def decode_payload(b64_str: str) -> str:
    padded = b64_str + "=" * ((4 - len(b64_str) % 4) % 4)
    return base64.urlsafe_b64decode(padded.encode("ascii")).decode("utf-8")

FAQ