Skip to main content
Base64 Encoder: How to Encode Text, Images & Files (Practical Guide 2026)
0%
Esc

Base64 Encoder: How to Encode Text, Images & Files (Practical Guide 2026)

Base64 Encoder: How to Encode Text, Images & Files (Practical Guide 2026)

Quick Answer: A Base64 encoder turns text or binary data into a string made of 64 safe characters (A–Z, a–z, 0–9, + and /), so it can travel through systems that only handle text. For example, "Hello, World!" encodes to SGVsbG8sIFdvcmxkIQ==. Encoded data is about 33% larger than the original. Use the free EasifyMe Base64 Encoder to encode text, images or files instantly.

Key Takeaways

  • Base64 is an encoding, not encryption. Anyone can decode it.
  • Every 3 bytes of input become 4 Base64 characters, so output is about 33% larger.
  • The "=" signs at the end are padding, added when the input is not a multiple of 3 bytes.
  • Use URL-safe Base64 (with - and _ instead of + and /) for URLs, filenames and tokens.
  • Inline images as data URIs only when they are small; large ones hurt page speed.

This is a hands-on guide. If you want the theory first, read our explainer on what Base64 encoding is and how it works.

Where Developers Use Base64 Encoding

Use case

Why Base64 helps

Example

Data URIs in HTML/CSS

Embed a small image directly in code

data:image/png;base64,iVBOR...

HTTP Basic Authentication

Headers must be plain text

Authorization: Basic dXNlcjpwYXNzMTIz

Email attachments (MIME)

Email was designed for text

Attachments are Base64-encoded behind the scenes

Binary data in JSON

JSON has no binary type

{"file": "JVBERi0xLjQK..."}

Tokens and IDs

Compact, text-safe representation

JWTs use URL-safe Base64

 

How to Encode Text to Base64 Online (Step by Step)

  1. Open the free Base64 Encoder.
  2. Choose what to encode: text, an image or a file.
  3. Paste your text, or drop in your image or file.
  4. Pick options if you need them, such as URL-safe output or a ready-made data URI for images.
  5. Copy the encoded result.

The encoding runs in your browser, so the text or file you encode is not uploaded anywhere. That is important when you are working with credentials or private documents.

Worked Examples

Example 1: Encoding a short string

Input

Base64 output

Notes

Man

TWFu

3 bytes in, 4 characters out, no padding

Ma

TWE=

2 bytes, one padding character

M

TQ==

1 byte, two padding characters

Hello, World!

SGVsbG8sIFdvcmxkIQ==

13 bytes, two padding characters

 

Padding keeps the output length a multiple of 4, which lets decoders know exactly where the data ends.

Example 2: A Basic Auth header

HTTP Basic Authentication sends username:password encoded in Base64. The credentials user:pass123 become dXNlcjpwYXNzMTIz, sent as:

Authorization: Basic dXNlcjpwYXNzMTIz

This shows clearly why Base64 is not security: anyone who sees the header can decode it in a second. Basic Auth must only ever be used over HTTPS.

Example 3: Embedding a small image as a data URI

A 1 KB icon encoded as Base64 can go straight into your HTML or CSS:

Icon

This saves one network request, which can help for tiny icons. For anything larger than a few kilobytes, a normal image file is better: it can be cached separately, and it avoids the 33% size overhead. Shrink images first with the Image Compressor before deciding.

Try it free: Encode text, images and files, with URL-safe and data URI options, in the free Base64 Encoder.

Example 4: Non-English text

Base64 works on bytes, so text is first converted to bytes, normally with UTF-8. The Hindi word नमस्ते is 18 bytes in UTF-8 and encodes to 4KSo4KSu4KS44KWN4KSk4KWH. Make sure the tool or code you use encodes text as UTF-8, or accented and non-Latin characters may break.

How to Encode Base64 in Code

// JavaScript (browser) - ASCII text only

btoa("Hello, World!");

 

// JavaScript (browser) - any Unicode text

btoa(String.fromCharCode(...new TextEncoder().encode("नमस्ते")));

 

// Node.js

Buffer.from("Hello, World!", "utf8").toString("base64");

 

# Python

import base64

base64.b64encode("Hello, World!".encode("utf-8")).decode()

 

# Linux / macOS terminal (-n stops echo adding a newline)

echo -n "Hello, World!" | base64

The browser's btoa() throws an error on characters outside the Latin-1 range, which is why the Unicode version encodes to UTF-8 bytes first. In the terminal, forgetting -n adds a newline to the input and changes the result.

How Long Will the Base64 Output Be?

You can predict the encoded length exactly. For n bytes of input:

Base64 length = 4 × ceil(n ÷ 3) characters

Input size

Base64 output (characters)

1 KB (1,024 bytes)

1,368

10 KB

13,656

100 KB

136,536

1 MB

about 1.4 million

 

Email (MIME) encoding also inserts a line break every 76 characters, which adds a little more. This is why embedding large files as Base64 in JSON or HTML quickly bloats payloads and pages.

Base64 vs Other Text Encodings

Encoding

Size overhead

Characters used

Typical use

Hex (Base16)

+100%

0–9, a–f

Hashes, colour codes, debugging

Base32

+60%

A–Z, 2–7

Case-insensitive codes, such as 2FA secrets

Base64

+33%

A–Z, a–z, 0–9, + /

Data URIs, email, JSON, tokens

URL (percent) encoding

Varies

%XX for special characters

Making text safe inside URLs

 

Base64 gives the smallest output of the common text-safe encodings, which is why it is the default choice for binary data.

Standard vs URL-Safe Base64

Standard Base64 uses + and /, which have special meanings in URLs and file paths. URL-safe Base64 (defined in RFC 4648) swaps them:

Standard

URL-safe

+

- (hyphen)

/

_ (underscore)

= padding

Often removed

 

Use URL-safe encoding for anything that goes in a URL, a filename, a cookie or a token. JSON Web Tokens, for example, always use URL-safe Base64 without padding.

Common Mistakes to Avoid

  • Treating Base64 as encryption. Never "hide" passwords or API keys with it.
  • Encoding large images inline. Bigger pages and no caching usually outweigh the saved request.
  • Mixing standard and URL-safe formats. A decoder expecting one may reject the other.
  • Double-encoding. Encoding an already-encoded string produces valid but useless output.
  • Ignoring character encoding. Always encode text as UTF-8 unless a system says otherwise.

Related Developer Tools

To reverse the process, use the Base64 Decoder. If your encoded data sits inside an API response, tidy it with the JSON Formatter and check it with the JSON Validator. You can browse everything else in our developer tools hub.

Frequently Asked Questions

What does a Base64 encoder do?

It converts text or binary data into a string of 64 text-safe characters, so the data can pass safely through systems designed for text, such as email, JSON, URLs and HTTP headers.

Why does Base64 output end with = or ==?

The equals signs are padding. Base64 works in groups of 3 bytes; when the input does not divide evenly, one or two = characters are added so the output length is a multiple of 4.

How much bigger does Base64 make a file?

About 33% bigger, because every 3 bytes become 4 characters. A 30 KB image becomes roughly 40 KB once encoded.

Is Base64 encoding secure?

No. Base64 is reversible by anyone and provides no protection. Use proper encryption, such as HTTPS or AES, to protect sensitive data.

Can I encode an image to Base64 for free?

Yes. The EasifyMe Base64 Encoder converts images and files to Base64 or a ready-to-use data URI for free, directly in your browser.

What is the difference between Base64 and Base64URL?

Base64URL is a variant that replaces + with - and / with _, and usually drops the = padding. This makes the output safe to use in URLs, filenames and tokens such as JWTs.

How do I turn an image into a data URI?

Encode the image to Base64, then add the prefix for its type, such as data:image/png;base64, followed by the encoded string. The EasifyMe Base64 Encoder can produce the full data URI for you.

Can I Base64 encode a PDF or other file?

Yes. Base64 works on any file, including PDFs, Word documents and ZIP archives. The encoded PDF string starts with JVBERi0, and it will be about a third larger than the original file.

Why does my Base64 output differ between tools?

Usually because of a hidden newline or space in the input, different character encodings, or one tool using URL-safe output. Trim the input, use UTF-8 and check the Base64 variant.

TOOLS MENTIONED IN THIS POST

Try These EasifyMe Tools

Free, instant, no signup required. Open any tool and start using it right away.