What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts arbitrary binary data into a sequence of printable ASCII characters. The name comes from the fact that it uses 64 distinct characters — the letters A–Z and a–z, the digits 0–9, and the symbols + and / — to represent binary data in groups of six bits at a time.
Base64 was designed to solve a fundamental problem: not all communication channels can safely transmit raw binary data. Email systems originally only handled plain ASCII text, and many network protocols impose similar restrictions. Base64 encodes binary content into a safe ASCII representation that can pass through any text-based system without corruption.
How to Encode and Decode Base64
- Select Encode or Decode using the toggle buttons.
- For encoding: type or paste the text you want to encode, or click Upload file to encode any file (image, PDF, etc.).
- For decoding: paste a Base64 string into the input area.
- The result appears instantly in the output panel below.
- Click Copy output to copy the result to your clipboard.
How Base64 Encoding Works
Base64 takes three bytes (24 bits) of input data and splits them into four groups of six bits each. Each six-bit group maps to one character from the 64-character alphabet. If the input length is not divisible by three, padding characters (=) are added to make the output length a multiple of four.
For example, the string Man encodes to TWFu. The ASCII codes for M, a, n are 77, 97, 110 — or in binary: 01001101 01100001 01101110. Regrouped into four six-bit blocks: 010011 010110 000101 101110, which map to T, W, F, u in the Base64 alphabet.
Common Use Cases for Base64
- Email attachments (MIME) — Email protocols transmit binary attachments (images, PDFs, documents) by encoding them as Base64 within the email body.
- Data URLs in HTML/CSS — Small images or fonts can be embedded directly in HTML or CSS as
data:image/png;base64,...to eliminate extra HTTP requests. Useful for icons in email templates that block external images. - JSON APIs — REST and GraphQL APIs often transmit binary blobs (profile images, file uploads, certificates) as Base64-encoded strings within JSON payloads, since JSON does not have a native binary type.
- JWT tokens — JSON Web Tokens use Base64url encoding (a variant that replaces
+with-and/with_) to encode their header and payload sections. - Basic HTTP authentication — The
Authorization: BasicHTTP header encodes credentials asusername:passwordin Base64. - Storing binary data in text fields — Databases and configuration files that only accept text can store binary content (keys, certificates, images) as Base64.
- Cryptography — Public keys, SSL certificates, and other cryptographic artifacts are commonly distributed in PEM format, which is Base64-encoded DER data with a header and footer line.
Base64 vs Base64url
Standard Base64 uses + and / as its 62nd and 63rd characters and uses = for padding. These characters have special meanings in URLs, which makes standard Base64 unsuitable for embedding in query strings or URL paths.
Base64url is a URL-safe variant that substitutes + with - and / with _, and often omits padding. It is used in JWT tokens, OAuth 2.0 flows, and any context where the encoded data appears in a URL. This tool handles standard Base64; for Base64url, replace + with - and / with _ after encoding.
Base64 Size Overhead
Base64 encoding increases data size by approximately 33%. Every three bytes of input become four Base64 characters. A 1 MB binary file becomes roughly 1.33 MB when Base64 encoded. This overhead is the trade-off for universal text-safe transport. For large files or performance-sensitive APIs, binary protocols (like multipart/form-data or Protocol Buffers) are more efficient.
Frequently Asked Questions
Is Base64 a form of encryption?
No. Base64 is encoding, not encryption. Anyone with a Base64 decoder can instantly recover the original data — no key is needed. Do not use Base64 to protect sensitive data. Use it only for safe transport of binary content through text-only channels.
Why does Base64 output end with == or =?
Base64 encodes three bytes at a time into four characters. If the input length is not a multiple of three, padding is added: one = if one byte of padding is needed, two == if two bytes are needed. The = signs are padding characters, not part of the encoded data.
Can I use this to encode images?
Yes. Click Upload file in Encode mode and select any image file. The tool encodes it as a Base64 string that you can embed directly in an <img> tag as a data URL: <img src="data:image/png;base64,... />.
Is my data safe when using this tool?
Yes. All encoding and decoding happens locally in your browser using the built-in btoa() and atob() JavaScript functions. Your text and files are never uploaded to any server and never leave your device.
What happens with non-ASCII characters?
Standard Base64 only handles ASCII characters directly. To handle Unicode (including emoji, non-Latin scripts, and special characters), this tool first encodes the input with encodeURIComponent and unescape before calling btoa(), ensuring multi-byte characters are handled correctly.
How do I decode a JWT token?
JWT tokens consist of three Base64url-encoded sections separated by dots. Copy the second section (the payload) and replace - with + and _ with /, then paste it into this tool's Decode mode. The JSON payload will be displayed as readable text. Note: use dedicated JWT tools for proper signature verification.