Disclosure: Some tools link to SaaS products we may earn a commission from — at no cost to you. All tools are free and run entirely in your browser. See full disclosure →
Client-side only — your data never leaves your browser
Input text
or drop a file
Base64 Output
Base64 output will appear here…

Base64 Encoding Explained: Why It Exists and When to Use It

Base64 solves a deceptively simple problem: how do you transport binary data through a system that was designed for text? The web, email, and many APIs were originally built on protocols that only reliably handle 7-bit ASCII characters. When you need to send binary data — images, certificates, arbitrary bytes — through these channels, you need an encoding that converts binary to a safe subset of text. Base64 is that encoding.

The name comes from the 64 characters used: A–Z (26), a–z (26), 0–9 (10), + (1), / (1). Every 3 bytes of binary input becomes 4 Base64 characters. If the input isn't divisible by 3, padding characters (=) are added to complete the last group.

Why Base64 Was Invented

SMTP (email) was designed to transfer 7-bit ASCII text. The 8th bit of each byte was used for line signalling on some older networks, meaning binary data would be corrupted in transit. MIME (Multipurpose Internet Mail Extensions), introduced in 1992, added Base64 as the standard way to encode binary attachments in email. Every time you receive a PDF or image attachment in your email, it was Base64-encoded during transfer and decoded by your email client.

The same problem exists in HTTP. While modern HTTP handles binary just fine, many APIs, configuration files, and data interchange formats are text-based (JSON, XML, YAML). When you need to embed binary data in JSON — say, a file upload or a cryptographic key — Base64 is the standard approach.

Data URIs: Embedding Binary in HTML and CSS

Data URIs use Base64 to embed binary resources directly in HTML or CSS. The format is:

data:[mediatype][;base64],[data]

For example, to embed a small PNG icon directly in an <img> tag:

<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />

This eliminates an HTTP request for the resource. The trade-off is a ~33% size increase and the inability to cache the resource independently. Data URIs are appropriate for small inline icons (under ~5KB) but counterproductive for larger images.

JWTs and Base64url

JSON Web Tokens (JWTs) use a variant called Base64url. Standard Base64 uses + and / — characters that are meaningful in URLs. Base64url replaces them with - and _ respectively, making the token safe to use directly in a URL without percent-encoding.

A JWT has three Base64url-encoded parts separated by dots: header.payload.signature. The header and payload are not encrypted — they're just Base64url-encoded JSON that anyone can decode. The signature verifies authenticity. This is a common security misconception: JWTs are not secret by default. Sensitive data should not be stored in a JWT payload unless the token is also encrypted (JWE).

To decode a JWT's payload, use the Base64 Decoder — it handles Base64url automatically.

API Authentication Headers

HTTP Basic Authentication encodes credentials in Base64: the header value is Basic [Base64(username:password)]. For example, username api_user with password secret becomes Basic YXBpX3VzZXI6c2VjcmV0. This is sent in the Authorization header. Critically, this is not secure over plain HTTP — Base64 is trivially reversible. Always use HTTPS when sending any credentials, including Basic auth.

Email Attachments (MIME)

MIME encodes email attachments as Base64 with 76-character lines followed by CRLF line endings (per RFC 2045). If you've ever looked at raw email source, you've seen multi-kilobyte blocks of Base64 under Content-Transfer-Encoding: base64. This line-length limit was a compatibility requirement for some legacy SMTP servers. Modern Base64 implementations (RFC 4648) don't require line breaks — they're just a MIME convention.

Affiliate CTA

Building an app that handles Base64, JWT, or file encoding?

Deploy it globally in seconds with Cloudflare Pages — free tier, 275+ edge locations, Workers for server-side logic.

Deploy to Cloudflare Pages Free →

Frequently Asked Questions

Is Base64 a form of encryption?

No. Base64 is an encoding scheme, not encryption. It converts binary or text data into a subset of ASCII characters so it can be safely transported over systems that only handle text. Anyone who sees a Base64 string can decode it instantly — there is no key, no secret, no security. If you need to protect data, you need encryption (AES-256-GCM, RSA, etc.). Base64 only changes how data looks, not who can read it.

Why does Base64 output often end with == or =?

Base64 encodes 3 bytes into 4 characters (6 bits per character × 4 = 24 bits = 3 bytes). When the input length isn't divisible by 3, padding characters (=) are added to complete the final 4-character group. One = means 1 byte of padding (the input had 2 remaining bytes); == means 2 bytes of padding (the input had 1 remaining byte). This is standard per RFC 4648.

What is the difference between Base64 and Base64url?

Standard Base64 uses + and / as characters 62 and 63. These characters have special meaning in URLs (+ means space, / is a path separator). Base64url replaces + with - and / with _ to make the encoding URL-safe without percent-encoding. JWTs use Base64url. When working with JWT tokens, remember that a Base64 decoder expecting standard Base64 will fail on Base64url strings unless it normalises the characters first — this tool handles both.

How much does Base64 increase file size?

Base64 increases the size of the data by approximately 33%. Every 3 bytes of input produces 4 bytes of output (a 4/3 ratio). With line wrapping (MIME uses 76-character lines with CRLF), the overhead reaches about 37%. This is the trade-off: binary data becomes text-safe, but larger. For performance-sensitive applications (data URIs in CSS, embedded images), consider the size impact before choosing Base64.

Can I Base64-encode images and use them directly in HTML?

Yes — this is called a data URI. The format is: data:[mediatype];base64,[base64-encoded-data]. For example: <img src='data:image/png;base64,iVBORw0KGgo...' />. This embeds the image directly in the HTML, eliminating an HTTP request. It's useful for small icons and logos. Downsides: the HTML gets much larger, the image can't be cached by the browser separately, and it increases DOM parsing time. Best practice: use data URIs only for images under ~5KB.

Encoders & Hash Tools
Base64 Decoder URL Encoder URL Decoder MD5 Hash SHA-256 Hash
💡
Need AI tools for your development workflow?

Explore our reviews of the best AI coding assistants, documentation generators, and developer productivity tools — ranked by real-world usefulness.

Browse AI Tools for Developers →
The DevTools Team
Infinfy Engineering
We build free developer utilities that we actually use ourselves. No accounts, no tracking, no backend — just fast, accurate, in-browser tools. Part of Infinfy Solutions.