Skip to tool

Base64 Encoder & Decoder

Plain text
Encoded output

The Base64-encoded text

How Base64 encoding and decoding works

Base64 turns bytes into text using 64 characters: A–Z, a–z, 0–9, + and /. Every 3 input bytes become 4 output characters, and = pads the last group. Text is converted to UTF-8 bytes first, so emoji and CJK characters round-trip exactly: "Hello" encodes to SGVsbG8= and "你好" (6 UTF-8 bytes) to 5L2g5aW9. Text input is capped at 1,000,000 characters.

How to encode or decode Base64 online

  1. Pick a format: Base64 for general use, Base64URL for values that go into URLs or JWTs, URL for percent-encoding, File for images and other binary files.
  2. Choose Encode or Decode. ⌘E on macOS, or Ctrl+E on Windows and Linux, switches between the two.
  3. Type or paste into the input box. The line under the result shows the input length, the output length and the size change.
  4. Click Swap to move the output into the input and flip the direction. Encoding a value and swapping it back is a quick round-trip check.
  5. Copy the result. Only the format and the direction are stored in the page address, so a bookmark reopens the tool in the same mode. Your text is never added to the address.

Base64, Base64URL and URL encoding

Standard Base64 follows RFC 4648 §4 (`+/` alphabet, `=` padding). Base64URL follows RFC 4648 §5: it uses `-` and `_` instead of `+` and `/` and drops the padding. When decoding, whitespace and line breaks are ignored and missing padding is restored. URL mode percent-encodes text with `encodeURIComponent` (for a single query value or path segment) or `encodeURI` (for a full URL, keeping `/ ? # & =` intact).

Convert an image or file to Base64

In File mode, drop, paste, or choose a file up to 10 MB to get its raw Base64 payload and a `data:` URL you can paste into HTML or CSS. To go the other way, paste a Base64 string or a `data:...;base64,` URL: the tool detects PNG, JPEG, GIF, WebP, PDF, SVG, ZIP and GZIP from the file's first bytes, sets the right MIME type and extension, previews images, and lets you download the rebuilt file.

Base64 examples

  • Man → TWFu. Three bytes fill exactly four characters, so there is no padding.
  • Ma → TWE= and M → TQ==. Two leftover bytes need one = sign; one leftover byte needs two.
  • Hello, World! → SGVsbG8sIFdvcmxkIQ== in standard Base64.
  • subjects?_d → c3ViamVjdHM/X2Q= in Base64 and c3ViamVjdHM_X2Q in Base64URL. The / becomes _ and the padding is dropped.
  • a b&c=d → a%20b%26c%3Dd with encodeURIComponent. With encodeURI, https://example.com/search?q=a b&lang=zh becomes https://example.com/search?q=a%20b&lang=zh, and the URL structure stays intact.

Where Base64 shows up

Email attachments travel as Base64 inside MIME messages (RFC 2045), wrapped at 76 characters per line. HTTP Basic authentication sends user:password as Base64 in the Authorization header. A JWT is three Base64URL segments joined by dots. data: URLs embed small images and fonts directly in HTML and CSS, and PEM certificates and keys are Base64 between BEGIN and END lines. The first characters often identify the content: a string starting with iVBORw0KGgo is a PNG, /9j/ is a JPEG, R0lGOD is a GIF and JVBERi0 is a PDF.

Common Base64 mistakes

  • Decoding a Base64URL value in Base64 mode. The characters - and _ are not in the standard alphabet, so the tool reports invalid Base64. Switch the format to Base64URL. The reverse fails too: + and / are invalid in Base64URL.
  • Pasting a whole data: URL into a text mode. The data:image/png;base64, prefix is not Base64. Use File mode, which accepts the full URL, or paste only the part after the comma.
  • Expecting + to decode as a space in URL mode. Percent-decoding leaves + unchanged; only %20 becomes a space. HTML forms send spaces as +, so replace + with %20 before decoding form data.
  • Leaving a bare % in text you decode. A % that is not followed by two hex digits, as in 100%, is rejected as an invalid percent-encoded string. Write it as 100%25.
  • Treating Base64 as protection for passwords or API keys. Anyone can decode the value in one step, including from logs and browser history.
  • Embedding large files as data: URLs. The file grows by a third, and the browser cannot cache it separately from the HTML or CSS that carries it. Keep data: URLs for assets of a few kilobytes.

FAQ

Is Base64 encryption?

No. Base64 is a reversible encoding; anyone with the encoded value can decode it. Use it to move binary data through text-only channels, not to hide it.

How much bigger is Base64 than the original?

About 33% bigger. Every 3 bytes become 4 characters, so a 30 KB image becomes roughly 40 KB of Base64 text, and the data: URL prefix adds a few more characters.

How do I convert Base64 back to an image?

Switch to File mode, choose Decode, and paste the Base64 string or the full data:image/...;base64, URL. The image is previewed and can be downloaded with the detected extension, such as .png or .jpg.

Why does decoded Base64 text show garbled characters?

Text mode decodes the bytes as UTF-8. If the Base64 holds an image, a ZIP, or text in another encoding such as GBK, the bytes are not valid UTF-8 and show as � characters. Decode binary data in File mode instead.

When should I use Base64URL?

Use it when the value goes into a URL, a JWT segment, or a filename. Base64URL avoids +, / and =, which would otherwise need percent-escaping.