UtilsDaily

Base64 Encoder / Decoder

Convert text to Base64 format or decode Base64 strings back to readable text instantly.

What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 printable ASCII characters. It was designed to safely transmit binary data over communication channels that only support text, such as email (SMTP) and early web protocols.

The name "Base64" comes from the 64-character alphabet used: uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and two special characters (+ and /). The equals sign (=) is used for padding when the input length is not divisible by 3.

How Does Base64 Encoding Work?

Base64 encoding converts binary data into text through a systematic process:

  1. Group bytes: Take the input data and split it into groups of 3 bytes (24 bits).
  2. Split into 6-bit chunks: Divide each 24-bit group into four 6-bit segments.
  3. Map to characters: Convert each 6-bit value (0-63) to its corresponding Base64 character.
  4. Add padding: If the final group has fewer than 3 bytes, pad with "=" characters.

The Base64 Alphabet

Standard Base64 (RFC 4648):
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

Index mapping: A=0, B=1, C=2, ... Z=25, a=26, ... z=51, 0=52, ... 9=61, +=62, /=63

Each character represents a 6-bit value (2^6 = 64 possible values). Since 3 bytes (24 bits) map to 4 Base64 characters (4 x 6 = 24 bits), the encoded output is always approximately 33% larger than the input.

Size Increase Formula

Encoded Size = ceil(Input Size / 3) × 4

Example: 100 bytes input → ceil(100/3) × 4 = 34 × 4 = 136 characters output

Benefits of Using Base64

  • Universal compatibility: Base64 text can be safely transmitted through any text-based protocol without data corruption.
  • No special characters: The output contains only alphanumeric characters and +/=, avoiding issues with special character handling.
  • Embedding binary in text: Images, PDFs, and other binary files can be embedded directly in HTML, CSS, JSON, or XML documents.
  • Email attachments: MIME encoding uses Base64 to safely attach binary files to emails.
  • Data URIs: Embed small images directly in web pages using data:image/png;base64,... syntax.

Important Security Warning

Base64 is NOT encryption!
Base64 encoding can be reversed by anyone. It provides no security or privacy protection. Never use Base64 alone to store passwords, API keys, or sensitive information. For security, use proper encryption algorithms like AES or hashing functions like SHA-256.

Common Use Cases

  • Data URIs: Embedding small images (under 10KB) directly in HTML/CSS to reduce HTTP requests.
  • Email attachments: MIME standard uses Base64 for binary attachments in emails.
  • JSON/XML APIs: Transmitting binary data (images, files) through text-based APIs.
  • HTTP Basic Authentication: Encoding username:password pairs in Authorization headers.
  • JWT tokens: JSON Web Tokens use Base64URL encoding for header and payload sections.
  • Certificates: PEM format uses Base64 to encode X.509 certificates and keys.

Frequently Asked Questions

What is the difference between Base64 and Base64URL?

Standard Base64 uses + and / characters, which have special meanings in URLs. Base64URL replaces + with - and / with _ to make the output URL-safe without percent encoding. This variant is used in JWTs and other URL-embedded data.

Why does Base64 increase file size by 33%?

Base64 converts 3 bytes (24 bits) of binary data into 4 characters (4 × 6 = 24 bits). This 4/3 ratio means the output is always 33.33% larger than the input. Additionally, padding characters may add 1-2 extra bytes.

Can Base64 handle Unicode and emojis?

Yes, but with proper UTF-8 encoding first. This tool automatically converts Unicode text to UTF-8 bytes before Base64 encoding, ensuring full support for international characters, emojis, and special symbols.

Is Base64 encoding reversible?

Yes, Base64 is completely reversible. Any valid Base64 string can be decoded back to its original binary data. This is why it should never be used for security purposes - it provides obfuscation, not protection.

What causes "Invalid Base64 string" errors?

This error occurs when the input contains characters outside the Base64 alphabet (not A-Z, a-z, 0-9, +, /, =), has incorrect padding, or has an invalid length. Whitespace and line breaks can also cause issues in some decoders.

Should I use Base64 for storing images?

For small images (icons under 10KB), Base64 data URIs can reduce HTTP requests. For larger images, external files with proper caching are more efficient since Base64 increases size by 33% and cannot be cached separately.