Base64 Encoder/Decoder
A free online Base64 encoder/decoder for quick encoding and decoding, featuring text-file conversion, drag-and-drop file encoding, inline image preview, file restoration, UTF-8 safe handling, URL-safe conversion, auto-padding, real-time statistics, and secure copy functionality. Provides multilingual code examples, Data URI generation, detailed usage guides, and frequently asked questions. User-friendly interface with bidirectional input filling, keyboard accessibility, and mobile-friendly design. No download required, works directly in your browser.
Encode (Text / File → Base64)
Base64 Output
Decode (Base64 → Text / File)
Decode Result
How to Use
Features
- UTF-8 Safe: Encodes UTF-8 bytes directly, handling CJK, emoji and other non-ASCII characters correctly.
- URL-safe Support: One-click toggle between + / → - _, optional removal of padding =.
- Pre-process Before Decoding: Ignore whitespace, auto-convert URL-safe, and auto-pad =.
- Real-time Interaction: Input is processed instantly, with length and growth rate statistics displayed.
- Usability: Quick copy, bidirectional fill between inputs, keyboard-accessible, mobile-friendly.
- Consistent Theme: No Tailwind dark: classes — fully styled with DaisyUI themes.
- File Support: Click or drop any file to encode it to Base64; decoding detects the type automatically, with image preview, text preview, and file download.
- Local Processing: Files and Base64 are converted inside your browser — nothing is uploaded to a server.
What is Base64?
Base64 is a method of encoding binary data into ASCII text, commonly used to transmit images or file contents over text-based protocols such as JSON, XML, and HTTP.
It maps every 3 bytes into 4 printable characters, typically resulting in approximately a 33% increase in size.
Standard Base64 uses A–Z, a–z, 0–9, +, /, and the padding character =; the URL-safe variant replaces + and / with - and _ to avoid escaping issues in URLs.
Other Base Encodings Compared
"Base" refers to a family of encodings that map binary data onto a fixed alphabet — the number after "Base" is the alphabet size. Common variants include Base16 (Hex), Base32, Base58, Base62, Base64, Base85 (Ascii85) and Base91; they differ mainly in alphabet size, size overhead, and typical use.
| Encoding | Alphabet | Size increase | Typical use |
|---|---|---|---|
| Base16 (Hex) | 0-9 A-F, 16 characters | +100% | Hashes, color values, debug output |
| Base32 | A-Z 2-7, 32 characters | +60% | Case-insensitive tokens, TOTP secrets |
| Base58 | Alphanumeric without 0 O I l, 58 characters | +37% | Bitcoin addresses, short links, invite codes |
| Base64 | A-Z a-z 0-9 + /, 64 characters | +33% | General transport, Data URIs, email attachments |
| Base64URL | Same as Base64, + / replaced by - _ | +33% | URL parameters, filenames, JWT |
| Base85 (Ascii85) | 85 printable characters | +25% | PDF, Git objects, PostScript |
Why Base64 Is So Popular
Why Base64 dominates: its 64-character alphabet is entirely printable ASCII, and virtually every language ships built-in support; encoding and decoding are fixed-width bit operations, so implementations are fast and simple; overhead is only about 33%, and the output can be safely embedded in JSON, XML, email and URL parameters. Base32 is more conservative but 60% larger; Base85 is more compact, yet its alphabet includes quotes and backslashes that need extra escaping inside code or JSON.
Which Base Encoding Is Best?
There is no single best encoding — it depends on the job: Base64 for general transport and APIs; Base58 when humans must read or type the value without confusing 0/O or 1/l (invite codes, short links); Base32 when case-insensitivity is required (paper forms, some DNS setups); Base64URL for URLs and filenames; Base85 when both sides are under your control and size matters (PDF, Git objects). Choosing a "wrong" variant usually costs size or escaping, not correctness.
Why Avoid Base64 in Web Content
Why heavy Base64 is discouraged in web content: inlining images or fonts as Data URIs inflates HTML/CSS by about 33%, prevents those assets from being cached or downloaded in parallel, and slows first paint; Base64 text has lower entropy, so gzip/brotli gains are far smaller than for raw binary, and decoding costs more on mobile. Inlining a few KB of icons can cut requests, but large images and fonts should stay as separate URLs with caching and compression enabled.
Common Use Cases
- Embed images or small files as Data URIs.
- Transfer binary data between client and server (e.g., encrypted ciphertexts, compressed streams).
- Convert text into printable format to avoid encoding inconsistencies or invisible characters.
FAQs & Important Notes
- Character set: In web environments, first encode text as UTF-8 (this tool includes this step automatically).
- URL-safe: For URL parameters or paths, prefer the URL-safe variant and consider removing padding characters.
- Padding: Some implementations allow omitting =; during decoding, automatically pad to a multiple of 4 characters.
- Line breaks: MIME Base64 may include line breaks; select "Ignore whitespace" during decoding to handle them.
- File types: Any file can be encoded. Decoding detects PNG, JPEG, GIF, WEBP, PDF, ZIP, GZIP, MP3, WAV, OGG, MP4 and more from file signatures; unrecognized data that is not valid UTF-8 is treated as binary.
- File size: There is no hard limit — capacity depends on browser memory. Base64 input over 1 MB pauses auto-decoding; click Decode to continue.
How to Encode/Decode Base64 in Programming Languages
const encoded = btoa(unescape(encodeURIComponent(text)));
// URL-safe
const urlSafe = encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
// Preprocess: Replace -_ with +/
let b64 = input.replace(/-/g, '+').replace(/_/g, '/');
if (b64.length % 4 !== 0) b64 = b64.padEnd(b64.length + (4 - (b64.length % 4)), '=');
const text = decodeURIComponent(escape(atob(b64)));
$encoded = base64_encode($text);
// URL-safe
$urlSafe = rtrim(strtr($encoded, '+/', '-_'), '=');
$b64 = strtr($input, '-_', '+/');
// Auto-pad with '='
if (strlen($b64) % 4 !== 0) $b64 .= str_repeat('=', 4 - (strlen($b64) % 4));
$text = base64_decode($b64);
import base64
encoded = base64.b64encode(text.encode('utf-8')).decode('ascii')
# URL-safe Encode (Remove Padding)
url_safe = encoded.replace('+','-').replace('/','_').rstrip('=')
import base64
def b64_decode(s: str) -> str:
s = s.replace('-','+').replace('_','/')
s += '=' * (-len(s) % 4) # Auto-pad with '='
return base64.b64decode(s).decode('utf-8')
import (
"encoding/base64"
)
enc := base64.StdEncoding.EncodeToString([]byte(text))
// URL-safe Encode (No Padding)
urlEnc := base64.RawURLEncoding.EncodeToString([]byte(text))
import (
"encoding/base64"
)
decBytes, err := base64.StdEncoding.DecodeString(enc)
// URL-safe Decode (No Padding)
decURL, err2 := base64.RawURLEncoding.DecodeString(urlEnc)
use base64::{engine::general_purpose, Engine as _};
let enc = general_purpose::STANDARD.encode(text.as_bytes());
// URL-safe Encode (No Padding)
let url_enc = general_purpose::URL_SAFE_NO_PAD.encode(text.as_bytes());
use base64::{engine::general_purpose, Engine as _};
let dec_bytes = general_purpose::STANDARD.decode(&enc).unwrap();
let dec = String::from_utf8(dec_bytes).unwrap();
let url_dec = String::from_utf8(
general_purpose::URL_SAFE_NO_PAD.decode(&url_enc).unwrap()
).unwrap();
import java.nio.charset.StandardCharsets;
import java.util.Base64;
String enc = Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8));
// URL-safe Encode (No Padding)
String urlEnc = Base64.getUrlEncoder().withoutPadding().encodeToString(text.getBytes(StandardCharsets.UTF_8));
import java.nio.charset.StandardCharsets;
import java.util.Base64;
String dec = new String(Base64.getDecoder().decode(enc), StandardCharsets.UTF_8);
String urlDec = new String(Base64.getUrlDecoder().decode(urlEnc), StandardCharsets.UTF_8);