Base64 Encoder and Decoder

Encode any text or file to Base64, or decode Base64 back to readable text. Unicode is handled correctly, URL-safe and data URI formats are supported, and nothing leaves your browser.

100% freeNo sign-upRuns in your browserWorks on mobile

Encode a file to Base64

How to use the Base64 Encoder and Decoder

  1. Choose Encode to turn text into Base64, or Decode to turn Base64 back into text.
  2. Type or paste into the left box. The result updates on the right as you type.
  3. For encoding, tick URL-safe for tokens and URLs, or Wrap lines at 76 for email (MIME) bodies.
  4. To encode an image or document, drop it into the file box and copy the Base64 or a ready-made data URI.
  5. Copy the result, download it, or press Swap to reverse the conversion and check the round trip.

Features

  • Correct UTF-8 handling for accents, emoji and every script
  • URL-safe base64url output and decoding without padding
  • Optional 76-character line wrapping (MIME style)
  • File to Base64 or data URI, up to 50 MB
  • Detects binary results such as PNG or PDF and lets you save them
  • Precise error messages for invalid characters, padding and length

What Base64 is for

Base64 is a way to write arbitrary bytes using only 64 safe, printable characters: A–Z, a–z, 0–9, + and /. Many systems were built to carry text, not raw binary. Email bodies, JSON documents, XML files, HTTP headers and HTML attributes can all break if they meet a zero byte or an unexpected control character. Base64 lets you smuggle any data through those channels intact. You will meet it in email attachments, data: URIs that embed images in CSS, the Authorization: Basic header, JSON Web Tokens, PEM certificates and API payloads that include files.

How the encoding works

The encoder reads your data three bytes (24 bits) at a time and splits those bits into four groups of six. Each 6-bit group is a number from 0 to 63, which picks one character from the alphabet. Take the word Man: its bytes are 77, 97 and 110, or 01001101 01100001 01101110 in binary. Regrouped into six-bit chunks that is 19, 22, 5 and 46, which map to T, W, F and u, so Man becomes TWFu.

When the input length is not a multiple of three, the last group is padded with =. One leftover byte produces two characters plus ==; two leftover bytes produce three characters plus =. That is why Hi encodes to SGk=.

ValuesCharacters
0–25A–Z
26–51a–z
52–610–9
62, 63+ and / (standard) or - and _ (URL-safe)

Size overhead

Every 3 bytes become 4 characters, so Base64 output is about 33% larger than the input, plus a little for padding and any line breaks. A 300 KB image becomes roughly 400 KB of text. That is a good reason not to inline large images as data URIs: small icons are fine, but big photos load faster as normal files that the browser can cache.

Standard, URL-safe and MIME variants

RFC 4648 defines the standard alphabet and a second base64url alphabet that swaps + for - and / for _, because + and / have special meanings in URLs and file names. Base64url usually drops the = padding as well; JSON Web Tokens use exactly this form. MIME email (RFC 2045) uses the standard alphabet but breaks the output into lines of at most 76 characters. This decoder accepts all three forms automatically.

Why Unicode text needs care

Base64 encodes bytes, not letters, so text must first be turned into bytes with a character encoding. This tool uses UTF-8, the encoding of the web, so café and emoji round-trip correctly. The browser’s built-in btoa() function only accepts Latin-1 characters and throws an error on anything else, which is a common bug in hand-written JavaScript. If a decoded result shows strange characters such as é, the original was probably encoded with a different character set.

Mistakes to avoid

  • Treating Base64 as encryption. Anyone can decode it in a second. Never use it to hide passwords or keys.
  • Losing characters when copying. A missing character changes the length and corrupts the end of the data.
  • Mixing alphabets. Feeding base64url to a strict standard decoder fails on - and _.

Working with images specifically? The Image to Base64 and Base64 to Image tools add previews and size options.

Frequently asked questions

Is Base64 a form of encryption?

No. Base64 is an encoding, not encryption. It has no key, and anyone can reverse it instantly, so it offers no protection for secrets.

Why is my Base64 longer than the original?

Base64 represents every 3 bytes with 4 characters, so the output is about one third larger than the input. Line wrapping and padding add a few more characters.

What is the difference between Base64 and base64url?

Base64url replaces + with - and / with _ so the result can sit safely inside URLs and file names, and it usually omits the = padding. JWTs use base64url.

Why does my decoded text look garbled?

Either the input was not text to begin with (for example an image), or it was encoded with a different character set than UTF-8. If the data is binary, this tool offers it as a file download instead.

Are my text and files uploaded anywhere?

No. Encoding and decoding run entirely in your browser with JavaScript, so tokens, keys and private files never leave your device.

More developer tools

Other free tools you might need next.

View all 24