Advanced Base64 Encoder & Decoder 2025

Free online Base64 encoder and decoder tool with advanced features. Convert text, files, and images to/from Base64 with our unlimited, secure, and feature-rich converter. Supports URL-safe encoding, custom character sets, and data URI generation. Perfect for developers working with APIs, web development, and data encoding.

Encoding Options
Select the character encoding for input/output text
Choose between standard or URL-safe encoding (replaces + with - and / with _)
Whether to include padding characters (=) at the end
Add line breaks to make the Base64 output more readable
Advanced Options
View the output in different formats
Remove leading and trailing whitespace from input
Remove characters that are not valid in Base64 encoding when decoding
Automatically detect if input is Base64 encoded
Input Text
0 characters, 0 bytes
Output
0 characters, 0 bytes
File Options
Choose between standard or URL-safe encoding for files
Whether to include padding characters (=) at the end
Add line breaks to make the Base64 output more readable
Include data: MIME type prefix in the output
Drop files here or click to upload
Max file size: 100MB
Image Base64 Tools
Format when converting to Base64 (auto-detect will use original format)
Include data:image/[format];base64, prefix
Optimize image size before converting (may reduce quality)
Drop an image here or click to upload
Supported formats: JPG, PNG, GIF, WebP, SVG
Base64 Validator

Validate if a string is properly Base64 encoded and get detailed information about the content.

Base64 Input to Validate
0 characters, 0 bytes
Data URI Generator

Generate Data URIs for embedding resources directly in HTML, CSS, or JavaScript files.

The MIME type of the resource
How the data should be encoded in the URI
Include charset=utf-8 in the Data URI (for text types)
Drop a file here or click to upload
The file will be converted to a Data URI
OR Enter Text Directly
Text Input
0 characters, 0 bytes

Example Base64 Conversions

Text to Base64:
// Original Text Hello, World! // Base64 Encoded SGVsbG8sIFdvcmxkIQ== // JavaScript Implementation btoa("Hello, World!"); // Encode atob("SGVsbG8sIFdvcmxkIQ=="); // Decode
Image Data URI:
// Data URI Format for Images data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA... // Using in HTML <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA..." alt="Image" /> // Using in CSS .logo { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...); }

Common Uses for Base64 Encoding

Embedding Images in CSS/HTML

Reduce HTTP requests by embedding small images directly into your HTML or CSS files using data URIs, improving page load performance.

Email Attachments

Base64 is used in email systems to encode binary attachments into text for transmission through systems that only support ASCII characters.

API Authentication

OAuth tokens, API keys, and authentication headers often use Base64 encoding for transmitting credentials over HTTP.

Data Storage

Storing binary data in systems that only support text, such as JSON documents, XML files, or certain database fields.

How to Use Base64 Encoding

1

Choose Your Input Type

Select whether you want to encode text, a file, or an image. For text encoding, enter your text in the input field. For files or images, use the upload area to select your file.

2

Configure Encoding Options

Select the appropriate options for your needs: character encoding (UTF-8, ASCII, etc.), Base64 variant (standard, URL-safe, or MIME), padding preference, and line break settings.

3

Process the Conversion

Click the "Encode to Base64" button to convert your input to Base64, or "Decode from Base64" to convert Base64 back to its original form. For files, use the specific file encoding or decoding buttons.

4

Use the Result

Copy the output to your clipboard, download it as a file, or view it directly in the browser. For images, you can see a preview of the encoded or decoded result.

Frequently Asked Questions about Base64 Encoding

What is Base64 encoding?

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format by translating it into a radix-64 representation. It's commonly used when binary data needs to be stored or transferred over media that are designed to handle text.

The term "Base64" comes from the specific set of 64 characters chosen from the ASCII character set: A-Z, a-z, 0-9, +, and /. The = character is used for padding when the input length is not divisible by 3.

Base64 encoding increases the data size by approximately 33% compared to the original binary data (specifically, the size increases by a factor of 4/3).

What's the difference between standard and URL-safe Base64?

Standard Base64 uses the character set [A-Za-z0-9+/] with = for padding. However, the + and / characters have special meanings in URLs and might cause issues when Base64 strings are used in URLs.

URL-safe Base64 (also known as base64url) replaces + with - and / with _ to make the encoded string safe to use in URLs without additional encoding. This variant is defined in RFC 4648.

For example, the standard Base64 string "a+b/c==" would be encoded as "a-b_c==" in URL-safe Base64.

Why are there = characters at the end of Base64 strings?

The equals sign (=) at the end of a Base64-encoded string is used for padding. Since Base64 encodes 3 bytes of binary data into 4 ASCII characters, the input length must be a multiple of 3 bytes.

When the input length is not a multiple of 3, padding characters (=) are added to make the encoded output length a multiple of 4. This ensures that the encoded data can be properly decoded.

The number of padding characters can be 0, 1, or 2, depending on how many bytes are missing from a complete 3-byte group:

  • No padding (=) when the input length is divisible by 3
  • One padding character (=) when the input length mod 3 = 2
  • Two padding characters (==) when the input length mod 3 = 1

Some Base64 implementations omit the padding characters (called "no-padding" or "padding-optional" Base64), but this can sometimes cause ambiguity during decoding.

How do I use Base64 encoded images in HTML and CSS?

Base64 encoded images can be embedded directly in HTML using the data URI scheme. This is particularly useful for small images where you want to reduce HTTP requests.

To use a Base64 encoded image in HTML:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." alt="Description" />

To use a Base64 encoded image in CSS:

.element {
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...);
}

The format for the data URI is:

data:[<MIME-type>][;charset=<encoding>][;base64],<data>

Keep in mind that Base64 encoding increases the size of the image by approximately 33%, so it's best used for small images. For larger images, a regular URL reference to an external image file is usually more efficient.

How do I handle Base64 encoding with non-ASCII characters?

When encoding text with non-ASCII characters (like emoji, accented characters, or non-Latin scripts), you need to first convert the text to a binary representation using a character encoding like UTF-8 before applying Base64 encoding.

In JavaScript, the built-in btoa() function only works with ASCII characters. For handling Unicode strings, you need to first convert the string to a UTF-8 encoded binary format:

// Encode Unicode string to Base64
function encodeBase64(str) {
  // Convert the string to UTF-8 bytes
  const utf8Bytes = new TextEncoder().encode(str);
  // Convert bytes to a binary string
  const binaryStr = Array.from(utf8Bytes).map(byte => String.fromCharCode(byte)).join('');
  // Encode binary string to Base64
  return btoa(binaryStr);
}

// Decode Base64 to Unicode string
function decodeBase64(base64) {
  // Decode Base64 to binary string
  const binaryStr = atob(base64);
  // Convert binary string to UTF-8 bytes
  const utf8Bytes = new Uint8Array(binaryStr.length);
  for (let i = 0; i < binaryStr.length; i++) {
    utf8Bytes[i] = binaryStr.charCodeAt(i);
  }
  // Decode UTF-8 bytes to string
  return new TextDecoder().decode(utf8Bytes);
}

Our Base64 converter tool automatically handles this encoding/decoding process for you when you select UTF-8 as the character encoding.

Is there a size limit for Base64 encoding?

Theoretically, there is no fixed size limit for Base64 encoding itself. However, there are practical limitations when working with Base64 encoded data:

  • Browser limitations: Browsers may have limits on the length of URLs (important when using Base64 in query parameters) or on the size of data URIs.
  • Memory constraints: Very large Base64 strings can consume significant memory when processed.
  • Performance concerns: Encoding or decoding very large files can be slow and might freeze the browser's UI thread.

Our tool has implemented optimizations to handle files up to 100MB efficiently, including:

  • Chunked processing for large files
  • Web Workers for handling encoding/decoding operations off the main thread
  • Streaming for file downloads to reduce memory usage

For extremely large files (over 100MB), it's generally better to use a dedicated file format or binary transfer protocol rather than Base64 encoding.

Understanding Base64 Encoding

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It's part of the larger family of similar binary-to-text encoding schemes that encode binary data by treating it numerically and translating it into a base-64 representation.

How Base64 Works

Base64 works by taking three bytes (24 bits) of binary data and dividing it into four 6-bit groups. Each 6-bit group is translated to one of 64 printable ASCII characters using a specific table:

  • Characters 0-25: 'A' to 'Z'
  • Characters 26-51: 'a' to 'z'
  • Characters 52-61: '0' to '9'
  • Character 62: '+' (or '-' in URL-safe variant)
  • Character 63: '/' (or '_' in URL-safe variant)
  • Padding character: '='

Encoding Process

  1. Break the input into 3-byte (24-bit) chunks
  2. Divide each chunk into four 6-bit pieces
  3. Map each 6-bit piece to a character in the Base64 alphabet
  4. If the last chunk is less than 3 bytes, add padding ('=') characters to make the output length a multiple of 4

Common Uses of Base64

  • Email Attachments: Used in MIME to encode binary files for email transmission
  • Data URIs: Embedding images and other resources directly in HTML, CSS, or JavaScript
  • API Communication: Encoding binary data in JSON or XML documents
  • Authentication: Encoding usernames and passwords for Basic Authentication
  • Cryptography: Representing cryptographic keys, certificates, and signatures
  • Data Storage: Storing binary data in text-based systems like databases

Advantages of Base64

  • Text-Based: Allows binary data to be transmitted through text-only channels
  • Character Set Safety: Uses only printable ASCII characters, avoiding control characters
  • Standardization: Widely implemented and recognized across different platforms
  • Padding: The padding mechanism ensures proper decoding of data

Disadvantages of Base64

  • Size Increase: Base64 encoded data is about 33% larger than the original binary data
  • Processing Overhead: Requires computational resources for encoding and decoding
  • URL Safety: Standard Base64 includes characters that need additional encoding in URLs
  • Readability: Not human-readable for most data types