๐Ÿ“ฆ Encode ยท Decode ยท File โ†’ Base64 ยท Image Preview ยท URL-Safe

Base64 Encode / Decode

Encode text or files to Base64, decode Base64 strings back to text, and convert images to Base64 data URIs. Supports standard, URL-safe, and MIME formats.

base64-encode-decode โ€” primecalculator.net
Input (plain text)
Output (Base64 encoded)
Output will appear hereโ€ฆ
Format:
Charset:
Input Chars
0
Input Bytes
0
Output Length
0
Size Ratio
โ€”
๐Ÿ“ File / Image โ†’ Base64 Drag & drop or click to upload any file. All processing is done locally in your browser.
๐Ÿ“ค
Drop any file here, or click to browse
Images, PDFs, text files, any format โ€” max 10MB
๐Ÿ“„
โ€”
โ€”
Preview
๐Ÿ“– Base64 Alphabet โ€” All 64 Characters
Related Developer Tools

What Is Base64 and How Does It Work?

Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 printable ASCII characters: Aโ€“Z (26), aโ€“z (26), 0โ€“9 (10), and two special characters (+ and /), plus = as padding. It was designed to safely transmit binary data (images, files, cryptographic keys) through systems that only handle text โ€” such as email (MIME), HTML data URIs, JSON APIs, and HTTP headers. Base64 is not encryption โ€” it is a reversible encoding. For URL-specific encoding, see our URL Encode/Decode tool.

How Base64 Encoding Works โ€” The Algorithm

Base64 Encoding Process
1. Convert input text to bytes using UTF-8 (or Latin-1) 2. Group bytes into chunks of 3 bytes (24 bits) 3. Split each 24-bit chunk into four 6-bit groups 4. Map each 6-bit value (0โ€“63) to a Base64 alphabet character 5. If input isn't divisible by 3: pad with = or == at the end Example: "Hi" (72, 105) โ†’ 010010000110100100 โ†’ 010010 000110 100100 โ†’ 18, 6, 36 โ†’ S, G, k โ†’ "SGk=" (padded with =)

Base64 output is always 4/3 ร— input size, rounded up to nearest multiple of 4 characters.

Base64 Variants

๐Ÿ“

Standard Base64 (RFC 4648)

Uses A-Z a-z 0-9 + / with = padding. The most common variant. Used in email attachments (MIME), PEM certificates, and basic data encoding.

๐Ÿ”—

URL-Safe Base64 (RFC 4648 ยง5)

Replaces + with - and / with _. Safe to use directly in URLs and filenames without percent-encoding. Used in JWTs and OAuth tokens.

๐Ÿ“ง

MIME Base64 (RFC 2045)

Same alphabet as standard but inserts a line break (CRLF) every 76 characters. Used specifically in email encoding (Content-Transfer-Encoding: base64).

๐Ÿ–ผ๏ธ

Data URIs (images)

Format: data:image/png;base64,.... Embeds images directly in HTML/CSS without a separate HTTP request. Use the File encoder above to convert any image.

Common Uses for Base64

Base64 is used everywhere in modern web development and systems: JWT tokens (header.payload.signature โ€” each part is Base64url encoded); HTML data URIs (embedding images, fonts, icons directly in HTML/CSS); Email attachments (SMTP only supports ASCII, so binary attachments are Base64 encoded); API authentication (HTTP Basic Auth sends username:password as Base64); Cryptographic keys and certificates (PEM format is Base64-encoded DER data wrapped in BEGIN/END headers); Storing binary data in JSON (JSON is text-only, so binary blobs are Base64 encoded). See also our URL Encode/Decode tool for HTTP/URL-specific encoding needs.

Frequently Asked Questions

Common questions about Base64 encoding, decoding, and when to use it

Base64 is a method of encoding binary data as a string of printable ASCII characters. It's used to transmit binary data (images, files, keys) through systems that only support plain text. Common uses: email attachments (SMTP can only transmit ASCII), HTML/CSS data URIs (embed images inline without separate HTTP requests), API credentials (HTTP Basic Auth sends username:password Base64-encoded), JWT tokens (JSON Web Tokens use Base64url for header and payload), and PEM certificates (cryptographic keys stored as Base64 text). Base64 is a standard encoding โ€” it's not encryption and provides no security. Anyone can decode it instantly. For URL-specific encoding (spaces, special chars in URLs), use our URL Encode/Decode tool instead.
Base64 encoding increases data size by approximately 33โ€“37%. The theoretical increase is exactly 4/3 (โ‰ˆ33.3%) because 3 bytes of input produce 4 characters of Base64 output. Padding adds a small amount on top. For example: 100 bytes of binary data โ†’ ~136 characters of Base64. 1MB image โ†’ ~1.37MB Base64 string. This size overhead is why Base64 data URIs for large images can significantly increase page load times โ€” use them for small icons and logos, not large photographs. The stats bar in this calculator shows the input bytes and output length so you can see the exact ratio for your data.
Standard Base64 uses + and / as the 62nd and 63rd characters. These are special characters in URLs โ€” + means space in query strings, and / is a path separator. If you embed standard Base64 in a URL without further encoding, these characters will be misinterpreted. Base64URL (also called URL-safe Base64) simply replaces + with - and / with _, making the output safe for URLs without percent-encoding. The alphabet and all other aspects are identical. Base64URL is used in: JWTs (JSON Web Tokens), OAuth 2.0 tokens, cookie values, and URL parameters. Select "URL-Safe" in this calculator to use Base64URL encoding. For general URL encoding of arbitrary text, use our URL Encode/Decode tool.
To embed an image directly in HTML without a separate file request, use a data URI. The format is: data:[media type];base64,[Base64-encoded data]. Use the "File / Image โ†’ Base64" section above: drag and drop your image file, and the tool generates the complete data URI automatically (e.g. data:image/png;base64,iVBORw0KGgo...). You can then use it directly in an <img> tag: <img src="data:image/png;base64,...">, or in CSS: background-image: url("data:image/png;base64,..."). Best practices: use data URIs for small images (icons, logos under ~5KB) and avoid for large images, as it increases HTML size and prevents browser caching of the image separately. MIME type must match the actual image format (image/png, image/jpeg, image/svg+xml, image/gif, etc.).
No. Base64 is encoding, not encryption. It is completely reversible by anyone โ€” there is no key, no secret, and no security protection. If you paste any Base64 string into a decoder (like this tool), you immediately see the original data. Base64 exists for compatibility, not security. True encryption (AES, RSA, etc.) transforms data using a secret key that is required to reverse the transformation. A common misconception is that Base64 "hides" data. It does make text unreadable at a glance, but this is called "security through obscurity" and provides no real protection. Never use Base64 for sensitive data that needs to remain secret. For passwords in databases, use proper hashing (bcrypt, Argon2). For transmitted sensitive data, use TLS/SSL encryption (HTTPS). Base64 is safe to use for its intended purpose: encoding binary data for transmission through text-based systems.
Each language has built-in Base64 support. JavaScript (browser): btoa('Hello World') โ†’ encode; atob('SGVsbG8gV29ybGQ=') โ†’ decode. For Unicode: btoa(unescape(encodeURIComponent(str))). JavaScript (Node.js): Buffer.from('Hello').toString('base64') โ†’ encode; Buffer.from('SGVsbG8=','base64').toString() โ†’ decode. Python: import base64; base64.b64encode(b'Hello') โ†’ encode; base64.b64decode('SGVsbG8=') โ†’ decode. For URL-safe: base64.urlsafe_b64encode(). PHP: base64_encode('Hello') โ†’ encode; base64_decode('SGVsbG8=') โ†’ decode. Java: Base64.getEncoder().encodeToString(bytes). This online calculator handles all these scenarios instantly without writing any code. See also our URL Encode/Decode tool for URL encoding functions.