Skip to main content
Developer Tool • 100% Free & Client-Side

Base64 Encoder & Decoder (Unicode & URL-Safe)

Encode plain text or binary streams into 64-character ASCII representations and decode Base64 back into readable UTF-8 strings with optional RFC 4648 URL-safe substitution.

Base64 Encoder & Decoder

Full UTF-8 Unicode compliant encoding and decoding with optional URL-safe mode.

Bytes: 0
Bytes: 0
*Standard Base64 adds ~33.3% data overhead compared to raw binary.

How to Use the Base64 Encoder & Decoder (Unicode & URL-Safe) (Step-by-Step)

Follow these practical numbered steps to obtain accurate results with zero guesswork:

  1. Select your operational mode using the toggle buttons: choose "Encode" to convert plain text into Base64, or "Decode" to convert an existing Base64 string back into readable text.
  2. Paste or type your content into the upper editor area.
  3. Toggle "URL-Safe Mode" if you intend to embed the Base64 output into web query parameters or HTTP header cookies (this replaces + with -, / with _, and strips trailing = padding per RFC 4648 §5).
  4. Review the live byte measurement indicators to monitor the ~33.3% data expansion inherent to Base64 serialization.
  5. Use the "⇅ Swap In/Out" button to reverse your transformation workflow instantly, or "Copy Output" to transfer the result to your clipboard.

How It Works: Base64 Encoding Algorithm (RFC 4648 Binary-to-Text Mapping)

Base64 takes sequential chunks of 3 bytes (24 bits) from binary or UTF-8 streams and splits them into 4 groups of 6 bits each. Each 6-bit index (ranging from 0 to 63) maps directly to a standardized 64-character alphanumeric ASCII alphabet (A-Z, a-z, 0-9, +, /). If the input byte length is not divisible by 3, equal signs (=) are appended as padding.

Encoding Pipeline:
1. 3 Input Bytes = 3 × 8 bits = 24 bits
2. 24 bits split into 4 × 6-bit integers (values 0 to 63)
3. Each 6-bit integer indexes standard table: A-Z (0-25), a-z (26-51), 0-9 (52-61), + (62), / (63)
4. Padding: 1 byte remainder → 2 Base64 chars + "==" | 2 bytes remainder → 3 Base64 chars + "="
5. Output Length = 4 × Math.ceil(Input Bytes / 3)
6. Storage Overhead: (4 / 3) ≈ 1.333 (+33.3% size expansion)

3 Real-World Worked Examples with Real Numbers

To demonstrate how these calculations translate to daily financial and technical decisions, review these three verified scenarios:

Example 1: Encoding Basic ASCII String ("Man")

Demonstrating the textbook 3-byte to 4-character Base64 mapping on the word "Man".

Input Parameters:
Plaintext Input: Man
Byte Representation: M = 77 (01001101), a = 97 (01100001), n = 110 (01101110)
Calculation: Concatenate 24 bits: 010011010110000101101110. Split into 4 chunks of 6 bits: • Chunk 1: 010011 (binary) = 19 (decimal) → T • Chunk 2: 010110 (binary) = 22 (decimal) → W • Chunk 3: 000101 (binary) = 5 (decimal) → F • Chunk 4: 101110 (binary) = 46 (decimal) → u
Result: Encoded Base64: "TWFu" | Input: 3 bytes | Output: 4 bytes (zero padding required)

Practical Takeaway: Because 3 input bytes divide cleanly into 4 6-bit segments, no padding equal signs (=) are needed.

Example 2: Encoding Hindi & Multilingual UTF-8 Characters ("भारत")

Encoding the Devanagari word "भारत" (India) where each character comprises 3 UTF-8 bytes.

Input Parameters:
Unicode Input: भारत
UTF-8 Byte Length: 12 bytes (3 bytes per glyph)
Calculation: Using native TextEncoder to generate Uint8Array byte sequence before Base64 mapping, preventing browser btoa() Latin-1 character crashes.
Result: Encoded Base64: "4KSt4KS+4KSw4KSk" | Input: 12 bytes | Output: 16 characters

Practical Takeaway: Standard JavaScript btoa() throws an InvalidCharacterError when encountering Unicode code points > 255. Our tool utilizes UTF-8 byte stream encoding to guarantee total language compatibility.

Example 3: URL-Safe Base64 for Web Tokens and OAuth Parameters

A web security engineer embeds an authentication token containing slashes and plus signs into a browser redirect URL.

Input Parameters:
Standard Base64: user+session/profile==
RFC 4648 §5 Conversion: Replace "+" with "-", "/" with "_", strip "=="
Calculation: Standard "+" and "/" characters interfere with URL query syntax (?key=val) and path routing. Stripping padding prevents URL encoding percent signs (%3D).
Result: URL-Safe Base64: "user-session_profile"

Practical Takeaway: JSON Web Tokens (JWT) rely strictly on URL-safe Base64 (base64url) across headers, payloads, and cryptographic signatures.

Common Mistakes to Avoid

  • Assuming Base64 is Encryption: Base64 is an encoding format, NOT encryption. It offers zero confidentiality or security protection; anyone can decode it in one click. Never store plain passwords in Base64.
  • Using Native btoa() on Unicode Strings: JavaScript’s built-in window.btoa() treats characters as 8-bit Latin-1. Passing Hindi, Chinese, or emojis directly triggers fatal script exceptions.
  • Overlooking the 33% Bandwidth Penalty: Embedding heavy images directly into HTML/CSS via data:image/png;base64,... inflates network transfer size by one-third and prevents browser caching of individual media files.
  • Failing to Restore Padding in base64url Decoders: Stripping padding for URLs is standard, but strict backend decoders may reject unpadded strings unless you re-append missing = signs (while length % 4 !== 0).

Who Should Use This Tool

  • Web Developers encoding small SVG graphics or fonts directly into CSS stylesheets as Data URIs.
  • Security Engineers inspecting JWT payloads and Basic Authentication HTTP headers (Authorization: Basic base64(user:pass)).
  • Email & Protocol Engineers debugging MIME multipart email attachments and SMTP message transfers.
  • API Architects transmitting binary cryptographic hashes (SHA-256 / HMAC) via JSON endpoints.

The 6-Bit Bitwise Shifting Architecture

To comprehend Base64 at the silicon level, consider how microprocessors execute bitwise operators. When a 3-byte array [b0, b1, b2] is ingested, the bits are combined into a single 24-bit unsigned integer via left-shift operators: (b0 << 16) | (b1 << 8) | b2.

The engine then isolates each 6-bit segment using bitwise AND masks with binary 00111111 (0x3F) and right-shift operations: chunk0 = (int24 >> 18) & 0x3F; chunk1 = (int24 >> 12) & 0x3F; chunk2 = (int24 >> 6) & 0x3F; chunk3 = int24 & 0x3F. These four integer indices directly look up corresponding characters in the 64-symbol string constant table. This simple bitwise transformation executes in tens of nanoseconds on modern CPUs.

Data URIs in Modern Web Performance Optimization

A frequent real-world application of Base64 is the HTML/CSS Data URI scheme (data:[<mediatype>][;base64],<data>). By inlining tiny UI icons, placeholder blur images, or critical fonts directly into initial HTML, web engineers eliminate additional HTTP round-trip requests.

However, because Base64 expands binary size by 33% and cannot be cached independently from the HTML document, inlining files larger than 10-15 KB generally degrades Core Web Vitals (LCP). Knowing when to use Base64 requires balancing request elimination against payload weight.

Technical Limitations (What This Tool Does NOT Cover)

To maintain transparency and prevent financial or technical errors, please note the following specific boundary conditions:

  • Client-side memory constraints: uploading gigantic multi-gigabyte binary files directly may exhaust browser tab RAM.
  • Does not apply file compression (GZIP or Brotli); it merely translates binary bytes into ASCII text.
  • Does not detect file MIME types automatically from arbitrary decoded binary text.
  • Not suitable as a long-term data storage optimization due to inherent 33% size inflation.
ST

Written & Verified by SUMAN TR

Lead Developer & Publisher • Bengaluru, India

Reviewed: 2026-11-12

SUMAN TR is a seasoned WordPress developer, technical SEO specialist, and web publisher based in Bengaluru, India. With over 8 years of hands-on experience designing high-speed digital architectures and custom web utilities, Suman focuses on creating zero-bloat client-side calculation engines and practical, jargon-free guides tailored to Indian financial and web standards.

Frequently Asked Questions (Base64 Encoder & Decoder (Unicode & URL-Safe))

Why was Base64 invented and why is it still used?

Base64 was invented during the early development of electronic mail (MIME protocol). Legacy mail transport agents (like 7-bit SMTP servers) were designed strictly to route printable ASCII text and would arbitrarily corrupt, drop, or modify raw 8-bit binary data (such as images, executables, or compressed archives). Base64 safely packages raw 8-bit binary data using 64 universally supported ASCII characters that traverse any network gateway without corruption.

Is Base64 secure for protecting sensitive data like passwords?

No. Base64 is an encoding mechanism, not encryption or hashing. It contains no secret key, initialization vector, or cryptographic salt. Anyone with access to a Base64 string can decode it instantaneously. Storing passwords or sensitive API tokens in Base64 constitutes an extreme security vulnerability.

Why does Base64 output frequently end with one or two equal signs (=)?

The equal sign (=) is a padding character. Base64 processes data in 3-byte (24-bit) blocks. If your input data contains 1 leftover byte (8 bits), the encoder outputs 2 Base64 characters and appends "==" to maintain the 4-character alignment. If 2 bytes remain (16 bits), it outputs 3 Base64 characters and appends a single "=".

What is URL-Safe Base64 (base64url)?

Standard Base64 utilizes "+" (plus) and "/" (forward slash) as its 62nd and 63rd characters. In web URLs and query strings, plus signs are interpreted as spaces and slashes function as directory separators. RFC 4648 Section 5 defines URL-safe Base64 by substituting "+" with "-" (hyphen), "/" with "_" (underscore), and omitting trailing "=" padding.

Why does Base64 increase data size by 33%?

In raw binary, every byte stores 8 bits of information. Base64 maps only 6 bits of data per character to stay within printable ASCII. Because you require 4 Base64 characters (4 × 6 = 24 bits) to represent what originally took 3 bytes (3 × 8 = 24 bits), the ratio of output to input is 4 to 3, representing an exact 33.3% increase in data overhead.

Can this tool encode emojis and non-English scripts safely?

Yes. Our encoder utilizes the modern Web API TextEncoder to transform input strings into standard UTF-8 binary byte buffers before applying Base64 mapping. This prevents the notorious "character out of range" crash common to basic btoa() implementations.