Base64 Encoder & Decoder

100% Client-Side Instant Result

Your results will appear here.

Ready to run.
Verified

About this tool

What Is Base64 Encoding?

Base64 encoding is a binary-to-text conversion scheme that translates binary data into a safe ASCII string format using exactly 64 printable characters: A-Z, a-z, 0-9, plus (+), and forward slash (/). This encoding method was standardized in RFC 4648 and is widely used in web development, email protocols (MIME), and data transmission across text-only channels.

Base64 is not encryption. It provides no cryptographic security whatsoever. Anyone with access to a Base64 decoder can reverse the encoding instantly. Its purpose is purely to safely transport binary data through systems designed exclusively for text. Common applications include embedding images directly into CSS as Data URIs, transmitting binary file attachments over SMTP email, encoding authentication credentials in HTTP Basic Auth headers, and serializing binary blobs for storage in JSON or XML documents. The encoding alphabet of 64 characters was chosen specifically because 64 equals 2 to the 6th power, meaning each Base64 character represents exactly 6 bits of binary data.

How Base64 Encoding Works: The Algorithm Step by Step

Understanding the internal mechanics of Base64 helps developers debug encoding issues and optimize data transmission. The algorithm follows a strict mathematical process defined in RFC 4648:

Step 1: Convert to Binary. Each character in the input string is converted to its 8-bit binary ASCII representation. For example, the letter "A" becomes 01000001, "B" becomes 01000010, and "C" becomes 01000011.

Step 2: Group Into 24-Bit Blocks. The binary stream is divided into groups of 24 bits (three 8-bit bytes). The 24-bit block for "ABC" would be: 010000010100001001000011.

Step 3: Split Into 6-Bit Segments. Each 24-bit block is split into four 6-bit segments. Our example becomes: 010000 | 010100 | 001001 | 000011, which equals decimal values 16, 20, 9, and 3.

Step 4: Map to Base64 Characters. Each 6-bit value maps to a character in the Base64 alphabet index table. Values 16, 20, 9, 3 map to Q, U, J, D respectively. So "ABC" encodes to "QUJD".

Step 5: Handle Padding. If the input byte count is not divisible by 3, padding characters (=) are appended. One remaining byte produces two Base64 characters plus "==". Two remaining bytes produce three Base64 characters plus "=". This ensures the output length is always a multiple of 4.

The 33.3% Size Overhead: Why Base64 Makes Data Larger

A critical technical detail that developers must understand is that Base64 encoding always increases data size by approximately 33.3%. This happens because the algorithm converts every 3 bytes of input (24 bits) into 4 bytes of output (32 bits). The ratio is 4/3 = 1.333, meaning a 33.3% increase.

For practical applications, a 1 MB image encoded as a Base64 Data URI will consume approximately 1.33 MB. This overhead matters significantly for performance-critical applications. Embedding large images as Data URIs in CSS files can actually harm Core Web Vitals by increasing stylesheet parse time and blocking First Contentful Paint. The best practice is to use Base64 Data URIs only for small assets under 10 KB, such as icons, logos, or SVG graphics. Larger assets should use standard HTTP-served files with proper caching headers.

Data URIs, Email Attachments, and API Payloads: Real-World Applications

Scenario 1: Frontend Developer Creating Data URIs. A web developer needs to embed a small PNG icon directly into CSS to eliminate an HTTP request. They encode the image binary to Base64, prepend the MIME type header data:image/png;base64, and paste the result into their CSS background-image property. This eliminates a network round-trip and improves LCP for small icons.

Scenario 2: Backend Developer Debugging API Authentication. An API returns a 401 Unauthorized error despite sending credentials. The developer suspects the Basic Auth header is malformed. They decode the Base64 portion of the Authorization header to inspect the username:password string and discover a special character causing the failure.

Scenario 3: Security Analyst Inspecting JWT Tokens. A penetration tester intercepts a session cookie containing a JWT. They paste the token into the JWT decoder to extract the payload, revealing user roles, permissions, and expiration timestamps. This helps identify privilege escalation vulnerabilities without needing a dedicated JWT analysis tool.

Scenario 4: Email Engineer Troubleshooting MIME. An email arrives with a corrupted attachment. The engineer extracts the Base64-encoded attachment data from the raw MIME source, decodes it, and compares byte counts to identify where truncation occurred during transmission.

Scenario 5: Student Learning Encoding Concepts. A computer science student studying the RFC 4648 specification uses this tool to verify their manual Base64 calculations. They encode simple strings, compare the output to their hand-computed results, and build an intuitive understanding of 6-bit grouping and padding mechanics.

Common Mistakes and How to Avoid Them

Developers frequently encounter preventable Base64 errors:

Mistake 1: Confusing Encoding with Encryption. Base64 provides zero security. Never use it to protect passwords, API secrets, or personally identifiable information. Anyone can decode it instantly.

Mistake 2: Ignoring UTF-8 Compatibility. JavaScript built-in btoa() only accepts Latin-1 characters. Passing a string containing emojis, Chinese characters, or Arabic text throws an InvalidCharacterError. Always preprocess with encodeURIComponent() before encoding.

Mistake 3: Missing or Extra Padding. A valid Base64 string length must be divisible by 4. Extra whitespace, missing padding characters (=), or line breaks injected by email servers will cause decoding failures.

Mistake 4: Using Standard Base64 in URLs. The standard Base64 alphabet includes + and / characters, which conflict with URL parameter syntax. Use Base64url encoding (replacing + with - and / with _) when embedding encoded data in query strings or URL paths.

Mistake 5: Encoding Large Files as Data URIs. While technically possible, encoding images larger than 10 KB as Data URIs harms page performance by increasing CSS file size and blocking rendering. Use regular image files with CDN caching for anything beyond small icons.

Base64 Encoder vs. Alternatives: Comparison

Several encoding schemes serve similar purposes. Here is how they compare:

| Feature | Base64 | Hex Encoding | URL Encoding | ASCII85 |
|---|---|---|---|---|
| Size Overhead | 33.3% | 100% | Variable | 25% |
| Character Set | A-Z, a-z, 0-9, +, // | 0-9, A-F | Original + %XX | 33-117 ASCII |
| URL Safe | No (needs Base64url) | Yes | Yes | No |
| Primary Use | Binary data transport | Debugging, hashes | URL parameters | PostScript, PDF |
| Human Readable | No | Partial | Mostly yes | No |
| Browser Support | Native btoa/atob | toString(16) | encodeURIComponent | Requires library |

Base64 strikes the best balance between size efficiency and universal compatibility. Hex encoding doubles the data size, making it impractical for large payloads. URL encoding only transforms special characters, leaving most of the string readable. ASCII85 achieves better compression (25% overhead vs 33.3%) but lacks native browser support.

Advanced Tips for Power Users

Base64url Variant: When working with JWTs or URL-embedded data, use the Base64url alphabet (RFC 4648 Section 5) which replaces + with - and / with _ to avoid URL parsing conflicts. Most JWT libraries handle this automatically.

Multiline Base64: MIME-encoded email attachments split Base64 output into 76-character lines per RFC 2045. When decoding such data, strip all line breaks and carriage returns before passing the string to atob().

Streaming Large Files: For files larger than a few megabytes, consider chunked encoding to avoid memory exhaustion. Process the file in segments, encode each chunk separately, and concatenate the results.

Data URI MIME Types: When creating Data URIs, always specify the correct MIME type. Common formats include data:image/png;base64, data:image/svg+xml;base64, data:application/pdf;base64, and data:text/plain;base64.

Advertisement

Practical Usage Examples

Encoding a JSON API Payload

A developer encodes a JSON object for safe transmission through an HTTP header.

Input: {"user":"admin","role":"editor"} → Output: eyJ1c2VyIjoiYWRtaW4iLCJyb2xlIjoiZWRpdG9yIn0=

Decoding an HTTP Basic Auth Header

A developer debugs authentication by decoding the Base64 credentials from an Authorization header.

Input: YWRtaW46cGFzc3dvcmQxMjM= → Output: admin:password123

Inspecting a JWT Token Payload

A security analyst extracts user claims from a JSON Web Token.

Input: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo0Miwicm9sZSI6ImFkbWluIn0.signature → Output: {"user_id":42,"role":"admin"}

Step-by-Step Instructions

Step 1: Choose Your Conversion Mode. Select whether you want to encode plain text into Base64, decode an existing Base64 string back to readable text, or extract the payload from a JSON Web Token (JWT). Each mode is optimized for its specific use case.

Step 2: Paste Your Input Data. Enter your text string or Base64-encoded data into the input field. For JWT decoding, paste the complete token in the format header.payload.signature. The tool accepts any UTF-8 characters including emojis, non-Latin scripts, and special symbols.

Step 3: Click Calculate to Convert. The conversion executes entirely in your browser using native JavaScript functions with UTF-8 safety wrappers. No data is sent to any external server during processing, making it safe for sensitive API keys, tokens, or proprietary data.

Step 4: Review the Results and Byte Analysis. The output shows your converted string along with a byte-size comparison. For encoding, you will see the expected 33.3% size increase. For decoding, the tool reveals the original data size compression.

Step 5: Copy the Output. Use the copy button to grab your converted string. For JWT tokens, the payload is automatically formatted as pretty-printed JSON for easier reading and debugging.

Core Benefits

Complete Client-Side Privacy: Unlike server-based converters that upload your data, this Base64 encoder processes everything locally in your browser. Your API keys, tokens, and sensitive strings never leave your device.

Full UTF-8 Character Support: Standard JavaScript btoa() and atob() functions crash on wide characters like emojis or non-Latin scripts. This tool uses URI-component buffering to handle any Unicode character set safely without encoding errors.

Built-In JWT Token Decoder: Developers can paste an entire JSON Web Token and the tool automatically extracts and decodes the Base64url-encoded payload segment, converting it to readable JSON with proper formatting.

Instant Size Analysis: Every conversion includes a byte-size comparison showing exactly how the encoding affected your data footprint, helping developers understand the 33.3% overhead inherent in Base64 encoding.

Zero Dependencies and No Account Required: No signup, no API keys, no downloads. The tool works instantly in any modern browser and remains functional even after the initial page load completes.

Frequently Asked Questions

Base64 encoding converts binary data into a text-safe ASCII format using 64 printable characters. It is used to embed images as Data URIs in CSS, encode email attachments in MIME format, transmit binary data through text-only protocols like HTTP headers, and serialize authentication credentials in HTTP Basic Auth. It is not encryption and provides no security.

No. Base64 is a reversible encoding scheme, not encryption. Anyone can decode a Base64 string without a key or password. It converts binary to text for safe transport, not for security. Never use Base64 alone to protect sensitive data like passwords or API secrets. Use proper encryption algorithms like AES-256 for data protection.

Base64 converts every 3 bytes of input into 4 bytes of output because it maps 8-bit binary groups into 6-bit segments. The ratio 4 divided by 3 equals 1.333, resulting in a 33.3% size increase. This overhead is unavoidable and means a 1 MB file becomes approximately 1.33 MB after encoding.

This error occurs when the input contains invalid Base64 characters or the string length is not a multiple of 4. Common causes include whitespace, line breaks, or non-Latin characters in the input. Strip all whitespace before decoding, ensure proper padding with equals signs (=), and verify the string only contains valid Base64 alphabet characters: A-Z, a-z, 0-9, +, and /.

Yes. This tool includes a dedicated JWT decoder mode. Paste the complete token in header.payload.signature format, and the tool automatically extracts and decodes the Base64url-encoded payload, displaying it as formatted JSON. The decoding happens entirely in your browser, so your token data remains private.

Yes, from a privacy perspective. This tool processes all data entirely in your browser using client-side JavaScript. No data is uploaded to any server, making it safe for API keys, authentication tokens, and proprietary information. However, remember that Base64 itself is not encryption and should not be your sole data protection mechanism.

Standard Base64 uses the characters + and / which conflict with URL syntax. Base64url (defined in RFC 4648 Section 5) replaces + with - and / with _ to make encoded strings URL-safe. JWT tokens use Base64url encoding by default. This tool automatically handles Base64url conversion when decoding JWT tokens.

Once the page has fully loaded in your browser, the encoding and decoding functions are cached locally. You can disconnect from the internet and continue converting Base64 strings because all processing uses native JavaScript btoa() and atob() functions that require no network connectivity.

Standard btoa() only accepts Latin-1 characters. To encode Unicode text including emojis, Arabic, Chinese, or other scripts, the input must first be processed through encodeURIComponent() to convert multi-byte characters into percent-encoded sequences. This tool handles this conversion automatically, preventing the common InvalidCharacterError.

The equals sign is a padding character. Base64 output must be a multiple of 4 characters in length. If the input binary data does not divide evenly into 24-bit groups, one or two padding characters are appended. One = means the last group had 2 input bytes, and == means it had 1 input byte. Removing padding breaks decoding in strict parsers.

Related tools

View all tools