ToolsPoint Guide · By Vishal Kalariya, Founder & Editor · Updated November 15, 2026

How to Encode and Decode Base64 (Text and Images)

What Base64 is, when to use it and how to encode or decode in the browser and in code.

Base64 converts binary data into 64 safe text characters so it can travel through email, JSON, URLs and HTML. It's encoding, not encryption.

Step-by-Step Instructions

  1. To encode text, paste it into the Base64 Encoder.
  2. To decode, paste the string into the Base64 Decoder.
  3. For images, use Image to Base64 to get a data URI.

In Code

// JavaScript (UTF-8 safe)
const b64 = btoa(String.fromCharCode(...new TextEncoder().encode('héllo')));
# Python
import base64; base64.b64encode('héllo'.encode()).decode()

When to Use It

  • Data URIs for small icons in CSS/HTML.
  • HTTP Basic Auth headers.
  • Embedding binary data in JSON.
  • Email attachments (MIME).

When Not to

Never use Base64 to hide secrets — anyone can decode it. Avoid it for large images: it adds about 33% to size and can't be cached separately.

What Does the "=" at the End Mean?

Base64 turns every 3 bytes into 4 characters. When the input isn't a multiple of 3 bytes, one or two = signs are added as padding so the length is a multiple of 4. Some systems (like JWTs) drop the padding; decoders can usually add it back.

What Is Base64URL?

Standard Base64 uses + and /, which have special meaning in URLs. Base64URL replaces them with - and _ and often omits padding, so the result can sit safely in a URL or filename. JSON Web Tokens use Base64URL.

How Do I Decode Base64 in the Terminal?

On macOS and Linux, run echo 'SGVsbG8=' | base64 --decode. On Windows PowerShell, use [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('SGVsbG8=')).

How Do I Embed an Image With Base64?

Convert the image to a data URL such as data:image/png;base64,iVBORw0… and use it as the src of an <img> tag or in CSS background-image. This saves an HTTP request for tiny icons, but for larger images a normal file is better because it can be cached separately and is about 33% smaller.

Frequently Asked Questions

Why does Base64 end with = signs?
They're padding so the output length is a multiple of 4.
Is Base64 a form of encryption?
No. Anyone can decode Base64 instantly, so it must never be used to protect passwords or secrets.
Why is my Base64 output about a third bigger?
Four characters represent three bytes, so encoded data is about 33% larger than the original.

Try it now: Base64 Encoder

Encode text as Base64. Free, fast and private.

Open Base64 Encoder →

Get new free tools in your inbox

One short email a month with new tools, guides and productivity tips. No spam — unsubscribe anytime.

By subscribing you agree to receive emails from ToolsPoint Online. See our Privacy Policy.