Home / Developer tools / Base64 encode

Base64 Encode

Type or paste text, or choose any file, and get it back as Base64. Set the line length, the alphabet and the padding, or encode a list line by line.

Try:

Everything runs in your browser. Your data is not sent to our server.

What Base64 encoding does

Base64 turns any data, text or binary, into a string made of only 64 safe characters: A-Z, a-z, 0-9, + and /, with = used as padding. Such a string can travel through systems that only handle plain text, such as email, JSON, XML, HTML attributes, URLs and HTTP headers. This page encodes text as UTF-8 first, so accents, Arabic, Chinese and emoji work correctly, and then converts the bytes. You can also encode a file of any type.

Example

Hello, World!

encodes to:

SGVsbG8sIFdvcmxkIQ==

and the text café (the é takes two bytes in UTF-8) becomes Y2Fmw6k=. To see exactly how the bits are regrouped, open the text to Base64 converter, which shows every step.

Options

  • Line breaks. None (one long line, best for APIs and data URIs), every 76 characters (MIME, used in email, RFC 2045) or every 64 characters (PEM, used in certificates and keys).
  • Remove padding. Drops the trailing = signs. Some systems, such as JWT, expect no padding.
  • URL-safe alphabet. Uses - and _ in place of + and /. See the Base64URL encoder for details.
  • Encode line by line. Every line is encoded separately and the lines are kept, useful for lists of values.
  • Encode a file. Choose a file (up to 20 MB) and its bytes are encoded exactly as they are. For images, the image to Base64 converter also gives a ready data URI.

How much bigger does Base64 get?

Every 3 bytes become 4 characters, so the output is about 33% larger than the input (plus a few percent more with line breaks). Base64 is a way to carry data safely, not a way to compress it.

Encode in code

// JavaScript (browser)
btoa(unescape(encodeURIComponent('café')));   // "Y2Fmw6k="

// Node.js
Buffer.from('café', 'utf8').toString('base64');

// PHP
base64_encode('café');

# Python
import base64
base64.b64encode('café'.encode('utf-8')).decode()

# Shell
printf 'café' | base64

Common mistakes

  • Treating Base64 as encryption. Anyone can decode it. Do not use it to hide passwords or tokens.
  • Calling btoa() on Unicode text. It throws an error for characters above U+00FF. Convert to UTF-8 bytes first, as this tool does.
  • Adding a trailing newline. echo hello | base64 encodes the newline too. Use printf or echo -n.

Privacy

The encoding runs in your browser. Your text and files are not uploaded, stored or logged.

Next: the Base64 decoder reverses the result. The guide What is Base64? explains the alphabet, padding and variants. For links, see the URL encoder.

Frequently asked questions

How do I encode text to Base64?

Paste the text into the box. It is encoded at once. Press Copy to use the result.

Why does Base64 end with = or ==?

Base64 works in groups of 3 bytes. If the last group is short, one or two = signs pad the output to a multiple of 4 characters.

Can I encode a file to Base64?

Yes. Use Encode a file and choose any file up to 20 MB. It is read in your browser and not uploaded.

Is Base64 encryption?

No. It is a reversible encoding that anyone can decode. It does not protect data.

Why is the Base64 output longer than the input?

Four characters are used for every three bytes, so the output is about one third larger.