How the Base64 Encoder works

Base64 turns bytes into text using 64 safe characters: A–Z, a–z, 0–9 and two more. Every 3 bytes become 4 characters, so the output is about 33% larger than the input. When the input length is not a multiple of 3, the last group is completed with one or two = padding characters.

Text is first converted to UTF-8 bytes by the tool's own encoder, so characters such as é, and emoji are encoded correctly (the browser's btoa() function fails on them). In File mode the file is read as raw bytes, so images, PDFs and any other file type are encoded exactly.

The URL-safe alphabet (RFC 4648 section 5) replaces + with - and / with _, so the result can be used in URLs, file names and JSON Web Tokens; padding is usually omitted there. Wrapping at 76 characters matches the MIME format used in email. A data URI adds a data:<type>;base64, prefix so the file can be embedded directly in HTML or CSS.

How to use the Base64 Encoder

  1. Under Encode, choose Text to type or paste text, or File to encode a file from your device.
  2. For text, paste it into the input box or select Load example. For a file, select Choose file or drag the file onto the box. Files up to 10 MB are supported.
  3. Pick the Alphabet (Standard or URL-safe), and tick Omit = padding or Wrap lines at 76 characters if you need them. In File mode, set File output to Base64 only or Data URI.
  4. Select Encode to Base64, or press Ctrl + Enter (Cmd + Enter on a Mac). A chosen file is encoded straight away.
  5. Copy the result or download it as a .txt file.

Example

The text:

Hello, World! Café ☕

is encoded to standard Base64 as:

SGVsbG8sIFdvcmxkISBDYWbDqSDimJU=

With the URL-safe alphabet and padding omitted it becomes SGVsbG8sIFdvcmxkISBDYWbDqSDimJU. A 1×1 transparent PNG file encoded as a data URI starts with data:image/png;base64,iVBORw0KGgo.

Common use cases

  • Embedding a small icon or logo in HTML or CSS as a data URI so it loads without an extra request.
  • Putting binary content, such as a certificate or a PDF, into a JSON payload or an XML field that only accepts text.
  • Creating HTTP Basic authentication values by encoding username:password.
  • Producing URL-safe Base64 without padding for tokens, file names or query string values.
  • Checking what an application should send when an API expects a Base64-encoded file.

Common errors and how to fix them

Accented characters or emoji come back wrong after a round trip
Base64 encodes bytes, not characters, so text has to become bytes first. This tool uses UTF-8. If the system decoding your output assumes a different character set such as Latin-1, those characters will be corrupted, so make sure both sides agree on UTF-8.
The output will not work in a URL or a filename
Standard Base64 uses + and / and pads with =, all of which are unsafe in URLs. Switch to the URL-safe alphabet, which uses - and _ instead.
The encoded string is larger than the original
That is expected. Base64 represents every 3 bytes as 4 characters, so the result grows by about a third. It is a transport encoding, not compression, and it is not encryption.

Frequently asked questions

Why does btoa() fail on my text when this tool works?

The browser's btoa() function only accepts characters up to U+00FF, so accented letters outside Latin-1, symbols such as € and emoji throw an error. This tool converts the text to UTF-8 bytes first and encodes those bytes, which is what other systems expect when they decode Base64 back to UTF-8 text.

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

Standard Base64 uses + and / as its last two characters. Those have special meanings in URLs and file paths, so the URL-safe alphabet (RFC 4648) uses - and _ instead. URL-safe Base64 is used in JSON Web Tokens and is often written without the = padding.

When should I omit padding?

Padding (one or two = characters at the end) makes the length a multiple of 4. Many decoders do not need it, and formats such as JWT leave it out. Keep it if the receiving system uses a strict decoder.

What is a data URI?

A data URI puts a file's content directly into a URL, for example data:image/png;base64,iVBORw0KGgo... It can be used as an image src in HTML or a url() in CSS. The MIME type comes from your browser or, if it does not know it, from the file's content or extension. Data URIs always use standard Base64 with padding and no line breaks.

How much bigger is Base64 than the original?

About 33% bigger: every 3 bytes become 4 characters. A 300 KB image becomes about 400 KB of Base64 text, so data URIs are best kept for small files.

Is my file uploaded?

No. The file is read with JavaScript in your browser and encoded on your device. Nothing is sent to our server.