Base64 Encoder & Decoder
Instantly encode and decode text strings or convert images and files to Base64 data URIs. 100% offline.
Also Try JSON Formatter & Validator →Type in either box — the other updates instantly.
Select any file (like an image) to get its Base64 representation. Perfect for embedding images directly into CSS or HTML. No data is uploaded anywhere.
The Complete Guide to Base64 Encoding, Binary Serialization & Data URIs
Base64 is a standardized binary-to-text encoding scheme designed to translate arbitrary binary sequences (such as image files, cryptographic signatures, PDF documents, or compiled bytecode) into a strict set of 64 ASCII characters defined by IETF RFC 4648.
Historically, network transport layers such as SMTP email protocols, HTTP URL parameters, and JSON API payloads were built to handle 7-bit or 8-bit printable ASCII characters. Transmitting raw binary bytes directly over these text-based communication channels caused immediate byte truncation, newline conversion errors, and encoding corruption. Base64 guarantees that data remains 100% intact across all transport protocols.
The Mathematics of Radix-64 Binary Chunking
The Base64 encoding algorithm works by regrouping 8-bit binary bytes into 6-bit index values:
- Bit Regrouping: The encoder takes three consecutive 8-bit bytes (a total of 3 × 8 = 24 bits).
- 6-Bit Splitting: Those 24 bits are split into four 6-bit numbers (4 × 6 = 24 bits). Each 6-bit number represents an integer from
0to63(2⁶ = 64). - Character Lookup: Each integer maps directly to a predefined safe ASCII character:
0 – 25→ Uppercase letters (A–Z)26 – 51→ Lowercase letters (a–z)52 – 61→ Digits (0–9)62, 63→ Plus symbol (+) and Forward slash (/)
- Padding Rules (
=): If the input byte length is not divisible by 3:- If 1 byte remains (8 bits), 4 zero bits are padded to create two 6-bit characters, followed by two
==padding symbols. - If 2 bytes remain (16 bits), 2 zero bits are padded to create three 6-bit characters, followed by one
=padding symbol.
- If 1 byte remains (8 bits), 4 zero bits are padded to create two 6-bit characters, followed by two
The 33.3% Bandwidth Overhead Reality
Because every 3 bytes of raw binary data expand into 4 ASCII text characters, Base64 encoding introduces a mathematical overhead of exactly 33.33% (4/3 ≈ 1.3333). For example, a 30 KB PNG icon will expand into approximately 40 KB of Base64 text.
data:image/png;base64,...) are ideal for tiny icons, SVGs, and web fonts under 4 KB to eliminate separate HTTP roundtrips. However, large photos and multi-megabyte assets should remain external binary files to leverage browser caching and avoid the 33% payload penalty.
Frequently Asked Questions (FAQ)
What is Base64 encoding used for?
Base64 encoding is used to convert binary data into an ASCII string format so that images, files, or special UTF-8 characters can be safely transmitted over protocols that only support plain text, such as HTTP headers, JSON APIs, and email attachments. This prevents data corruption during transmission across systems.
How does Base64 encoding work?
Base64 encoding works by taking groups of three 8-bit binary bytes (24 bits total) and dividing them into four 6-bit values. Each 6-bit value is then mapped to a specific ASCII character from an alphabet of 64 safe characters (A-Z, a-z, 0-9, +, /). Padding characters (=) are added at the end if the input byte length is not a multiple of three.
Is the Base64 Encoder and Decoder safe and private to use?
Yes. Our Base64 Encoder and Decoder runs entirely locally inside your browser using JavaScript. Your input text and uploaded files are never transmitted to any cloud servers, ensuring total privacy. You can even disconnect from the internet after loading the page and continue encoding or decoding files securely offline.
Can I convert an image or PDF file to a Base64 data URI?
Yes. You can drag and drop any image, font, or PDF file into the File to Base64 tab to generate a complete Data URI that you can embed directly into HTML or CSS. This is ideal for reducing HTTP requests by inline-embedding small icons, background graphics, or web fonts.
Why does UTF-8 text sometimes fail in standard Base64 conversion?
Standard browser functions like btoa() only support single-byte Latin1 characters and will throw an error on Unicode emojis or international text. Our tool uses TextEncoder and TextDecoder to safely process all UTF-8 characters. This ensures non-ASCII characters, symbols, and multilingual text encode and decode without data loss.
Is Base64 a method of encryption or password security?
No. Base64 is strictly a public encoding format, not an encryption algorithm. It contains no secret cryptographic keys, and any encoded string can be instantly decoded back to its raw original bytes by anyone using a standard decoder.
Need more developer and design utilities? Explore our complete suite of offline-first tools in the Tools Directory →