{ sniptools }
Encoding

Base64 Encoder/Decoder

Encode and decode Base64 strings and files

What is Base64 Encoder?

Base64 is a binary-to-text encoding scheme that represents arbitrary binary data using a set of 64 printable ASCII characters (A-Z, a-z, 0-9, +, and /) plus the padding character =. It was originally designed to safely transmit binary data over channels that only support text — most notably email (MIME) and early HTTP systems. Today, Base64 is ubiquitous in web development: it appears in data URIs for inline images, JWT token segments, HTTP Basic Authentication headers, and anywhere binary content needs to travel through text-based protocols.

The encoding is purely a representation change, not a transformation of meaning. Every Base64 string can be decoded back to the exact original bytes — it is fully reversible with zero data loss. This is fundamentally different from encryption (which requires a key to reverse) or hashing (which is one-way). Base64 provides no security whatsoever; its sole purpose is format compatibility between binary data and text-only systems.

Two main variants exist: standard Base64 (RFC 4648 Section 4) uses + and / with = padding, while URL-safe Base64 (RFC 4648 Section 5) substitutes - for + and _ for /, and typically omits padding. The URL-safe variant is critical in web contexts because +, /, and = all have special meanings in URLs and would be double-encoded or misinterpreted without substitution. JWTs, for instance, exclusively use URL-safe Base64.

How it works

Base64 encoding processes input in groups of 3 bytes (24 bits) at a time. Each 24-bit group is divided into four 6-bit values, and each 6-bit value (ranging from 0 to 63) maps to a character in the Base64 alphabet: values 0-25 map to A-Z, 26-51 to a-z, 52-61 to 0-9, 62 to +, and 63 to /. This produces 4 output characters for every 3 input bytes, which is why Base64 output is always roughly 4/3 the size of the input.

When the input length is not a multiple of 3, the final group is handled with padding. If 1 byte remains, it produces 2 Base64 characters plus == padding. If 2 bytes remain, it produces 3 Base64 characters plus = padding. The decoder uses these padding indicators (or infers from the string length) to know how many bytes to reconstruct from the final group. Some modern implementations strip padding entirely since the math is unambiguous.

Decoding reverses the process exactly: each Base64 character is converted back to its 6-bit value, four characters are combined into three bytes (24 bits), and the padding signals how many trailing bytes to discard from the final group. This tool performs encoding and decoding entirely in the browser using JavaScript's TextEncoder for UTF-8 conversion and typed arrays for binary handling, ensuring correct behavior with Unicode text and binary files alike.

How to use this tool

  1. To encode text, type or paste your content into the input field and select "Encode" mode. The Base64 output appears instantly in the output area as you type.
  2. To decode a Base64 string, paste the encoded string into the input field and select "Decode" mode. The original text is reconstructed and displayed immediately.
  3. Toggle the "URL-safe" option if you need output that uses - and _ instead of + and /, which is required for JWT segments, URL parameters, and filenames.
  4. To encode a file, drag and drop it onto the input area or use the file picker. The tool reads the file as binary and produces the Base64 representation, which you can copy for use in data URIs or API payloads.
  5. Copy the result using the copy button. For data URI usage, prepend the appropriate MIME type prefix (e.g., data:image/png;base64,) to the encoded output.

Examples

Embedding a small image as a CSS data URI

Drag a small icon or logo PNG onto the encoder to get its Base64 representation. Use the output in your CSS as background-image: url(data:image/png;base64,...) to eliminate an HTTP request. This technique is effective for images under 5-10 KB where the inline overhead is outweighed by saving a network round-trip.

Constructing an HTTP Basic Auth header

HTTP Basic Authentication requires sending credentials as a Base64-encoded string in the format username:password. Type your credentials (e.g., "admin:secretpass"), encode them, and use the result in an Authorization header: "Basic YWRtaW46c2VjcmV0cGFzcw==". Remember that Basic Auth over HTTP provides no real security — always use HTTPS.

Decoding a Base64 payload from an API response

Some APIs return binary content (PDFs, images, protobuf messages) as Base64-encoded strings within JSON responses. Paste the encoded string into the decoder to inspect the content, verify it is valid, or check its size before writing the decode logic in your application code.

Inspecting the segments of a JWT token

Each segment of a JWT (header and payload) is a Base64url-encoded JSON object. If you want to understand the raw encoding rather than using a dedicated JWT decoder, paste an individual segment into the decoder with URL-safe mode enabled to see the underlying JSON. This helps when debugging tokens that fail to decode due to encoding issues.

About this tool

Encode text or files to Base64 and decode Base64 back to plain text or binary. Supports URL-safe encoding, Unicode text, and file drag-and-drop.

Common use cases

  • Encoding binary data or images for embedding in HTML, CSS, or JSON payloads
  • Decoding Base64 strings from API responses, email headers, or data URIs
  • Preparing data for systems that only accept ASCII text (email attachments, XML)
  • Converting authentication credentials for HTTP Basic Auth headers

Frequently asked questions

Is Base64 encoding the same as encryption?
No. Base64 is an encoding scheme, not encryption. It converts binary data to ASCII text for safe transport, but anyone can decode it. Never use Base64 to protect sensitive data — use proper encryption instead.
What is URL-safe Base64?
Standard Base64 uses characters (+, /, =) that have special meaning in URLs. URL-safe Base64 replaces these with hyphen (-), underscore (_), and omits padding, making it safe for use in URLs and filenames.
Can I encode files with this tool?
Yes. You can drag and drop files or paste text to encode. The tool supports both text and binary file encoding, producing a Base64 string you can use in data URIs or API payloads.
Why does Base64 encoding increase the size of my data?
Base64 represents every 3 bytes of input as 4 ASCII characters, resulting in approximately 33% size overhead. This is because 6 bits of data are mapped to each of the 64 printable characters in the Base64 alphabet (A-Z, a-z, 0-9, +, /), and 8-bit bytes must be padded to align with 6-bit groups. The trade-off is worthwhile when you need to embed binary data in text-only formats like JSON, XML, or email.
What does the padding character (=) mean in Base64?
The equals sign (=) is padding added to make the output length a multiple of 4 characters. If the input byte count is not divisible by 3, one or two padding characters are appended: one = if there is one extra byte, two == if there are two. Some implementations (like URL-safe Base64 and many modern APIs) strip padding since the decoder can infer the original length from the output length.
How do I handle Unicode text with Base64?
JavaScript's built-in btoa() function only handles Latin-1 characters. For Unicode text (emojis, CJK characters, etc.), you must first encode the string to UTF-8 bytes using TextEncoder, then Base64-encode those bytes. This tool handles this conversion automatically, so you can safely encode any Unicode text without worrying about character encoding issues.