ToolBook
Support us on Ko-fi
Help us keep this free, forever

Base64 Encoder / Decoder

How to use Base64 Encoder / Decoder

Encode text or files to Base64, or decode a Base64 string back to text.

  1. Choose mode

    Select Encode to convert text or a file to Base64, or Decode to convert Base64 back to readable text.

  2. Enter your input

    Type or paste text into the input box, or drag-and-drop a file onto the upload area.

  3. Toggle URL-safe if needed

    Enable the URL-safe option to get a variant safe for use in URLs. It uses - and _ instead of + and /.

  4. Wrap lines for MIME if required

    Enable Wrap lines to split the encoded output into 76-character lines, producing MIME-compliant Base64 for email attachments and PEM files.

  5. Copy or download the result

    Click Copy to send the output to your clipboard, or Download to save it as a file.

Frequently asked questions

What is Base64 encoding?

Base64 is a binary-to-text encoding scheme. It converts arbitrary bytes into a 64-character alphabet (A–Z, a–z, 0–9, +, /) so binary data can travel safely through text-only channels like JSON fields, email, or data: URIs.

Does this tool send my data to a server?

No. Encoding and decoding runs entirely in your browser. Your text and files never leave your device.

What is the difference between standard and URL-safe Base64?

Standard Base64 uses + and / which have special meaning in URLs. URL-safe Base64 replaces + with − and / with _ and omits = padding, so the result can be embedded directly in query parameters or paths without percent-encoding.

Why does Base64 increase file size?

Every 3 bytes of input become 4 ASCII characters of output, a 33% overhead. That is the price of making binary data text-safe.

Can I encode an image to Base64?

Yes. Drop an image file into the file-drop zone and the tool returns the Base64 string along with a data: URI you can paste directly into an HTML <img> src attribute.

What does "invalid Base64" mean?

Base64 only permits its 64-character alphabet plus = padding. Characters outside that set (such as special characters) cause a decode error. This tool automatically strips whitespace and newlines, including MIME-wrapped lines, before decoding, so pasting formatted Base64 from emails or PEM files works without manual cleanup.

What is Base64 commonly used for?

Base64 encoding appears in data URIs (embedding images directly in HTML or CSS), HTTP Basic Authentication headers, JWT token payloads, MIME email attachments, and binary data inside JSON or XML. Any time binary bytes need to travel through a text-only channel, Base64 is the standard solution.

How do I embed a Base64-encoded image in HTML?

Encode your image file to Base64 using this tool, then use the result as the src of an img tag: <img src="data:image/png;base64,YOUR_BASE64_HERE">. This technique eliminates a separate HTTP request for the image, which is useful for small icons or inline assets in emails.

Can I use this tool to inspect a JWT token?

Yes. JWT tokens are three Base64URL-encoded segments separated by dots (header.payload.signature). To read the payload, copy the middle segment and paste it into decode mode. Enable URL-safe mode if the tool shows a decoding error. JWT uses - and _ instead of + and /.

What is MIME Base64 and when do I need line wrapping?

MIME Base64 (RFC 2045) breaks encoded output into 76-character lines separated by newlines. Most modern APIs and browsers accept unwrapped Base64, but legacy email systems and PEM certificate or private-key files require the line breaks. Use the "Wrap lines" toggle in this tool to produce MIME-compliant output.

Base64 encoding explained — from data URIs to API secrets

Why Base64 was invented, where you see it every day, and the edge cases that trip up developers.

Why Base64 was invented

Binary data — images, audio, compiled code — contains bytes with values that collide with control characters in older text protocols. SMTP (email), HTTP/1.0 headers, and early XML parsers could all corrupt raw binary in transit.

Base64 solves this by mapping every 3 bytes of input into 4 printable ASCII characters. The output uses only letters, digits, +, and / — characters safe in every 7-bit ASCII channel. The trade-off is a 33% size increase.

Where you see Base64 every day

Data URIs embed images directly in HTML or CSS: <img src="data:image/png;base64,iVBORw0...">. Eliminates an HTTP request for small assets.

HTTP Basic Authentication encodes username:password in the Authorization: Basic header. This is encoding, not encryption — Base64 is trivially reversible.

JSON Web Tokens (JWTs) use URL-safe Base64 (Base64url) for their header and payload segments.

Email attachments (MIME) have used Base64 since the 1990s to transmit binary files as text.

SSH keys~/.ssh/id_rsa.pub contains a Base64-encoded public key.

Standard vs URL-safe Base64

Standard Base64 uses + and /. Both characters have special meaning in URLs: + represents a space in query strings and / is a path separator. If you embed standard Base64 in a URL without percent-encoding these characters, the URL breaks.

URL-safe Base64 (Base64url, RFC 4648 §5) substitutes +- and /_, and drops the = padding. It is directly embeddable in query parameters and path segments. JWTs, OAuth tokens, and signed URLs always use Base64url.

The 33% overhead explained

The math: 3 input bytes → 24 bits → 4 groups of 6 bits → 4 Base64 characters.

If the input is not a multiple of 3 bytes, padding (=) fills the last group:

  • 1 leftover byte → 2 Base64 chars + ==
  • 2 leftover bytes → 3 Base64 chars + =

A 100-byte input → ~133 characters. A 1 MB image encodes to ~1.33 MB. Gzip compression of Base64 output recovers much of this, since the character set is small and repetitive.

Common mistakes

Encoding an already-encoded string is the most frequent error. If you encode SGVsbG8= (which is already Base64 for "Hello"), you get U0dWc2JHOD0= — double-encoded. The tool auto-detects the likely direction to help, but the detection is heuristic.

Line breaks in base64 — some tools insert newlines every 76 characters (PEM format). The decoder here normalises these automatically, but if you paste PEM-formatted Base64 into a system expecting a single line, strip the newlines first.

Decoding binary files as text — Base64-decoding a PNG gives you raw bytes, not a printable string. The tool shows a hex representation when the output is not valid UTF-8.