Mr. Tools

How to

How to use Base64 Encode / Decode

Enter text and it becomes Base64 right away. You can also choose an image or another file. Switch the action to Decode to get the original text back. What you enter is never sent anywhere and stays on this device.

Base64 Encode / Decode thumbnailBase64 Encode / Decode thumbnail
Steps
3 steps
Guide
With screenshots
Content
Notes and FAQ

Use Cases

When to use it

  • Read Base64 in an API response or a config file
  • Embed a small image in HTML or CSS
  • Decode Shift_JIS or ISO-2022-JP Base64, such as in an email header
  • Check what is inside the Base64 in an authorization header

Capabilities

What this tool can do

  • Turn text into Base64 and Base64 back into text
  • Choose the character encoding from UTF-8, Shift_JIS, EUC-JP, and ISO-2022-JP (Auto detect is also available when decoding)
  • Turn an image or another file into Base64 or a data URL
  • Switch to the URL-safe format (- and _, no =)
  • Convert each line separately
  • Offer to switch to Decode when you enter text that looks like Base64
  • Show why above the input box when text cannot be decoded

Steps

Steps

The order of operations and checkpoints are listed so you can proceed while looking at the screen.

STEP 1

Enter text or choose a file

Paste your text into "Text to convert" on the left. While the box is empty, you can also press "Paste" in the bar at the bottom. To turn an image or another file into Base64, press "Choose a file". There is no convert button: the result appears on the right as soon as you enter something.

Screen with the input box and the result box outlined in red

Checkpoints

  • A result appears in "Converted result" on the right

Where to look on screen

01
Paste, sample, and file

"Insert sample" puts in "こんにちは" (Japanese for "hello"). When Decode is selected, it puts in a Base64 sample instead. "Choose a file" appears only when encoding.

Screen with "Paste", "Insert sample", and "Choose a file" in the bottom bar outlined in red
02
When you choose a file

The file name and size appear above the input box. Turn on "Make it a data URL (data:…;base64,)" and the type, such as data:image/png;base64, is added at the start. "Remove file" takes you back to entering text.

Screen with the file name and the data URL switch outlined in red

STEP 2

Choose the action and character encoding

Choose "Encode" to turn text into Base64, or "Decode" to turn Base64 back into the original. Unless the place you are sending it to asks for something else, keep the character encoding on UTF-8.

Screen with the action and character encoding outlined in red

Checkpoints

  • The action matches what you want to do
  • You chose the character encoding the receiving side asks for

Where to look on screen

01
Action and Swap

Press "Swap" and the result moves to the left box and the action switches to the opposite one. Use it to check that the text comes back correctly.

Screen with the action and Swap outlined in red
02
Character encoding

Choose from UTF-8, Shift_JIS, EUC-JP, and ISO-2022-JP. When decoding, you can also choose Auto detect.

Screen with the character encoding outlined in red
03
Line by line and URL-safe format

"Convert line by line" converts each line separately. "URL-safe format (- and _, no =)" changes + to - and / to _, and leaves off the = at the end.

Screen with Convert line by line and URL-safe format outlined in red

STEP 3

Check the result and copy it

Press "Copy" in "Converted result" on the right to copy the result. If you enter Base64 text while Encode is selected, "Switch to decode" appears above the input box. If you enter text that cannot be decoded, a red bar above the input box tells you why.

Screen with the result box outlined in red

Checkpoints

  • The result is not cut off partway
  • No red bar has appeared

Where to look on screen

01
Copy

Copies the result in the right box.

Screen with "Copy" in the result box outlined in red
02
Prompt to decode

Appears when you try to encode text that looks like Base64. Press it to switch to Decode.

Screen with the prompt to switch to decode outlined in red
03
Bar when it cannot decode

It tells you why, for example "Cannot read this as Base64 or as the selected character encoding."

Screen with the red bar above the input box outlined in red

How does the character encoding change the result?

We converted the sample "こんにちは" (Japanese for "hello") with each of the four character encodings. The same text gives a different result every time.

Results for "こんにちは"
Character encodingBase64 result
UTF-844GT44KT44Gr44Gh44Gv
Shift_JISgrGC8YLJgr+CzQ==
EUC-JPpLOk86TLpMGkzw==
ISO-2022-JPGyRCJDMkcyRLJEEkTxsoQg==

Unless the receiving side asks for something else, choose UTF-8. Decode starts on Auto detect, so grGC8YLJgr+CzQ==, made with Shift_JIS, still comes back as "こんにちは".

How much longer does Base64 make it?

Original dataOriginal sizeBase64 length (characters)
tools5 B8
こんにちは (UTF-8)15 B20
300 English letters300 B400
16 × 16 pixel PNG image107 B144

The result is about 1.33 times the original. Each Japanese hiragana character takes 3 B in UTF-8, so even 5 characters become 20. Turning an image into a data URL also adds the 22 characters of data:image/png;base64, at the start.

What does "Convert line by line" change?

We converted two lines, "apple" and "orange".

SettingResult
OffYXBwbGUKb3Jhbmdl
On (/ marks a line break)YXBwbGU= / b3Jhbmdl

When it is off, the whole text, line breaks included, is converted as one value. Turn it on when you want each line handled as a separate value.

What if it does not work?

What happensWhyHow to fix it
You get garbled text like 縺薙s縺ォ縺。縺ッYou chose a different character encoding from the one used to encodeSet the character encoding back to Auto detect, or choose the one used to encode
"Cannot read this as Base64 or as the selected character encoding." appearsThe text contains characters that Base64 does not useCheck for extra characters
The last character becomes �The Base64 text is cut off partwayCopy the whole original text again
"Cannot encode with the selected character encoding." appearsSome characters cannot be written in the chosen character encoding (emoji in Shift_JIS, half-width katakana in ISO-2022-JP, and so on)Switch to UTF-8

With Shift_JIS, the "〜" typed on a Mac is converted as "~", the same as on Windows.

Notes

Notes

Important points are grouped with reasons so you can make decisions before using the tool.

Character encoding

Decode with the same character encoding you encoded with

With a different one, you may get garbled text without any error. Decode starts on Auto detect.

Encryption

Base64 is not encryption

Anyone can decode it, so it cannot protect passwords or anything else you want to keep secret.

Files

You can also turn an image or other file into something you can put in HTML

Choose a file and turn on "Make it a data URL (data:…;base64,)". You can then write the result straight into an img src.

FAQ

Questions about Base64 Encode / Decode

Questions that make decisions easier before use are summarized first.

Can it convert non-English text and emoji?

Yes. With UTF-8, text in any language, including Japanese, and emoji convert and come back correctly. If you choose a character encoding that cannot represent emoji, such as Shift_JIS, you see "Cannot encode with the selected character encoding."

Can it turn an image or another file into Base64?

Yes. While the input box is empty, press "Choose a file". Turn on "Make it a data URL (data:…;base64,)" and a PNG image starts with data:image/png;base64,, so you can write it straight into an img src.

How much longer does Base64 make it?

The result has about 1.33 times as many characters as the original data. For example, "こんにちは" (Japanese for "hello"), which is 15 B in UTF-8, becomes 20 characters.

What if the text comes out garbled?

You are decoding with a different character encoding from the one used to encode. Set the character encoding for Decode to Auto detect, or choose the one used to encode.

Can it decode Base64 that contains line breaks?

Yes. Base64 broken across lines is decoded as one value, with the line breaks removed. If each line is a separate value, turn on "Convert line by line".

Is what I enter sent anywhere?

No. The conversion happens in your browser. The text you enter stays only in this device's browser, so you can pick up where you left off when you open the page again.

Next guides

Related guides

Related guides are listed next so you can continue without getting lost.