Toolphy

Base64 Encoder / Decoder

Encode text to Base64 or decode Base64 back to plain text. All processing happens locally in your browser.

Mode:

How to Use the Base64 Encoder/Decoder

Base64 encoding is a fundamental technique for representing binary data as text. Whether you are embedding images, encoding credentials, or transmitting data through text-based protocols, this tool makes it simple. Here is how to use it.

  1. Enter your input. Type or paste your text into the input area. For encoding, enter plain text. For decoding, enter a Base64-encoded string.

    Example (Encode): Enter "Hello World!" — the output becomes "SGVsbG8gV29ybGQh".

  2. Select the mode. Choose "Encode" to convert plain text to Base64, or "Decode" to convert Base64 back to readable text. The tool uses browser-native btoa() for encoding and atob() for decoding, with proper UTF-8 handling via encodeURIComponent/decodeURIComponent wrappers to support special characters.

    Example (Decode): Enter "SGVsbG8gV29ybGQh" and select Decode — the output becomes "Hello World!".

  3. Click "Process" to execute. The result appears instantly in the output area.

  4. Check for errors. If you enter invalid Base64 text (e.g., containing characters outside the Base64 alphabet), the tool displays an error message asking you to verify your input.

  5. Copy the result. Use the "Copy to Clipboard" button to copy the encoded or decoded output.

    Pro tip: Base64 is not encryption. Never use it to protect sensitive data. Anyone with the encoded string can decode it instantly. Use proper encryption algorithms like AES for security needs.

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format by translating it into a radix-64 representation. The name comes from the fact that it uses 64 different characters (A-Z, a-z, 0-9, +, /, and = for padding). It works by taking binary data in 8-bit bytes, grouping them into 24-bit sequences, and splitting each sequence into four 6-bit values, each mapped to one of the 64 characters. Base64 is not encryption — it is encoding. Anyone can decode a Base64 string using widely available tools. It is essential for scenarios where binary data must travel through text-only channels. Common uses include email attachments via MIME, embedding images directly in HTML or CSS as data URIs, storing binary data in JSON, and encoding authentication credentials for HTTP headers. Understanding Base64 helps developers debug data transmission issues and work with web APIs more effectively.

Common Applications

1. Embedding images in HTML/CSS: A web developer wants to reduce HTTP requests by embedding a small icon directly in a CSS file. They encode the image file to Base64 and use it as a data URI: url("data:image/png;base64,iVBORw..."). This eliminates an additional server request.

2. API authentication: A developer integrates with a REST API that requires HTTP Basic Authentication. The username and password must be encoded as a Base64 string in the Authorization header. The tool quickly generates the correct encoded string for testing.

3. JSON data storage: A backend system stores binary blobs alongside JSON data. Since JSON is text-only, binary data must be Base64-encoded before inclusion. The tool helps developers encode and decode these blobs during development and debugging.

4. Email attachments: When sending emails programmatically, binary attachments are Base64-encoded according to the MIME standard. Developers use encoding tools to prepare attachment data before constructing email messages.

5. Web security testing: Security researchers and penetration testers often encounter Base64-encoded data in web applications. Using the decoder, they can quickly inspect encoded tokens, session identifiers, or configuration data to identify security weaknesses.

What Base64 Is — and What It Is Not

Base64 is a binary-to-text encoding defined in RFC 4648. It represents arbitrary bytes using 64 printable ASCII characters — A–Z, a–z, 0–9, plus '+' and '/', with '=' for padding. The point is transport, not secrecy: many systems carry text but corrupt or truncate raw binary, so base64 turns bytes into an alphabet that survives email bodies, JSON, XML, and configuration files.

The most important thing to understand is that base64 is not encryption. It provides no confidentiality and no key; anyone can decode a string instantly, which is why a base64-encoded password or API token is effectively plain text. 'cGFzc3dvcmQ=' decodes to 'password'.

It is also not compression — the output is nearly always larger, never smaller — and not a hash, since decoding returns the exact original bytes and cannot serve as a one-way fingerprint. For secrecy use real encryption such as AES-GCM; for integrity use a cryptographic hash or MAC. Base64 solves one problem only: moving bytes through text-only channels. Because decoding is trivial and lossless, never treat it as a security boundary; where tokens look like base64url, their security comes from a signature, not the encoding.

Why Base64 Adds About 33%: The Arithmetic

Base64 maps every 3 input bytes (24 bits) onto 4 output characters, each carrying 6 bits: 6 x 4 = 24, an exact and reversible mapping. The output is therefore 4/3 the size of the input, an increase of about 33.3%.

Padding makes the arithmetic work when the input length is not a multiple of three. One leftover byte produces two characters followed by '=='; two leftover bytes produce three characters and a single '='. The '=' signs carry no data — they only signal how many bytes to reconstruct. Stripping padding is a common mistake: many decoders tolerate it, but a strict decoder rejects a string whose length is not a multiple of four.

The alphabet matters too. Standard base64 includes '+' and '/', which do not survive in URLs or filenames without escaping. Base64url, also in RFC 4648, replaces them with '-' and '_' and usually drops padding, so decoding standard base64 as base64url yields the wrong bytes even when the string looks plausible.

Finally, base64 encodes bytes, not characters. Text is first converted to bytes with a character encoding, typically UTF-8. Encoding as Latin-1 and decoding as UTF-8 produces mojibake, so both ends must agree on the charset.

Data URIs and Everyday Uses of Base64

The most visible web use of base64 is the data URI, defined by RFC 2397: 'data:image/png;base64,iVBORw0KGgo...'. The browser parses the media type, decodes the payload, and renders it inline, saving a network request. That is handy for tiny icons, spacer images, or CSS backgrounds that would otherwise cost a round trip.

The costs are real. The 33% penalty is compounded because a data URI cannot be cached separately from its document, and gzip cannot compress base64-encoded binary well since the alphabet is close to random. Embedding a large image bloats the HTML and delays first paint. Inline only assets of a few kilobytes and serve everything larger from a normal URL with proper caching headers.

Beyond images, base64 appears wherever binary must travel as text: MIME email attachments, JSON APIs carrying a file or key, and PEM certificate files, which are base64 wrapped in '-----BEGIN ...-----' lines. Tokens and cookies may use base64url, though the encoding is not what makes them secure.

When building a data URI by hand, get the media type right. Omitting it or declaring the wrong MIME type can make the browser treat content as plain text. Use the tool to emit the full 'data:...;base64,' prefix when embedding, and the bare payload when an API expects only the encoded bytes.

Common Base64 Errors and When Not to Use It

Common errors are predictable. In the browser, passing non-ASCII text straight to btoa() throws 'InvalidCharacterError', because btoa expects a binary string, not Unicode. Encode the string to UTF-8 bytes first, for example with TextEncoder, then base64-encode. The mirror bug appears when decoding: atob() returns a binary string that must be interpreted as UTF-8 to recover accents, emoji, or non-Latin scripts.

Next comes padding and alphabet confusion — mixing base64url with standard base64, or stripping '=' and then feeding a strict decoder. Decide up front which variant the receiver expects. Whitespace inserted for readability, as in MIME, must be removed before decoding, and '+' and '/' need percent-encoding in URLs unless you use base64url.

A subtler failure is treating base64 as security. A classic bug is encrypting data, base64-encoding the ciphertext, and calling it obfuscated; the encoding adds nothing, and the security rests entirely on the cipher.

Know when not to use base64: not as encryption, compression, or a hash. Avoid it for large files, where the overhead and lost cacheability hurt, and skip it when the transport already carries binary safely, such as multipart uploads. Use it for its one real purpose — moving binary through text-only channels — and expect no protection from it.

Sources

Frequently Asked Questions - FAQ

Is my data safe using this tool?

Yes. All encoding and decoding happens locally in your browser. No data is transmitted.

Is Base64 encryption?

No. Base64 is encoding, not encryption. It can be easily reversed and should not be used for security. Anyone with the encoded string can decode it instantly.

Does it support UTF-8 characters?

Yes, the tool properly handles UTF-8 and Unicode characters including accented letters, emoji, and non-Latin scripts using encodeURIComponent/decodeURIComponent wrappers.

Why does Base64 output sometimes end with = signs?

The = character is used as padding in Base64. Since Base64 converts 3 bytes into 4 characters, if the input length is not a multiple of 3, one or two = signs are added to make the output length correct.

Can I encode images or files with this tool?

This tool works with text input. To encode binary files like images, you need to read the file as a data URL first. Some browsers support reading files as Base64 directly through the FileReader API, which you can then paste into this tool.

Last updated: