Base64 Encoder — Text, File & Data URI Encoding Tool
Encode and decode UTF-8 text, JSON payloads, images, and binary files using RFC 4648 standard or URL-safe Base64url with instant Data URI output and live byte-expansion metrics, 100% client-side.
Hello World!Ready locally via WebAssembly & JavaScript
SGVsbG8gV29ybGQh100% Client-Side • Zero Server Upload
Base64 is a binary-to-text encoding scheme standardized in RFC 4648 that maps arbitrary 8-bit binary octets onto a safe 64-character subset of US-ASCII. Whenever raw bytes—images, cryptographic digests, TLS certificates, or multi-byte UTF-8 strings—must pass through text-only transport layers such as JSON strings, XML elements, HTTP headers, YAML manifests, or SMTP MIME messages, Base64 guarantees that non-printable control bytes (0x00–0x1F) and high-bit octets (0x80–0xFF) survive without truncation or character-set corruption. Running this encoder directly in your browser ensures credentials, private keys, and internal payloads never leave local memory.
Bitwise Mechanics: The 24-Bit Quantum and Modulo-3 Padding
Computers store raw data in 8-bit octets (256 possible byte values), whereas Base64 encodes 6 bits per printable symbol (64 possible values: A–Z for 0–25, a–z for 26–51, 0–9 for 52–61, plus two dialect-dependent symbols for 62 and 63). Because the least common multiple of 8 and 6 is 24, the encoder reads the input stream in contiguous 3-byte (24-bit) quanta and splits each quantum into four 6-bit sextets.
Encoding the 3-byte ASCII string "Man" demonstrates exact alignment with zero padding:
| Pipeline Stage | Byte / Sextet Breakdown | Resulting Values |
|---|---|---|
| 1. Input Characters | M, a, n | Decimal 77, 97, 110 (0x4D 0x61 0x6E) |
| 2. 8-Bit Octet Stream | 01001101 01100001 01101110 | 24 contiguous bits |
| 3. Regroup Into 6-Bit Sextets | 010011 010110 000101 101110 | 4 six-bit groups |
| 4. Sextet Decimal Indices | 19, 22, 5, 46 | Lookup range 0–63 |
| 5. RFC 4648 Alphabet Output | T, W, F, u | Encoded string: TWFu |
When the input byte length n is not divisible by 3, the final 24-bit quantum is incomplete. The encoder appends zero bits on the right to finish the final active 6-bit group, then appends = pad characters in Standard Base64 so the total output length remains a multiple of 4:
n mod 3 == 0: Complete 24-bit block produces 4 Base64 characters and no=padding.n mod 3 == 1: 1 trailing byte (8 bits) receives 4 trailing zero bits to form 2 sextets (2 characters), followed by==.n mod 3 == 2: 2 trailing bytes (16 bits) receive 2 trailing zero bits to form 3 sextets (3 characters), followed by=.
Under RFC 4648 Section 3.5 (Canonical Encoding), those trailing pad bits must always remain zero so two distinct Base64 strings can never silently decode to identical bytes—an important security check in signed tokens and deduplicated hashes. For any input of n bytes, standard padded output length is 4 * ceil(n / 3) bytes, whereas unpadded Base64url length is ceil(4 * n / 3) bytes—converging to a 33.33% size overhead before gzip or Brotli transport compression.
RFC 4648 Variants and Protocol Specifications
Although developers frequently refer to "Base64" as a single format, four active RFC profiles differ in alphabet characters, padding rules, and line wrapping:
| Variant | Standard | Index 62 | Index 63 | Padding (=) | Line Wrapping | Primary Protocol Uses |
|---|---|---|---|---|---|---|
| Standard Base64 | RFC 4648 §4 | + | / | Required | None | Data URIs, HTTP Basic Auth, Kubernetes Secrets, JSON binary fields |
| URL-Safe Base64url | RFC 4648 §5 | - | _ | Optional / Omitted | None | JWT segments, OAuth 2.0 PKCE code_challenge, URL query tokens |
| MIME Base64 | RFC 2045 | + | / | Required | CRLF every 76 chars | SMTP email attachments and Content-Transfer-Encoding: base64 |
| PEM Base64 | RFC 7468 | + | / | Required | LF every 64 chars | X.509 TLS certificates, PKCS#8 keys, SSH key blocks |
When decoding, this tool automatically normalizes - back to +, _ back to /, strips embedded whitespace/line breaks from MIME or PEM blocks, and restores omitted = padding before converting octets back into UTF-8 text.
Avoiding UTF-8 btoa() Errors and Shell Newline Traps
Two classic implementation bugs cause hours of authentication and signature debugging in production codebases:
- JavaScript
window.btoa()Unicode Failure: Nativebtoa()maps each UTF-16 code unit directly to a single byte and throwsInvalidCharacterErroron any character aboveU+00FF(such as"café ☕"or CJK text). Always serialize strings to UTF-8 bytes withTextEncoderfirst:
function toBase64Url(input) {
const bytes = new TextEncoder().encode(input);
let binary = "";
for (const b of bytes) binary += String.fromCharCode(b);
return btoa(binary)
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
}
- Trailing Newlines in CLI and Kubernetes Workflows: Running
echo "admin:secret" | base64appends a hidden\n(0x0A) byte before encoding, silently invalidating HTTP Basic Auth headers and KubernetesSecretdata:fields in GitOps manifests. Always useprintfwithout a trailing newline—and pass-w 0on GNU coreutils to suppress 76-character line wraps, emitting the exact tokenYWRtaW46c2VjcmV0:
printf '%s' 'admin:secret' | base64 -w 0
Data URI Thresholds and Security Boundaries
Dropping an image onto the upload panel generates an RFC 2397 Data URI (data:image/png;base64,...) ready for <img src="..."> tags or CSS url(...) rules. Inlining eliminates a network round-trip for critical icons under 4 KB, but larger assets pay a triple penalty: 33% raw payload inflation, lost independent HTTP caching across routes, and slower CSSOM parsing when embedded inside render-blocking stylesheets. Always benchmark bundled stylesheet weights before inlining vector sprites or raster thumbnails across multi-page web applications. For specialized image conversion and reverse extraction, use our Image to Base64 and Base64 to Image utilities.
Finally, remember that Base64 is encoding, never encryption. Any encoded payload can be inspected instantaneously with our Base64 Decoder. To inspect signed Base64url claims, open our JWT Decoder; to escape special URI characters without 33% bloat, switch to our URL Encoder; and when you need genuine cryptographic integrity or one-way digests, pair your workflow with our HMAC Generator or Hash Generator.
How to Use Base64 Encoder — Text, File & Data URI Encoding Tool
Select Encode or Decode in the top toolbar, or click Paste to let the tool detect an existing Base64 string and switch modes automatically.
Enter UTF-8 text, JSON, or credentials into the left Monaco editor, or drag and drop an image or binary file onto the upload zone.
Enable the URL-Safe switch whenever the encoded string will be embedded inside a URL query parameter, route segment, filename, or JWT.
Check the live character and UTF-8 byte counters to verify exact expansion overhead, and preview generated Data URIs for uploaded images.
Click Copy or Download to export the encoded string, or press Swap to feed the output back into the input pane for round-trip verification.
Real Examples
Standard Text Encode
Encoding a simple English string.
Hello World!SGVsbG8gV29ybGQhUnicode & Emoji Encode
Properly handling UTF-8 emojis and special characters.
I ❤️ Web Dev!SSDimqQgV2ViIERldiE=JSON Payload Encode
Encoding a JSON object for API transport.
{"user":"admin","role":"superuser"}eyJ1c2VyIjoiYWRtaW4iLCJyb2xlIjoic3VwZXJ1c2VyIn0=Frequently Asked Questions
Why does Base64 encoding expand payload size by roughly 33.3%?
What changes when you switch from Standard Base64 (RFC 4648 Section 4) to URL-Safe Base64url (Section 5)?
Why does native JavaScript btoa() fail on emojis and non-ASCII text, and how does this tool prevent that?
Is Base64 encoding a form of encryption or a safe way to hide API keys and passwords?
When should you inline an image as an RFC 2397 Data URI instead of serving an external file?
Key Features
- Bidirectional RFC 4648 Section 4 (Standard) and Section 5 (URL-Safe Base64url without '=' padding) encoding and decoding with one-click mode swap
- Strict UTF-8 byte serialization via TextEncoder and fatal UTF-8 decoding via TextDecoder, preventing btoa() errors on CJK characters, accents, and emojis
- Drag-and-drop image and binary file encoding that automatically emits RFC 2397 Data URIs with MIME type detection and instant image previews
- Smart clipboard paste detection that recognizes valid Base64 payloads and switches directly into Decode mode
- Live input and output statistics tracking character count, line count, and exact UTF-8 byte delta to quantify 4:3 encoding overhead
- Monaco editor with automatic dark/light theme support, local draft persistence, file download, and 100% offline client-side execution
Common Use Cases
- Building HTTP Basic Authentication headers (Authorization: Basic base64(username:password)) from UTF-8 credentials without shell newline bugs
- Generating unpadded Base64url segments for JSON Web Token (JWT) headers, OAuth 2.0 PKCE code challenges, and URL-safe state parameters
- Inlining small PNG, WebP, or SVG icons as RFC 2397 Data URIs inside CSS stylesheets, standalone HTML emails, or component bundles
- Encoding PEM TLS certificates, service-account JSON credentials, and configuration blobs for Kubernetes Secret YAML manifests
- Embedding binary signatures, PDF buffers, or encrypted ciphertexts safely inside JSON REST APIs and GraphQL string fields
- Performing round-trip verification on webhook payloads and log tokens by toggling between Encode and Decode modes in one click
Related Tools
Explore More Tools in This Category
View All Developer & Utility ToolsBase64 Decode Tool
Decode standard RFC 4648 and URL-safe Base64 strings into readable UTF-8 text, formatted JSON, or downloadable images with automatic magic-byte sniffing directly inside your browser.
URL Encoder & Decoder Tool
Percent-encode full URIs, individual query parameters, and multi-byte UTF-8 text using RFC 3986 and JavaScript encodeURI/encodeURIComponent rules with an interactive query string builder.
URL Decoder Tool
Unescape percent-encoded URLs and query strings back into readable UTF-8 text, inspect and edit key-value parameters visually, and diagnose malformed or double-encoded sequences locally in your browser.
JWT Decoder Tool
Inspect JSON Web Tokens locally in real time. Decode Base64url headers and payload claims, evaluate Unix exp/iat/nbf timelines, and flag risky signing algorithms without sending tokens over the network.
Hash Generator Tool
Compute MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA3-256, and SHA3-512 cryptographic digests simultaneously for text or local files directly inside your browser.
MD5 Generator Tool
Compute 128-bit MD5 checksums for UTF-8 strings and large local files with 2 MB chunked browser streaming, live hash verification, and zero server uploads.
SHA256 Generator Tool
Generate FIPS 180-4 SHA-256 digests for text and local files entirely in your browser using hardware-accelerated Web Crypto APIs, hybrid chunked streaming, and instant hash comparison.
Advanced Password Generator
Generate cryptographically secure passwords, memorable word hybrids, and Diceware passphrases completely offline with live entropy analysis, character-pool filters, and local QR handoff.