Skip to content
cliplimeClipLime

Base64 encode

Turn text or any file into Base64 as you type.

Your text and files stay in your browser

Any language and emoji work. The text is turned into bytes first, then into Base64.

0 characters, 0 lines

UTF-8 is right unless you know a system needs something else.

Options

Writes - and _ instead of + and /, so the result is safe in URLs, file names and JWTs.

Standard Base64 pads to a multiple of 4 characters with =. Turn it off for the shorter form many APIs expect.

Break the result into lines. 76 is what email (MIME) uses, 64 is what PEM files use.

Adds data:type;base64, in front, so the result can go straight into an img tag or a CSS url().

At a glance

What it does
Converts text or any file into Base64 as you type, ready to copy or save.
Text encodings
UTF-8 by default, plus UTF-16 little endian and Latin-1 for systems that need them.
Output styles
Standard or URL-safe, with or without padding, on one line or wrapped at 64 or 76 characters.
Data URLs
Add the data:type;base64, prefix with one switch, for an img tag or a CSS url().
Files
Any type, up to 50 MB. The result can be copied or saved as a text file.
Privacy
Your text and files never leave your browser.

How to do it

  1. 1

    Type, paste or load text

    Write in the box, paste from anywhere, or load a text file with the Load a file button.

  2. 2

    Or switch to a file

    Choose A file at the top, then pick any file. Its size and detected type are shown.

  3. 3

    Choose the style

    Pick the URL-safe alphabet, drop the padding or set a line length to match what the receiving system expects.

  4. 4

    Copy or download

    Press Copy for the result, or Download to save it as a text file.

How text becomes Base64, step by step

Take the text Hi!. In UTF-8 its three characters are the bytes 48 69 21, which are 01001000 01101001 00100001 in binary. Base64 regroups those 24 bits into four groups of 6 bits: 010010 000110 100100 100001. Each group is a number from 0 to 63, which picks a character from the Base64 alphabet: 18 is S, 6 is G, 36 is k and 33 is h. The result is SGkh.

When the text is not a multiple of 3 bytes long, the last group is short and the output is padded with =. Hi becomes SGk=, and H becomes SA==.

Why two tools can give different results for the same text

If two Base64 strings differ, one of these is almost always the reason:

  • A newline was included. On the command line, echo "hello" | base64 encodes the newline that echo adds. Use echo -n or printf to leave it out.
  • A different text encoding. UTF-8, UTF-16 and Latin-1 turn the same text into different bytes. Only plain ASCII text gives the same bytes in UTF-8 and Latin-1.
  • A different alphabet or padding. URL-safe output uses - and _, and some tools drop the = characters.
  • Line breaks. Some tools wrap the output every 76 characters, as email does. Others write one long line.

The options here let you reproduce each of those, so you can match the tool or library you need to be compatible with.

Encoding for PowerShell and for URLs

PowerShell's -EncodedCommand expects the command as Base64 of UTF-16 little endian text. Choose that text encoding and leave the other options at their defaults.

For a value that will sit inside a URL, such as a token in a query string, switch on the URL-safe alphabet and usually switch off the padding, so no character needs percent-encoding. To encode a whole URL instead, use the URL encoder.

Questions people ask

Why does btoa() throw an error on my text?

btoa() only accepts characters in the Latin-1 range. Text with characters such as 你 or an emoji has to be converted to UTF-8 bytes first. This tool does that step for you.

What is the Base64 of an empty string?

An empty string. Nothing in, nothing out.

Should I keep the = padding?

Keep it unless the system you are sending to says otherwise. Standard Base64 includes it, and most decoders accept the text without it, but a few strict ones do not.

How do I encode text for a PowerShell encoded command?

Choose UTF-16 little endian as the text encoding. PowerShell reads the Base64 as UTF-16LE text, and the default UTF-8 would give it a string it cannot run.

Can I encode a file instead of text?

Yes. Switch to A file and choose any file up to 50 MB. To go the other way and save a Base64 string back as a file, use the Base64 decoder.