How Base64 Encoding, UTF-8 Byte Mapping & URL-Safe Base64 Work

Why Developers Use Base64 for APIs, Data URIs & Email Attachments

Base64 is a standardized binary-to-text encoding scheme (defined in RFC 4648) that converts arbitrary raw bytes—such as UTF-8 text, images, cryptographic hashes, or binary files—into a safe 64-character ASCII subset (A–Z, a–z, 0–9, +, and /, with = used for padding). Because legacy transport protocols like SMTP email, JSON payloads, XML documents, and HTTP Basic Authentication headers can corrupt raw non-printable bytes, Base64 guarantees data arrives intact across any network. When embedding small icons or fonts directly inside HTML or CSS, developers also use Base64 Data URIs (data:image/png;base64,...) to eliminate extra HTTP requests.

How to Encode or Decode Base64 in 3 Easy Steps

  1. Select Encode or Decode Mode: Click Encode (Text → Base64) to convert plain text into Base64, or Decode (Base64 → Text) to restore readable UTF-8 text.
  2. Paste Text or Upload a File: Type any text (including Hindi, Unicode symbols, and emojis) or click + File / Image to Base64 to generate a Data URI locally.
  3. Copy or Download Output: Toggle URL-Safe Base64 if building JWT tokens or query parameters, then click Copy Output or Download .TXT.

Base64 Encoded Size Expansion Formula & Worked Example

Base64 groups every 3 input bytes (24 bits) into 4 output ASCII characters (6 bits each), increasing payload size by approximately 33.3%:

Encoded Base64 Length (Characters) = 4 × ⌈ Input Bytes / 3 ⌉

Worked Example: Suppose you encode the 3-character ASCII string "Man" (3 bytes: 0x4D 0x61 0x6E).

In binary: 01001101 01100001 01101110 → split into four 6-bit groups: 010011 (19 = T), 010110 (22 = W), 000101 (5 = F), 101110 (46 = u).

Encoded Base64 output = "TWFu" (exact length: 4 × ⌈3 / 3⌉ = 4 characters with zero padding).

Base64 Encoding Standards, Padding Rules & Byte-Size Reference (16 Items)

Use this technical developer cheat sheet to understand Base64 alphabets, padding characters, and size overhead.

Base64 Concept / Input Encoded Output / Rule Byte / Bit Structure Common Real-World Usage
Standard Alphabet (RFC 4648) A–Z, a–z, 0–9, +, / 64 Characters (6-bit) MIME email, HTTP Basic Auth, Data URIs
URL-Safe Alphabet (Base64url) A–Z, a–z, 0–9, -, _ Replaces + and / JWT tokens, OAuth2 state, URL query params
Input Length Divisible by 3 No = padding 3N bytes → 4N chars Clean 24-bit block alignment
Input Length Remainder 1 Ends with == 1 byte → 2 chars + == Pads missing 16 bits to complete 4-char block
Input Length Remainder 2 Ends with = 2 bytes → 3 chars + = Pads missing 8 bits to complete 4-char block
ASCII Input: "A" QQ== 1 byte → 4 chars Demonstrates double-equals padding
ASCII Input: "AB" QUI= 2 bytes → 4 chars Demonstrates single-equals padding
ASCII Input: "ABC" QUJD 3 bytes → 4 chars Zero padding required
UTF-8 Rupee Symbol: "₹" 4oK5 3 UTF-8 bytes → 4 chars Multi-byte Unicode requires TextEncoder
HTTP Basic Auth Header Basic dXNlcjpwYXNz user:pass → Base64 REST API authorization headers
PNG Image Data URI data:image/png;base64,... +33.3% Size Overhead Inline small icons & favicons in HTML/CSS
SVG Vector Data URI data:image/svg+xml;base64,... +33.3% Size Overhead CSS background-image inline embedding
1 KB Binary File ~1,368 Base64 chars 1.33x File Size Negligible overhead for tiny assets
100 KB Image File ~136.5 KB Base64 text +33.3 KB Overhead Better served as external cached file
Is Base64 Encryption? No (Encoding Only) Zero Secret Key Anyone can decode Base64; use AES/HTTPS for secrets
Native JS btoa() Trap Fails on Unicode > U+00FF Solved via UTF-8 Bytes Our tool safely encodes Hindi & emojis

Formatting JSON payloads, generating strong passwords, counting characters, or creating QR codes? Explore our companion developer tools:

Frequently Asked Questions

No. Base64 is an open encoding format—not encryption—and uses no secret key. Anyone who intercepts a Base64 string can decode it instantaneously. Always use HTTPS/TLS and proper cryptographic hashing (such as bcrypt or SHA-256) to protect passwords and sensitive tokens.
Base64 processes input data in groups of 3 bytes (24 bits) and outputs 4 characters per group. When the input byte length is not evenly divisible by 3, one or two = padding characters are appended at the end so the total output length is always a multiple of 4.
Standard Base64 uses + and /, which have special meanings in URLs (where + is decoded as a space and / separates path segments). URL-Safe Base64 (RFC 4648 Section 5) replaces + with - and / with _ so you can safely pass encoded strings inside URLs and JSON Web Tokens (JWT).
Never. All UTF-8 byte conversions, Base64 encoding/decoding, and FileReader Data URI conversions run 100% locally inside your web browser using JavaScript. Your sensitive strings and files never leave your device.