Base64 Encoder

Web & Dev

Encode and decode base64 strings

Base64 is a binary-to-text encoding scheme that represents any binary data using only 64 printable ASCII characters (A–Z, a–z, 0–9, +, /, with = as padding). It exists because many systems — email, JSON, URLs, older text-based protocols — were designed to safely carry plain text but can corrupt or reject raw binary bytes. Base64 wraps that binary data in a text-safe format that passes through those systems unchanged.

This Base64 encoder and decoder converts text or data to Base64 format and back, entirely in your browser. Paste in plain text to get its Base64 representation, or paste in a Base64 string to decode it back to the original text.

Common uses include embedding small images directly into CSS or HTML using data URIs (avoiding an extra network request), encoding binary data for transmission in JSON API payloads (JSON has no native binary type), and preparing file attachments for MIME-based email transmission. One tradeoff to know upfront: Base64-encoded output is always about 33% larger than the original input, because every 3 bytes of binary data become 4 characters of text.

Why Base64 Encoder Matters

Base64 encoding is everywhere in web and application development, often invisibly. Data URIs let developers embed small icons or images directly inside CSS (background-image: url(data:image/png;base64,...)) or HTML, eliminating a separate HTTP request — a meaningful performance win for small, frequently-used assets like sprite icons. JSON Web Tokens (JWTs), used for authentication in most modern web APIs, are Base64Url-encoded in all three of their segments (header, payload, signature), so understanding Base64 is a prerequisite to debugging auth issues by hand. API integrations that need to send binary data (images, PDFs, encrypted payloads) inside a JSON request body almost always Base64-encode that data first, since JSON only supports text.

Email systems rely on Base64 as part of the MIME standard to attach binary files (images, documents) to messages built on a text-only transport protocol (SMTP). Developers troubleshooting webhook payloads, inspecting encoded cookies or auth headers, or decoding embedded images in a page's HTML source all need a fast way to decode Base64 without writing throwaway script code. It's also worth being clear about what Base64 is not: it is an encoding, not encryption — anyone can decode it instantly, so it provides zero confidentiality and should never be used to "protect" sensitive data.

The Base64 Encoder Formula, Explained

Encoding: group input bytes into chunks of 3 bytes (24 bits total), split each chunk into four 6-bit groups, and map each 6-bit value (0–63) to a character in the Base64 alphabet (A–Z=0–25, a–z=26–51, 0–9=52–61, +=62, /=63). If the final chunk has fewer than 3 bytes, pad the output with = characters.

Each Base64 character encodes exactly 6 bits of information, while each original byte holds 8 bits. Three input bytes (3 × 8 = 24 bits) divide evenly into four 6-bit groups (4 × 6 = 24 bits), which is why Base64 processes input in blocks of 3 bytes and produces output in blocks of 4 characters. This is also the source of the 33% size increase: 3 bytes of input become 4 characters of output, a 4/3 ratio.

When the input length isn't a multiple of 3, the final group is padded with zero bits and the output is padded with one or two = characters to signal how many bytes of padding were added, so a decoder can reconstruct the exact original byte count.

Decoding reverses the process: each Base64 character is mapped back to its 6-bit value, the 6-bit groups are concatenated and re-split into 8-bit bytes, and any padding characters are dropped from the final output.

How to Use the Base64 Encoder: Step by Step

  1. Choose encode or decode

    Select whether you're converting plain text/data to Base64 (encode) or converting a Base64 string back to its original form (decode).

  2. Paste your input

    Enter the text you want to encode, or paste the Base64 string you want to decode.

  3. Review the output

    The tool instantly generates the encoded or decoded result. For encoding, note the output is roughly 33% larger than the input.

  4. Copy the result

    Copy the output for use in a data URI, JSON payload, configuration file, or wherever the Base64 string or decoded text is needed.

Base64 Encoder Examples: Real-World Scenarios

1

Encoding a Simple Text String

Encoding the string "Hello, World!" to Base64 to see how the transformation works.

Input text:Hello, World!
Input length:13 bytes

Calculation

13 bytes does not divide evenly by 3 (13 = 4×3 + 1), so the encoder processes four full 3-byte groups plus one leftover byte, padded to fit and marked with '=' at the end.

Result

Base64 output: SGVsbG8sIFdvcmxkIQ== (20 characters, including 2 padding characters — verified with Python's base64 module).

2

Encoding a JSON Payload for an API Request

A developer needs to embed a small JSON object as a Base64 string inside a larger API payload field.

Input text:{"user":"alice","id":42}
Input length:25 bytes

Calculation

Each 3-byte group of the JSON string's UTF-8 bytes is mapped to 4 Base64 characters, with the final partial group padded as needed.

Result

Base64 output: eyJ1c2VyIjoiYWxpY2UiLCJpZCI6NDJ9 (no padding needed, since 25 bytes doesn't require padding in this case — verified with Python's base64 module).

3

Understanding the Size Increase

Confirming how much larger Base64 output is compared to the original input, using the "Hello, World!" example.

Original size:13 bytes
Encoded size:20 characters

Calculation

20 / 13 = 1.538, close to the theoretical 4/3 ≈ 1.333 ratio for larger inputs; small strings show a higher ratio because of padding overhead relative to their size.

Result

For larger files, expect Base64 output to be almost exactly 33% larger than the original binary size — a 1 MB image becomes roughly 1.33 MB as a Base64 data URI.

Common Mistakes to Avoid

  • Treating Base64 as encryption or a security measure — it is a reversible, publicly known encoding with no key, so anyone can decode it instantly. Never use Base64 alone to protect passwords, tokens, or sensitive data.
  • Forgetting the ~33% size overhead when embedding Base64 data URIs in CSS or HTML — for large images, this overhead plus the loss of separate browser caching can make Base64 embedding slower than a normal image request, so it's best reserved for small, frequently reused assets.
  • Confusing standard Base64 (using + and /) with the URL-safe variant (using - and _ instead, and often omitting = padding) used in JWTs and URL query parameters — decoding one variant with the wrong alphabet produces garbled output or errors.

Tips & Tricks

  • Use Base64 for embedding small (a few KB) icons as CSS data URIs to save HTTP requests, but keep larger images as normal image files so browsers can cache them separately.
  • If you're decoding a JWT and it fails, check whether it uses URL-safe Base64 (- and _ instead of + and /) — most JWT libraries handle this automatically, but manual decoding tools may not.

Base64 is a foundational encoding used throughout web development, from embedded images to API payloads to authentication tokens — but it is text-safe encoding, not security. Use this tool to quickly encode or decode strings without writing code. Pair it with the hash calculator when you need to verify data integrity rather than just represent binary data as text, and the file size converter to estimate the real transfer size of Base64-encoded payloads.

Base64 Encoder — Frequently Asked Questions

Related Calculators

Authoritative References

External links open in a new tab. OmniCalc.us is not affiliated with these organisations.

Related Calculators