Skip to main content
The Base64 String Encode/Decode tool handles bidirectional conversion between plain text and Base64-encoded strings. It supports both standard Base64 encoding and URL-safe variants, with proper UTF-8 handling for international characters.

Features

  • Standard Base64 encoding (RFC 4648)
  • URL-safe Base64 encoding (RFC 4648 Section 5)
  • UTF-8 character support
  • Automatic padding handling
  • URL-safe character substitution (+-, /_)

Use Cases

API Authentication

Encode credentials for Basic Authentication headers

URL Parameters

Safely encode data for inclusion in URLs using URL-safe variant

Data Transmission

Encode binary-safe text for transmission over text-only protocols

Email Encoding

Encode non-ASCII characters in email headers (MIME)

Actions

Default (Encode)

Standard Base64 encoding with + and / characters:
hello world → aGVsbG8gd29ybGQ=

Decode

Decode Base64 back to plain text:
aGVsbG8gd29ybGQ= → hello world

URL-Safe Encode

Encode with URL-safe characters (no padding):
hello+world/test → aGVsbG8rd29ybGQvdGVzdA
URL-safe encoding replaces + with -, / with _, and removes padding = characters.

Input Formats

Plain Text

Any UTF-8 text including international characters:
Hello, 世界! 🌍

Base64 String (for decoding)

Standard or URL-safe Base64:
aGVsbG8gd29ybGQ=
aGVsbG8gd29ybGQ  (without padding)
aGVsbG8-d29ybGQ  (URL-safe)

Examples

Convert plain text to Base64.Input:
The quick brown fox jumps over the lazy dog
Output:
VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==

Implementation Details

From lib/tools/engine.ts:396-404:
case 'base64-string': {
  if (action === 'decode') {
    // Normalize URL-safe variants
    const normalized = input.trim().replaceAll('-', '+').replaceAll('_', '/');
    // Add padding if needed
    const padded = normalized + '='.repeat((4 - (normalized.length % 4)) % 4);
    return { output: decodeURIComponent(escape(atob(padded))) };
  }
  const encoded = btoa(unescape(encodeURIComponent(input)));
  return { output: action === 'encode-url-safe' 
    ? encoded.replaceAll('+', '-').replaceAll('/', '_').replaceAll(/=+$/g, '') 
    : encoded };
}

UTF-8 Handling

The tool uses a two-step encoding process for proper UTF-8 support:
  1. Encode: text → encodeURIComponent → unescape → btoa
  2. Decode: base64 → atob → escape → decodeURIComponent
This ensures multi-byte UTF-8 characters are correctly encoded.

Common Patterns

Basic Authentication Header

Encode credentials for HTTP Basic Auth:
const credentials = "username:password";
const encoded = btoa(credentials);
const header = `Authorization: Basic ${encoded}`;
// Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

URL-Safe Token

Create URL-safe tokens:
const token = "session_data_with+special/chars";
// Encode with URL-safe action
// Result: c2Vzc2lvbl9kYXRhX3dpdGgrc3BlY2lhbC9jaGFycw (no padding)

Data URLs

Base64 is commonly used in data URLs (see Base64 Image tool):
data:text/plain;base64,SGVsbG8gV29ybGQh

Padding Rules

Standard Base64: Always includes = padding to make length multiple of 4URL-Safe: Padding is optional and removed for cleaner URLs
Input LengthPadding
hello (5)aGVsbG8= (1 pad)
hello! (6)aGVsbG8h (no pad)
hello!! (7)aGVsbG8hIQ== (2 pads)

Error Handling

Invalid Base64 Input

If decoding fails, you’ll see:
Invalid character in base64 string

Common Issues

  • Missing padding: The decoder automatically adds padding
  • URL-safe characters: Automatically normalized during decode
  • Whitespace: Trimmed automatically
Base64 increases data size by approximately 33%. The encoded output will be larger than the input text.

Build docs developers (and LLMs) love