toolverse

Base64 Encoder

Encode text to Base64 online. Convert any string into a Base64-encoded representation for safe transmission or storage.

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using a restricted set of 64 printable ASCII characters. The character set consists of uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), plus (+), and forward slash (/). The equals sign (=) is used for padding when the input length is not a multiple of three bytes.

Base64 encoding is used whenever binary or non-ASCII data needs to be transmitted through a channel that only handles text safely. This includes JSON payloads, XML documents, email attachments (MIME), CSS data URIs, and URL parameters (using the URL-safe Base64URL variant). Our encoder converts any text input — including Unicode characters, emojis, and non-Latin scripts — into a valid Base64 string that can be safely embedded in any text-based format.

How It Works

The encoding process takes groups of three bytes (24 bits) from the input and divides them into four groups of six bits each. Each six-bit group maps to one of the 64 characters in the Base64 alphabet. When the input length is not a multiple of three, padding characters (=) are appended to make the output length a multiple of four.

Our encoder uses the browser's btoa() function with proper UTF-8 handling to ensure that all Unicode characters are encoded correctly. Standard btoa() only handles Latin-1 characters, so our tool applies an additional UTF-8 encoding step that correctly handles:

  • Accented characters (cafe, resume)
  • Emojis and other supplementary plane characters
  • CJK characters (Chinese, Japanese, Korean)
  • Cyrillic, Arabic, Hebrew, and other non-Latin scripts
  • Combining characters and diacritical marks

All encoding runs in the browser. Your text is never transmitted to any server.

Common Use Cases

1. Encoding Data for JSON API Payloads

When you need to include binary data (images, files, certificates) in a JSON API request, Base64 encoding converts the binary content into a string value that fits naturally into the JSON structure:

{
  "filename": "document.pdf",
  "content": "JVBERi0xLjQKJcfs..."
}

2. Creating Data URIs for CSS and HTML

Base64-encoded data URIs allow you to inline small images, fonts, or SVGs directly into CSS or HTML without separate HTTP requests:

.icon { background-image: url("data:image/svg+xml;base64,PHN2Zy4uLg=="); }

This technique eliminates a network round-trip for small assets, though it increases the payload size by approximately 33%.

3. Encoding Credentials for HTTP Basic Authentication

HTTP Basic Authentication encodes the username:password pair as a Base64 string in the Authorization header:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

Note that Base64 is encoding, not encryption. The credentials are trivially recoverable, so Basic Auth must always be used over HTTPS.

4. Safe Transmission of Non-ASCII Data

When transmitting text that contains special characters through systems that may not handle Unicode correctly (legacy email systems, certain database fields, log files), Base64 encoding provides a safe ASCII representation that can be decoded on the receiving end.

5. Embedding Assets in Source Code

Developers sometimes embed small images or binary resources as Base64 strings directly in source code, avoiding the need for separate asset files. This is common in testing, prototyping, and embedded systems.

Tips and Best Practices

  • Base64 is not encryption. Never use Base64 to "protect" sensitive data. It is trivially reversible by anyone who intercepts the encoded string. Use proper encryption (AES, RSA) for data that needs confidentiality.
  • Account for the size increase. Base64 encoding increases data size by approximately 33%. A 1 MB file becomes roughly 1.33 MB when Base64-encoded. For large file transfers, consider multipart/form-data instead.
  • Use Base64URL for URL parameters. Standard Base64 uses + and /, which have special meaning in URLs. If your encoded string will appear in a URL or filename, use the Base64URL variant which replaces + with - and / with _.
  • Do not store Base64 in databases. Storing Base64-encoded data in database columns wastes storage space and slows queries. Use native binary column types (BLOB, BYTEA) instead.
  • Be mindful of line breaks. Some Base64 implementations insert line breaks every 76 characters (MIME convention). Our encoder produces a single continuous string without line breaks, which is the standard for most modern applications.

FAQ

Does it support Unicode and special characters?

Yes. The encoder handles UTF-8 encoded text including emojis, accented characters, CJK scripts, and all other Unicode characters. The encoding process properly converts multi-byte UTF-8 sequences into the correct Base64 representation.

Is Base64 encryption?

No. Base64 is encoding, not encryption. It transforms data into a different representation that is trivially reversible. Anyone can decode a Base64 string with a single function call. Never use Base64 as a substitute for encryption.

Can I encode files?

Currently, the tool accepts text input. For encoding binary files, you would need to read the file as a byte array and encode it programmatically. File upload support is planned for a future update.

Is my data private?

Yes. All encoding runs entirely in your browser using JavaScript. Your text is never sent to any server, logged, or stored. You can encode sensitive data with confidence.

How much does Base64 increase the size of my data?

Base64 encoding increases data size by approximately 33%. Every 3 bytes of input becomes 4 bytes of output. For a 100-character string, the Base64 output will be approximately 133-136 characters (depending on padding).

What is the difference between Base64 and Base64URL?

Standard Base64 uses + and / characters, which can cause issues in URLs and filenames. Base64URL replaces + with - and / with _, and may omit trailing = padding. Use Base64URL when the encoded string will appear in URLs, JWT tokens, or filenames.

Why is my encoded output different from another tool?

Different Base64 implementations may produce slightly different output due to padding conventions (with or without trailing =), line break insertion (MIME-style 76-character lines), or character encoding assumptions. Our encoder produces standard padded Base64 without line breaks using UTF-8 character encoding.