Base64 Encoder - Encode Text to Base64 Online Free
Encode text to Base64 in Standard, URL-safe, MIME, and Data URI formats. Auto-detects text type. Free, no signup.
What Is Base64 Encoding?
Base64 encoding is a method of converting binary data or text into a safe ASCII string representation using a character set of 64 printable characters: uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), plus (+), and forward slash (/). An equals sign (=) is used as padding at the end of the encoded string when the input length is not a multiple of 3 bytes.
Base64 encoding works by taking every 3 bytes of input data and converting them into 4 ASCII characters. Each group of 6 bits from the input is mapped to one of the 64 characters in the Base64 alphabet. This process is fully reversible — anyone can decode a Base64 string back to its original content without any key or password.
It is important to understand that Base64 is not encryption. It provides no security, confidentiality, or integrity. It is simply an encoding scheme designed to represent binary data as text, making it safe to transmit through text-based systems like email, URLs, HTTP headers, and configuration files.
The Four Base64 Output Formats
This tool provides four distinct Base64 output formats, each designed for specific use cases:
- Standard Base64 — The classic format using the character set A-Z, a-z, 0-9, +, / with = padding. This is the default output of PHP's
base64_encode()and is used in most general-purpose encoding scenarios including HTTP headers, JSON payloads, and data storage. - URL Safe Base64 (RFC 4648) — A variant that replaces the + and / characters with - (hyphen) and _ (underscore) respectively. This format is essential when embedding Base64 data in URLs, file names, or any context where the standard + and / characters would be misinterpreted or cause parsing errors. This is also the format used in JWT (JSON Web Token) signatures.
- MIME Base64 (76-character line breaks) — Follows the RFC 2045 standard for email transmission. The encoded output is split into lines of 76 characters each, which is required by the MIME specification for encoding binary attachments in email messages. If you are sending binary data via email or SMTP, use this format.
- Data URI — Wraps the Base64-encoded content in a
data:URI scheme (e.g.,data:image/png;base64,iVBOR...). This allows you to embed images, fonts, scripts, and other small files directly inline in HTML, CSS, or JavaScript, reducing HTTP requests and improving initial page load performance.
How Base64 Encoding Works
Base64 encoding operates on the principle of converting 3 bytes (24 bits) of binary data into 4 characters of ASCII text. Here is the step-by-step process:
- Group bytes in threes — The input data is processed in chunks of 3 bytes. Each chunk produces 4 Base64 characters.
- Split into 6-bit groups — The 24 bits from 3 bytes are divided into four 6-bit segments. Each 6-bit value (0–63) maps to one character in the Base64 alphabet.
- Map to characters — Each 6-bit value is mapped to A-Z (0–25), a-z (26–51), 0–9 (52–61), + (62), or / (63).
- Add padding — If the final group has fewer than 3 bytes, equals signs (=) are appended to pad the output to a multiple of 4 characters.
The tool also auto-detects the type of your input text and labels the output accordingly. It identifies Plain Text, JSON, XML, HTML, CSV, URLs, and email addresses, giving you insight into what you are encoding.
When Should You Use Base64 Encoding?
Base64 encoding is essential in several common scenarios:
- Email attachments — Email was designed to transmit text only. Binary files (images, PDFs, documents) must be Base64-encoded before inclusion in MIME-formatted email messages. Use the MIME format with 76-character line breaks for email compatibility.
- Data URIs for inline embedding — Embed small images, fonts, icons, and scripts directly in HTML or CSS using
data:URIs. This eliminates extra HTTP requests and can improve initial page load times for small assets. - HTTP Basic Authentication — The
Authorization: Basicheader in HTTP requests contains the Base64-encoded representation of the username:password pair. This is the standard authentication method for many REST APIs and web services. - URL parameters — When binary data or data containing special characters must be passed through a URL query string, Base64 encoding ensures it remains URL-safe (especially when using the URL Safe format).
- JWT tokens — JSON Web Tokens use Base64URL encoding (RFC 4648 URL Safe variant) for the header, payload, and signature segments.
- Data storage and transfer — Store binary data as ASCII text in databases, configuration files, and text-based systems that do not support raw binary input.
Standard Base64 vs URL Safe Base64
The two most commonly used Base64 variants differ in their character sets:
- Standard Base64 uses
+and/as the 62nd and 63rd characters. These characters have special meaning in URLs (+ is a space delimiter, / is a path separator) and file systems, making Standard Base64 unsuitable for URL parameters or file names. - URL Safe Base64 (RFC 4648) replaces
+with-(hyphen) and/with_(underscore). These characters are safe in URLs and file names, making this format the correct choice for URL parameters, file names, and JWT tokens.
Always check which format your target system expects. Using Standard Base64 in a URL will break the URL structure because the + and / characters will be misinterpreted by the URL parser.
How MIME Base64 Differs from Standard
The MIME variant of Base64 follows the RFC 2045 standard and adds line breaks every 76 characters. This is required for email transmission because:
- Many email systems and SMTP servers impose line length limits on message headers and bodies.
- The MIME standard mandates a maximum line length of 76 characters for Base64-encoded content parts.
- Without line breaks, encoded email content may be truncated or corrupted by intermediate mail servers.
Use MIME format when encoding data for email attachments. Use Standard or URL Safe format for all other use cases.
Data URIs: Embedding Base64 in HTML and CSS
A Data URI wraps Base64-encoded content in a data: scheme, allowing you to embed files directly in your HTML, CSS, or JavaScript without external file requests. The format is:
data:[mediatype];base64,[encoded-data]
For example, to embed a small PNG image inline:
<img src="data:image/png;base64,iVBORw0KGgo..." alt="icon">
Data URIs are ideal for small assets like icons, logos, and fonts. However, because Base64 increases data size by approximately 33%, avoid using Data URIs for large files like full-size photographs or video clips.
Common Use Cases in Web Development
- Embedding images in CSS — Use Data URIs to embed small background images and icons directly in CSS files, eliminating extra HTTP requests.
- SVG icons in HTML — Encode SVG files as Base64 Data URIs to embed them inline, avoiding CORS and caching issues.
- API authentication headers — Encode credentials as Base64 for HTTP Basic Authentication when calling protected REST API endpoints.
- JWT token generation — Sign and encode JWT tokens using Base64URL for header and payload segments in authentication systems.
- Email via SMTP — Encode binary attachments (PDFs, images, documents) as MIME Base64 before sending via email protocols.
- Configuration files — Store binary secrets, certificates, or keys as Base64 strings in JSON, YAML, or XML configuration files.
Base64 Encoding vs URL Encoding
These two encoding schemes serve different purposes and should not be confused:
- Base64 encodes entire blocks of data into a safe ASCII character set. It converts 3 bytes into 4 characters and is used for embedding and transmitting binary data.
- URL encoding (percent-encoding) encodes individual characters that are unsafe or reserved in URLs. A space becomes
%20and an ampersand becomes%26. It is used for URL query parameters and path segments.
Use Base64 when you need to represent binary data as text. Use URL encoding when you need to safely include special characters in URLs.
How to Use This Tool
- Enter your text — Paste or type any text into the input textarea. The tool auto-detects the text type (Plain Text, JSON, XML, HTML, CSV, URL, Email).
- Click Encode — The tool encodes your text to Base64 using PHP's
base64_encode()function and detects the text type. - Choose output format — Select Standard, URL Safe, MIME, or Data URI depending on your use case.
- Copy or Download — Use the Copy button to copy the result to your clipboard, or click Download to save it as a text file.
Need to hash your data instead? Try our MD5 Generator for computing checksums of your text and files.
Related Tools
- URL Encode — Encode and decode URLs with special characters to percent-encoded format.
- MD5 Generator — Generate MD5 hash values for text and data integrity verification.
Privacy and Security
Base64 encoding is performed entirely on our servers using PHP's native base64_encode() function. We do not store your input or encoded output. The tool processes your data in memory and discards it immediately after returning the result. No cookies, tracking scripts, or analytics collect your encoded data.
Base64 encoding increases data size by approximately 33%. For every 3 bytes of input, 4 bytes of Base64 output are produced. When encoding large data, consider the impact on bandwidth and storage. Also note that Base64 is encoding, not encryption — it provides no security or confidentiality.
AI Overview
Base64 encoding is a method of converting binary data or text into a printable ASCII string representation using a character set of 64 characters: A-Z, a-z, 0-9, plus (+), and forward slash (/). An equals sign (=) is used as padding at the end of the encoded string. Base64 is not encryption; it is a reversible encoding scheme designed to safely represent binary data in text-based systems like email, URLs, and configuration files.
Quick Answers
What is Base64 encoding?
A:Base64 encoding converts binary data or text into a safe ASCII string format using 64 printable characters. It is commonly used to transmit data over media that handle text, such as email and URLs.
Is Base64 encoding secure?
A:No. Base64 is an encoding scheme, not encryption. Anyone can decode Base64 without a key. It is not suitable for protecting sensitive data.
How much larger is Base64 compared to the original?
A:Base64 encoding increases data size by approximately 33%. For every 3 bytes of input, 4 bytes of Base64 output are produced.
How to Use the Base64 Encoder - Encode Text to Base64 Online Free
- Paste or type any text into the input textarea. This can be plain text, JSON, XML, HTML, CSV, a URL, or an email address. The tool automatically detects the text type.
- Click the Encode button to convert your text into Base64 using PHP's base64_encode() function. The tool also detects and labels the text type in the output.
- Select from four output formats: Standard Base64, URL Safe (RFC 4648), MIME with 76-character line breaks, or Data URI for embedding in HTML and CSS.
Benefits
- 100% Free, No Registration
- Instant Encoding
- Four Output Formats
- Auto Text Detection
- Character Count and Size
- Copy and Download
Common Mistakes
- Confusing Base64 with encryption — Base64 is an encoding, not encryption. Anyone can decode it without a key
- Using Standard Base64 in URLs without URL-safe encoding, causing padding characters (+ and /) to break the URL
- Forgetting that Base64 increases data size by approximately 33%, which matters when encoding large payloads
- Embedding Base64 directly in HTML without considering the 33% size increase on page load performance
- Mixing up URL-safe Base64 (uses - and _) with Standard Base64 (uses + and /) in different contexts
Professional Tips
- Use URL-safe Base64 (RFC 4648) when encoding data that will be placed in URLs or file names to avoid issues with special characters
- Use the MIME format when encoding data for email attachments, as it follows the 76-character line width required by RFC 2045
- Use the Data URI format to embed small images, fonts, or scripts directly in HTML or CSS to reduce HTTP requests
- Strip Base64 padding characters (=) when using the encoding in JWT tokens or URL parameters
- Always verify decoded output matches the original input, especially with multi-byte UTF-8 characters
Common Use Cases
Email Attachments
Encode binary file contents as Base64 for embedding in MIME-formatted email messages and attachments.
Data URIs
Embed images, fonts, and small files directly in HTML or CSS using data: URIs to reduce HTTP requests and improve load times.
API Authentication
Encode username and password pairs for HTTP Basic Authentication headers used in REST API calls.
URL Parameters
Encode binary or special-character data to safely pass it through URL query parameters without breaking the URL structure.
Web Development
Encode configuration data, SVG icons, or small assets for embedding in JavaScript, JSON, or CSS files.
Data Storage
Store binary data as ASCII text in databases and text-based systems that do not support raw binary input.
Related Concepts
Base64
A binary-to-text encoding scheme that represents binary data using a set of 64 ASCII characters (A-Z, a-z, 0-9, +, /).
RFC 4648
The Internet standard that defines the Base64, Base32, and Base16 encoding schemes, including the URL-safe variant.
Data URI Scheme
A URI scheme (data:) that allows inline embedding of small files directly in HTML, CSS, or JavaScript using Base64-encoded content.
MIME (RFC 2045)
The standard for email message formatting that uses Base64 encoding for binary content transfers with 76-character line limits.
HTTP Basic Authentication
An authentication scheme that encodes username:password as Base64 and sends it in the Authorization header of HTTP requests.
JWT (JSON Web Token)
A compact token format that uses Base64URL encoding for its header and payload segments, commonly used for API authentication.
Frequently Asked Questions
References
Popular Related Tools
Most Used Tools in Web Tools
More Web Tools
Explore our complete collection of web tools.