Base64 Encode and Decode

Paste anything, or drop a file. The tool works out whether to encode or decode, repairs Base64 that was copied badly, and tells you what the decoded bytes are.

This Base64 tool takes whatever you give it and does the sensible thing. Text is encoded as you type. A pasted Base64 string is decoded, even when it arrives wrapped across lines, in the URL-safe alphabet, percent-encoded, inside a data: URI or missing its padding, and the tool says which of those it repaired. Decoded bytes are shown as text, as a JSON tree when they are JSON, or as hex; if they are a PNG, JPEG, GIF, PDF, ZIP or another known file type, the type is named from the first bytes, images are previewed, and the download gets the right extension. Drop a file to get its Base64 and a ready data URI with the size increase shown. All of it happens in your browser.

Paste text or Base64, or drop a file. The direction is worked out for you.

Nothing is uploaded. Base64 is an encoding, not encryption.

  • Text and files, both directions
  • Repairs badly copied Base64
  • Names the file type and previews images

How to encode or decode Base64

One input box and one result, converted as you type.

  1. 1

    Paste text or Base64, or drop a file

    Type or paste into the input, or drop a file on it (Choose a file does the same). With Auto selected, the line beside the switch says whether the input was read as Base64 or as plain text. If it guessed wrong, choose Encode or Decode yourself.

  2. 2

    Set the options when encoding

    URL-safe swaps + and / for - and _, for use in URLs, file names and tokens. No padding leaves off the trailing = signs. Wrap at 76 breaks the output into lines the way email does. Decoding needs no options: every one of these forms is accepted.

  3. 3

    Read, copy or download the result

    Decoded data can be viewed as Text, as a JSON tree, or as Hex, then copied or downloaded. For a file you get the Base64, a data URI and the size before and after. Use this result as the input sends the output back through the other way.

Works out the direction

Input is treated as Base64 only when it decodes cleanly to readable text or a known file type. Ordinary words that happen to use Base64 letters, such as "test", are encoded. Auto, Encode and Decode are always one click apart.

Decodes what people really paste

Line-wrapped strings, missing padding, URL-safe characters, percent-encoding, surrounding quotes and data: URI prefixes are repaired, and a note lists each repair. Input that cannot be Base64 gets a specific reason, such as the position of the first invalid character.

Base64 to file, with the type named

The first bytes are checked against PNG, JPEG, GIF, WebP, BMP, ICO, SVG, PDF, ZIP, gzip, WOFF, WOFF2, MP3, MP4, Ogg, WAV and WebAssembly. Images are previewed, and the download is named with the matching extension.

File to Base64 and data URI

Drop any file up to 25 MB to get its Base64 and a complete data: URI ready for CSS or an img tag, with the byte count, character count and percentage increase.

Example: an API response field

A JSON API returns "eyJ1c2VyIjoiYWRhIiwicm9sZXMiOlsiYWRtaW4iXX0". Paste it: the tool adds the missing padding, decodes it, and shows {"user":"ada","roles":["admin"]} as a tree you can expand.

Example: an icon for a stylesheet

Drop a 2 KB PNG icon. Copy data URI gives data:image/png;base64,… to paste into background-image: url(…). The size line shows it grew by about a third, which is the cost of inlining it.

Nowhere. The conversion uses your browser's own functions, no request carries your text or your file, and nothing is stored when you leave.

What Base64 is, and is not

Four facts about the encoding that prevent the most common mistakes people make with it.

Not encryption

Base64 hides nothing. Anyone can decode it, as this page shows. Do not use it to protect a password or a secret.

To keep text private, encrypt it; Rune's Text Encryptor does that in the browser.

The size cost

Base64 writes every 3 bytes as 4 characters, so the result is about 33% larger than the original. Line wrapping adds a little more.

That is why inlining a large image as a data URI makes a page heavier, not lighter.

When to use URL-safe

Standard Base64 uses + and /, which have a meaning in URLs. Base64URL replaces them with - and _, and usually drops the = padding.

Use it for anything that goes into a URL, a file name or a token. JSON Web Tokens are Base64URL.

Text encoding

Text is encoded as UTF-8, the encoding the web uses. A system that expects another encoding, such as UTF-16 or Latin-1, will produce different Base64 for accented or non-Latin characters.

Decoded bytes are shown as text only when they are valid UTF-8; otherwise the hex view shows them as they are.

Limits

Base64 takes files up to 25 MB. A result longer than 200,000 characters is shown in part on the page; Copy and the download give all of it.

Base64 conversions are not counted or capped.

File types are recognised from a fixed list of signatures. A ZIP-based document such as .docx is reported as a ZIP archive.

Questions about Base64

Is Base64 encryption?

No. It is a way of writing bytes using 64 printable characters so they survive systems that only handle text. It has no key, and anyone can reverse it.

How do I turn a Base64 string back into an image or a PDF?

Paste the string, with or without its data: prefix. The tool recognises the file type from its first bytes, previews it if it is an image, and Download saves it with the right extension.

Why does my Base64 string fail to decode elsewhere?

Usually because it was wrapped across lines, lost its = padding, or uses the URL-safe characters - and _. This tool repairs all three and tells you which applied, so you know what to fix at the source.

What is the difference between Base64 and Base64URL?

Two characters. Base64URL uses - and _ where standard Base64 uses + and /, and normally leaves off the padding, so the result is safe inside a URL.

Is it safe to paste a token or key here?

The text is processed by your browser and is not sent to Rune or anyone else. You can confirm that by turning off your network connection after the page loads: the tool keeps working.

I pasted a JWT. Why does it point me to another tool?

A JSON Web Token is three Base64URL parts joined by dots, so it is not one Base64 string. Rune's JWT Decoder splits it and shows the header, the claims and the expiry.