In short: what does a Base64 encoder do?
A Base64 encoder converts binary data — text, images, files, tokens — into a string of 64 safe ASCII characters so it can travel through text-only channels like JSON, URLs and email. A Base64 decoder reverses the process. This tool also converts files to Base64 and back, builds Data URIs, decodes JWT tokens, translates between Base64, hex and binary, and analyzes any encoded string — all 100% in your browser, with nothing ever uploaded. Remember: Base64 is encoding, not encryption — it provides no security on its own.
Encode & decode
Text ↔ Base64 in standard, URL-safe and MIME variants — fully Unicode-safe.
File ↔ Base64
Convert images, PDFs and any binary, with live preview and one-click rebuild.
Data URI builder
Generate data: URIs plus ready-to-paste CSS and HTML snippets.
JWT decoder
Inspect token header, payload and claims with expiry checks — decode only.
Auto-detection
Recognizes JWTs, encoded JSON/XML, files, hex and binary automatically.
100% private
Everything runs in your browser. Your data is never uploaded.
What is Base64 encoding?
Base64 is a binary-to-text encoding scheme. Computers store everything — images, audio, documents, cryptographic keys — as raw bytes, where each byte can hold any of 256 possible values. Many of those values are not printable characters: they are control codes, null bytes or sequences that have special meaning to the systems that carry them. The moment you try to push raw binary through a channel that was designed for text — a JSON field, an HTTP header, a URL, the body of an email — those bytes get corrupted or rejected.
Base64 solves this by re-expressing arbitrary bytes using only 64 characters that every text system agrees on: the uppercase letters A–Z, the lowercase letters a–z, the digits 0–9, and the two symbols + and /. A = character is used for padding. Because every one of these symbols survives transport intact, any binary blob encoded with Base64 can be safely embedded inside text and decoded back to the exact original bytes on the other side.
The name itself is literal: the encoding is built on a base-64 positional system, just as hexadecimal is base-16 and decimal is base-10. Where one hex digit represents 4 bits, one Base64 character represents 6 bits, which is why 64 distinct symbols are needed (26 = 64). Base64 was standardized in RFC 4648, with the email-oriented MIME variant defined earlier in RFC 2045.
It is critical to understand what Base64 is not. It is not compression — encoded output is about a third larger than the input. It is not a checksum or hash — it is perfectly reversible. And, most importantly, it is not encryption: anyone can decode a Base64 string instantly without any key. Its single job is compatibility — making binary safe to handle as text.
How Base64 works, step by step
The algorithm is elegantly simple once you see the bit arithmetic. Base64 reads your data 3 bytes (24 bits) at a timeand re-slices those same 24 bits into four 6-bit groups. Each 6-bit group is a number from 0 to 63, which is used as an index into the 64-character alphabet to produce one output character. So every 3 input bytes become 4 output characters — the source of the famous “4/3” size ratio.
Consider encoding the three letters Cat:
- Bytes → bits.
C=67,a=97,t=116, giving the 24-bit stream01000011 01100001 01110100. - Regroup into 6-bit chunks.
010000 110110 000101 110100= the numbers 16, 54, 5, 52. - Map to the alphabet. 16→
Q, 54→2, 5→F, 52→0, producingQ2F0.
When the input length is not a multiple of 3, the final group is incomplete. The encoder pads the missing bits with zeros and appends = characters so the decoder knows how many real bytes to keep: one trailing byte → two =, two trailing bytes → one =. This is why valid padded Base64 always has a length that is a multiple of 4.
Here is the exact, Unicode-safe technique this tool uses in JavaScript:
// Encode (handles all of Unicode, not just ASCII)
const bytes = new TextEncoder().encode("Hello 世界");
const base64 = btoa(String.fromCharCode(...bytes));
// Decode back to text
const restored = new TextDecoder().decode(
Uint8Array.from(atob(base64), c => c.charCodeAt(0))
);The naive btoa("Hello 世界") throws a “character out of range” error because btoa only understands single-byte values. Encoding to UTF-8 bytes first — as above — is what makes emoji, accents and non-Latin scripts round-trip correctly.
Base64 vs binary, hex and URL encoding
Base64 is one of several ways to render bytes as text, and choosing the right one matters. The trade-off is always readability versus size. Here is how the common encodings compare for the same data:
| Encoding | Alphabet size | Chars per byte | Size overhead | Best for |
|---|---|---|---|---|
| Binary | 2 (0,1) | 8 | +700% | Teaching, bit-level debugging |
| Hexadecimal | 16 (0–f) | 2 | +100% | Hashes, colors, byte inspection |
| Base64 | 64 | ~1.33 | +33% | Embedding binary in text |
| URL encoding | varies | 1–3 per char | variable | Query strings & form data |
Binary is the most verbose: every byte becomes eight 0/1 characters. Hexadecimal halves that to two characters per byte and is wonderfully readable byte-by-byte, which is why hashes and color codes use it — but it still doubles the size. Base64 is the most compact text encoding in common use, adding only about a third, because it packs 6 bits into every character instead of hex’s 4. URL (percent) encoding is a different beast: it leaves safe characters untouched and only escapes the unsafe ones as %XX, so its overhead depends entirely on the content.
A practical rule: use hex when a human needs to read individual bytes (a SHA-256 digest, a MAC address), use Base64 when you need to embed binary compactly inside text (an image in JSON, a key in a config file), and use URL encoding for the textual parts of URLs. The Convert tab above translates between all of them instantly.
Base64 in APIs and web development
Base64 is everywhere in modern web development, precisely because APIs speak text. Whenever binary needs to ride inside a text protocol, Base64 is the bridge. The most common places you will meet it:
- HTTP Basic Authentication. The
Authorization: Basicheader is literallybase64(username:password)— which is exactly why Basic Auth must only ever be used over HTTPS, since the credentials are encoded, not encrypted. - JSON Web Tokens. Every JWT is three base64url segments joined by dots; the header and payload are decodable by anyone (see below).
- Binary in JSON payloads. Since JSON has no binary type, file contents, thumbnails, signatures and certificates are commonly transported as Base64 strings inside JSON fields.
- Data URIs. Inlining a small image or font into CSS/HTML uses
data:[mime];base64,…to avoid an extra request. - Email attachments. SMTP is a text protocol, so MIME encodes every attachment with Base64.
- Webhooks & message queues. Binary event payloads are frequently Base64-wrapped so they survive JSON serialization.
A word of engineering caution: because Base64 inflates payloads by a third and must be decoded entirely in memory, it is the wrong tool for large files. For anything beyond a few hundred kilobytes, prefer a multipart upload or a pre-signed URL that streams the bytes directly, and reserve Base64 for small, embedded assets and tokens.
The complete Data URI guide
A Data URI (or data URL) lets you embed a file directly inside source code as a single string, removing the need for a separate network request. The structure is straightforward:
data:[<media-type>][;base64],<data>
/* A real example — a tiny inline PNG used as a CSS background */
.icon {
background-image: url("data:image/png;base64,iVBORw0KGgoAAA...");
}Everything between data: and the comma is metadata: the MIME type (e.g. image/png, font/woff2,image/svg+xml) and the optional ;base64 flag indicating the payload is Base64-encoded. The Data URI tab above builds these for you and emits ready-to-paste CSS and <img> snippets.
When Data URIs help:
- Tiny, critical assets — inline SVG icons or 1×1 spacers load with zero extra round-trips.
- Self-contained files — a single HTML file with everything embedded, useful for emails and offline pages.
- Eliminating render-blocking requests — above-the-fold images that must appear instantly.
When to avoid them:
- Large assets — the 33% bloat and the inability to cache inlined data separately hurt performance.
- Frequently-changing files — any change forces the whole document to be re-downloaded.
- Many repeated assets — each inline copy is duplicated rather than shared from cache.
Decoding JWTs: header, payload and signature
A JSON Web Token (JWT) is the most visible application of URL-safe Base64. A JWT is three segments separated by dots — header.payload.signature — where the header and payload are base64url-encoded JSON and the signature is a cryptographic MAC or digital signature over the first two parts.
| Segment | Encoding | Contains |
|---|---|---|
| Header | base64url(JSON) | Algorithm (alg) and token type (typ) |
| Payload | base64url(JSON) | Claims: sub, iss, exp, iat, custom data |
| Signature | base64url(bytes) | HMAC/RSA/ECDSA over header.payload |
The single most important security fact about JWTs: the header and payload are encoded, not encrypted. Anyone who intercepts a token can Base64-decode the payload and read every claim — user IDs, roles, email addresses. Never put secrets in a JWT payload. The JWT tab above decodes both segments, lists each claim, and checks the exp / iat /nbf timestamps to tell you whether a token is expired.
What this tool deliberately does not do is verify the signature. Verification requires the signing secret or public key and proves that the token was issued by a trusted party and has not been tampered with. Decoding (what we do, safely and locally) only reveals the contents; it can never tell you a token is genuine. Always verify signatures server-side before trusting a token.
File encoding techniques
Encoding a file to Base64 follows the same byte-grouping algorithm — the encoder simply reads the file’s raw bytes rather than text. The File tab above reads your file entirely in the browser via the File and ArrayBuffer APIs, so nothing is uploaded. It detects the file type from its magic number (the signature bytes at the start of the file), shows a live preview for images, and reports the exact size overhead.
Common magic numbers the detector recognizes when reconstructing files from Base64:
| File type | First bytes (hex) | MIME |
|---|---|---|
| PNG | 89 50 4E 47 | image/png |
| JPEG | FF D8 FF | image/jpeg |
| GIF | 47 49 46 38 | image/gif |
| 25 50 44 46 | application/pdf | |
| ZIP / Office | 50 4B 03 04 | application/zip |
| MP3 | 49 44 33 | audio/mpeg |
Because encoding happens in memory, very large files can be slow or exceed browser limits. This tool handles files up to tens of megabytes comfortably; for multi-hundred-megabyte assets a streaming, server-side pipeline is the right architecture. When you decode Base64 back to a file, the original bytes are reconstructed exactly — Base64 is lossless — and the tool offers a download with the correct extension inferred from the signature.
Base64 security considerations
Base64 is not encryption and offers zero confidentiality. Encoding a password, API key or token in Base64 is exactly as secure as writing it in plain text — anyone can decode it in one click. Use Base64 only to transport data, and use real cryptography (AES, TLS, bcrypt/Argon2 for passwords) whenever security is the goal.
With that foundation, a few more practical security notes:
- HTTP Basic Auth needs HTTPS. Credentials are only Base64-encoded in the header, so without TLS they are effectively sent in the clear.
- Never store secrets in JWT payloads. They are world-readable once decoded. Keep secrets server-side.
- Validate decoded input. Decoding attacker-controlled Base64 can yield malicious payloads — treat decoded bytes as untrusted and validate them.
- Beware “double Base64” obfuscation. Malware sometimes Base64-encodes data several times to evade naive scanners; decoding repeatedly reveals the real payload.
- Prefer local tools for sensitive data. This encoder runs entirely in your browser, so confidential strings, internal tokens and regulated data never leave your device.
Base64 best practices
- Pick the right variant. Use standard Base64 in JSON and config; use URL-safe Base64 (
-/_, no padding) anywhere the value appears in a URL, path or JWT. - Always encode via UTF-8. Convert text to UTF-8 bytes before encoding so Unicode survives the round-trip; never feed raw multi-byte strings to
btoa. - Strip whitespace before decoding. Copy-pasted Base64 often carries stray newlines; tolerant decoders (like this one) ignore them, but strict parsers may not.
- Do not use Base64 for large files. The 33% overhead and in-memory parsing make it unsuitable above a few hundred KB — stream instead.
- Compress before encoding, not after. Gzip/Brotli on the wire recovers most of the Base64 overhead; compressing the encoded text yourself is far less effective.
- Validate length and padding. Padded Base64 length is always a multiple of 4 — a quick sanity check that catches truncation.
- Never rely on Base64 for security. It hides nothing. Encrypt or hash sensitive data with a real algorithm.
Frequently asked questions
43 answers about Base64 encoding, decoding, files, Data URIs and JWTs.
Base64 is a binary-to-text encoding scheme that represents arbitrary binary data using only 64 printable ASCII characters (A–Z, a–z, 0–9, plus “+” and “/”). It lets you safely move binary content — images, files, cryptographic keys — through channels that were designed for text, such as JSON, XML, email and URLs.
No. Base64 is encoding, not encryption. It provides zero confidentiality — anyone can decode a Base64 string instantly with no key. Never use Base64 to “hide” passwords, tokens or secrets. Use it only to transport binary data as text, and use real cryptography (AES, RSA, TLS) when you need security.
Open the Encode tab, type or paste your text, and the Base64 output appears instantly. The tool encodes via UTF-8, so emoji, accented letters and non-Latin scripts all encode correctly. You can switch between Standard, URL-safe and MIME variants and copy or download the result with one click.
Open the Decode tab and paste your Base64. The tool normalizes whitespace, accepts both standard and URL-safe alphabets, repairs missing padding and shows the decoded text. If the data is JSON it can pretty-print it, and if it is binary it offers to reconstruct the original file.
URL-safe Base64 swaps the two characters that have special meaning in URLs — “+” becomes “-” and “/” becomes “_” — and usually drops the “=” padding. This lets the encoded value travel inside query strings, path segments and JWTs without being corrupted by percent-encoding. The tool converts between standard and URL-safe automatically.
Base64 represents every 3 bytes of input using 4 ASCII characters, so the encoded output is roughly 33% larger than the original (plus a little padding). That overhead is the price of turning binary into safe text. For large assets, gzip/Brotli compression on the wire usually recovers most of the difference.
About 33–37%. The core ratio is 4 output characters for every 3 input bytes (a 4/3 ≈ 1.333× expansion), and MIME line breaks plus padding add a little more. The tool’s Analyzer shows the exact overhead percentage for your input.
Yes. In the File tab, upload or drag-and-drop a JPG, PNG, SVG, WebP, GIF or ICO and the tool encodes it instantly, shows a live preview, and generates a ready-to-paste Data URI for CSS or HTML. Everything happens in your browser — the image is never uploaded.
Paste the Base64 (or a full data: URI) into the Decode or File tab. The tool inspects the magic-number signature to detect the file type, previews images, and gives you a Download button that reconstructs the exact original bytes with the correct extension.
A Data URI embeds a file directly inside a string using the form data:[mime];base64,[payload]. It lets you inline small images, fonts or SVGs straight into CSS or HTML so the browser does not need a separate network request. The Data URI tab builds these for you, complete with copy-ready CSS and <img> snippets.
Yes. The JWT tab splits a token into its three base64url segments and decodes the header and payload into readable JSON, lists every claim, and flags expiry using the exp/iat/nbf fields. It decodes only — it never verifies the signature and never sees your secret key, so it is safe to inspect tokens locally.
Pasting is safe in the sense that nothing is transmitted — all decoding runs in your browser and no data is uploaded or logged. That said, treat live production tokens with care on any shared machine. The tool only decodes; it cannot authenticate, forge or validate a token, because that requires the signing secret.
Yes. Text is first encoded to UTF-8 bytes and then to Base64, so any Unicode character — emoji, CJK, Arabic, accented Latin — round-trips perfectly. The older btoa() approach breaks on these; this tool uses TextEncoder/TextDecoder to handle the full Unicode range.
Standard Base64 uses A–Z, a–z, 0–9, “+” and “/”, with “=” as padding (RFC 4648). The URL-safe alphabet replaces “+” with “-” and “/” with “_”. Together those 64 symbols (hence the name) map to the 6-bit groups the encoder produces from your bytes.
The “=” characters pad the output so its length is a multiple of 4. Because Base64 works in groups of 3 input bytes → 4 characters, an input whose length is not divisible by 3 leaves one or two “=” at the end. Padding is required by strict standard Base64 but is often omitted in URL-safe contexts.
The usual causes are: characters outside the alphabet (spaces in the middle, smart quotes, line numbers), wrong or missing padding, a length that is not a multiple of 4 for padded strings, or mixing the standard and URL-safe alphabets. The Validator pinpoints each problem and suggests a fix.
MIME Base64 (RFC 2045) is the variant used in email. It is standard Base64 with the output wrapped into lines of 76 characters separated by CRLF. The tool can produce MIME-wrapped output and also strips those line breaks automatically when decoding.
It groups the input into 24-bit blocks (3 bytes), then splits each block into four 6-bit numbers. Each 6-bit value (0–63) indexes into the 64-character alphabet to produce one output character. If the final block is short, the encoder pads with zero bits and appends “=” so decoders know how many bytes to drop.
Both turn binary into text, but hex uses 16 symbols (0–9, a–f) and needs 2 characters per byte (100% overhead), while Base64 uses 64 symbols and needs only ~1.33 characters per byte (33% overhead). Hex is easier to read byte-by-byte; Base64 is more compact. The Convert tab translates between them instantly.
Use it whenever you must embed binary inside a text-only field: a file upload inside a JSON body, a small image in a webhook payload, binary credentials in an HTTP header, or a signed token. For large files, prefer multipart uploads or pre-signed URLs — Base64 inflates the payload and is parsed entirely in memory.
Absolutely not. Base64 is trivially reversible and offers no protection. Passwords should be hashed with a slow, salted algorithm such as bcrypt, scrypt or Argon2. Use Base64 only to encode the resulting binary hash or salt for storage as text — never as a security measure on its own.
Yes. The File tab accepts PDFs, Office documents, text files, archives, audio and video. It reports the size and detected MIME type and produces the Base64 plus an optional Data URI. Reconstruction on decode preserves the original bytes exactly.
Because encoding happens entirely in your browser memory, very large files can be slow or hit browser limits. This tool comfortably handles files up to tens of megabytes. For multi-hundred-megabyte assets, a streaming server-side pipeline is a better fit than in-browser Base64.
Never. All encoding, decoding, file conversion and JWT decoding run locally using standard Web APIs. Your text, files and tokens never leave your device, are never logged and are never stored remotely — making the tool safe for confidential and regulated data.
For ASCII you can use btoa(str), but it breaks on Unicode. The correct, Unicode-safe approach is btoa(String.fromCharCode(...new TextEncoder().encode(str))) to encode, and new TextDecoder().decode(Uint8Array.from(atob(b64), c => c.charCodeAt(0))) to decode. This tool uses exactly that technique under the hood.
Use the base64 module: base64.b64encode(data.encode()).decode() to encode a string and base64.b64decode(b64).decode() to decode. For URL-safe output use base64.urlsafe_b64encode. Remember to encode/decode the string to bytes first, since the functions operate on bytes.
Use the base64 utility: echo -n "text" | base64 to encode, and echo "encoded" | base64 -d to decode. Add the -w 0 flag to disable line wrapping. On macOS the same command exists, and openssl base64 works cross-platform.
Encoding (like Base64) transforms data into another format for safe transport and is fully reversible by anyone. Encryption transforms data using a secret key so that only someone with the key can recover it. Encoding is about compatibility; encryption is about confidentiality. They solve different problems.
Pure Base64 does not, but the MIME variant inserts a CRLF every 76 characters, and pasted strings often pick up stray line breaks. Decoders should ignore whitespace, which this tool does — it strips all spaces, tabs and newlines before decoding so wrapped or copy-pasted strings still work.
Encode the image in the File tab, then use the generated Data URI like this: background-image: url("data:image/png;base64,iVBORw0K…"). The Data URI tab outputs this snippet ready to paste. Inlining avoids an extra HTTP request, which is ideal for tiny icons.
Data URIs remove a network round-trip, which speeds up rendering of small, critical assets like inline SVG icons or above-the-fold thumbnails. The trade-offs are the 33% size increase and that inlined assets cannot be cached separately, so reserve them for small, rarely-changing resources.
Yes. The Auto-detect engine inspects your input and recognizes JWTs, Data URIs, Base64-encoded JSON/XML/HTML, encoded images and files (via magic-number signatures), hex, binary and URL-encoded text — then suggests the right one-click action for each.
Entropy estimates how random the characters are, measured in bits per character. Compressed or encrypted data approaches the theoretical maximum (~6 bits for Base64), while repetitive or structured text scores lower. It is a quick heuristic for telling random keys apart from encoded plain text.
Yes. Once the page has loaded, all core features keep working without a connection because everything runs client-side. You can encode, decode, convert files and decode JWTs on a plane or behind a firewall with no internet access.
Use the Convert tab. Paste a value in any format — text, Base64, URL-safe Base64, hex, binary or URL-encoded — and the tool decodes it to raw bytes and re-renders it in every other format simultaneously, so you can read the same data however you need it.
Yes. The alphabet includes both uppercase and lowercase letters, and they map to different values, so changing the case of a Base64 string corrupts it. This differs from hex, where case does not matter. Always preserve the exact casing when copying Base64.
No. Base64 is a lossless, one-to-one mapping between byte sequences and encoded strings (ignoring optional whitespace and padding differences). The same bytes always produce the same output, and every valid Base64 string decodes back to exactly one byte sequence.
RFC 4648 defines the canonical Base64 and Base64URL alphabets with no line wrapping. RFC 2045 (MIME) uses the standard alphabet but mandates 76-character lines for email bodies. They share the same characters; the difference is whether line breaks are inserted.
Use URL-safe Base64. Standard Base64 contains “+”, “/” and “=”, which must be percent-encoded in URLs and can cause subtle bugs. URL-safe Base64 (- and _ with no padding) drops cleanly into query parameters and path segments. The tool produces it directly in the Encode and Convert tabs.
The File tab focuses on one file at a time with a preview and stats so you can verify each result. For automated batch pipelines, a script using the same encoding logic (shown in the code examples) is the right approach. Drag a new file in at any time to replace the current one.
That usually means the bytes are not UTF-8 text — they may be a binary file (image, PDF, compressed data) or text in a different character set. The tool flags non-text output and offers to decode it as a file instead, where the magic-number detector identifies the real format.
Yes, completely free with no sign-up, no usage limits and no watermarks. Encode, decode, convert files, build Data URIs and decode JWTs as much as you like. An optional Pro tier removes ads and raises in-browser file limits, but every core feature is free forever.
Common actions are bound: Ctrl/Cmd + Enter swaps between Encode and Decode, Ctrl/Cmd + C copies the output when the editor is focused via the Copy button, Ctrl/Cmd + K clears the input, and Ctrl/Cmd + / opens the shortcuts panel. Native undo/redo works inside the editor.
Related Tools
Explore More Tools
Go ad-free & unlock power features
- Zero ads, faster focused workflow
- Upload 50MB+ files & batch process
- Priority AI type & schema generation