Text to Base64

Encode text to Base64. Free Base64 encoder.

up to 5 MB; the bytes of the file are encoded as they are
Text bytes
Alphabet

Going the other way? Base64 to Text

Rate this tool

How useful was this tool?

Text to Base64

Type or paste into Text, or load the Example, and the result appears under Base64. To encode a file instead, choose one under or a file: up to 5 MB, encoded byte for byte as it is.

The options:

  • Encoding: how the text becomes bytes before it’s encoded. The choices are UTF-8, which nearly everything expects; UTF-16 little-endian (Windows, .NET); UTF-16 big-endian (Java); and Windows-1252 / Latin-1, one byte per character, the old btoa way. For UTF-16 you can also Start with a byte-order mark.
  • Alphabet: Standard (+ and /) or URL-safe (- and _), with or without Pad with = to a multiple of four.
  • Line breaks: none, every 76 characters (MIME), or every 64 (PEM).
  • As a data URL: the result is wrapped as a data: link, ready for an image source or a link.

Stats show the characters, the bytes, the Base64 length and the overhead. A small card shows exactly how the first bytes were turned into Base64 characters. Copy takes the result, and Clear starts over.

Everything runs in your browser, so neither text nor files are sent anywhere.

Example

Café ☕ in UTF-8 becomes:

Q2Fmw6kg4piV

That’s 6 characters, 9 bytes, and 12 Base64 characters: 33% larger. é takes two bytes in UTF-8 and ☕ takes three, which is why six characters become nine bytes.

How Base64 works

Base64 turns any bytes into 64 safe characters: A–Z, a–z, 0–9, + and /. It takes three bytes at a time, 24 bits, and cuts them into four groups of six bits. Each six-bit group is a number from 0 to 63, which picks one character.

The card on the page shows this for the first bytes of your text. For Hi!:

H        i        !
01001000 01101001 00100001     3 bytes
010010 000110 100100 100001    regrouped in sixes
18     6      36     33
S      G      k      h         →  SGkh

That’s the whole trick, and it’s why Base64 is always about a third larger than the original: every 3 bytes become 4 characters.

When the bytes don’t divide into threes, the last group is filled out and marked with =. “Café” is 5 bytes, so it becomes Q2Fmw6k=. One = means the last group had two bytes, and two == mean it had one.

Why the encoding matters

Base64 encodes bytes, not letters. Before text can be encoded, it has to become bytes, and different encodings produce different bytes. The same word gives five different results:

Encoding “Café” in Base64
UTF-8 Q2Fmw6k=
Windows-1252 / Latin-1 Q2Fm6Q==
UTF-16 little-endian QwBhAGYA6QA=
UTF-16 big-endian AEMAYQBmAOk=
UTF-16 LE with a byte-order mark //5DAGEAZgDpAA==

Whatever decodes the result must use the same encoding, or “Café” comes back as “Café” or worse. That’s why UTF-8 is the default. It’s what the web, email and nearly every API expect, so it decodes correctly everywhere.

Choose another encoding only when the receiving side needs it. A Windows or .NET program may expect UTF-16 little-endian, and a Java one big-endian. Windows-1252 reproduces what JavaScript’s old btoa() does: one byte per character. It can only write about 250 characters, so anything outside them, such as an emoji or Chinese, can’t be encoded. The tool names those characters instead of silently dropping them.

Standard or URL-safe

Standard Base64 uses + and /, which have special meanings in URLs and file names, and =, which has one in query strings. The URL-safe alphabet swaps them out:

  Standard URL-safe, no padding
<<???>> PDw/Pz8+Pg== PDw_Pz8-Pg

URL-safe Base64 without padding is what JSON Web Tokens use for each of their three parts, and what most links and file names need. Without =, a decoder works out the length itself, and most do.

Line breaks: MIME and PEM

Some formats want Base64 broken into lines:

  • Every 76 characters (MIME): email attachments and encoded email parts.
  • Every 64 characters (PEM): certificates and keys between -----BEGIN …----- and -----END …----- lines.

Everywhere else, including JSON, URLs, data URLs and HTTP headers, use none. A line break inside a value usually breaks it.

Data URLs and files

As a data URL wraps the result in a link that carries its own content:

data:text/plain;charset=utf-8;base64,Q2Fmw6k=

The charset part tells the browser which encoding the text uses. For a file, the file’s own type goes in instead, such as data:image/png;base64,…, ready to paste into an <img src> or a CSS url().

Data URLs are handy for small things: an icon, a tiny image in an email template, a test file. For anything larger, a normal file is better. A data URL is a third bigger, and the browser can’t cache it separately from the page it’s in. For images specifically, Image to Base64 shows a preview as well.

Base64 isn’t encryption

Anyone can decode Base64 in a second. It makes data safe to transport through systems that only handle text, not secret. A password or API key in Base64 is as exposed as it was in plain text.

FAQ

Why does another tool or btoa() give a different result?

Almost always the encoding. btoa() writes one byte per character, like Windows-1252, so for “Café” it gives Q2Fm6Q== rather than UTF-8’s Q2Fmw6k=, and it fails outright on characters such as € or emoji. Other differences come from the alphabet (+/ versus -_), padding, or line breaks.

How much bigger does Base64 make the data?

About 33%: 4 characters for every 3 bytes, plus up to two = at the end, and a little more if you add line breaks. The stats show the exact overhead for your text.

How do I do it in code?

  • JavaScript (Node.js): Buffer.from(text, 'utf8').toString('base64')
  • JavaScript (browser): encode to UTF-8 first: btoa(String.fromCharCode(...new TextEncoder().encode(text)))
  • Python: base64.b64encode(text.encode('utf-8')), or urlsafe_b64encode for the URL-safe alphabet
  • PHP: base64_encode($text), which encodes the string’s bytes, usually UTF-8

How do I decode Base64?

Use Base64 to Text.

Note: All processing is done client-side. We do not store or see your data.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us