base64 encoding converter tutorial

How to Encode and Decode Base64 Online

UseEasyTool Team Developer Tools Expert
July 22, 2026 8 min read

Base64 is one of the most widely used encoding schemes in computing. Whether you are embedding images in HTML, transmitting binary data over text-based protocols, or working with API authentication, understanding how to encode and decode Base64 is an essential skill. In this comprehensive guide, we will cover everything you need to know about Base64 encoding and decoding, including how to use our free online Base64 encoder/decoder tool.

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that converts binary data into a string of ASCII characters. It works by dividing the input data into groups of three bytes (24 bits) and then splitting each group into four sets of six bits. Each six-bit group is mapped to a character from a set of 64 characters: the uppercase letters A through Z, lowercase letters a through z, digits 0 through 9, plus + and /. The = character is used for padding when the input length is not a multiple of three bytes.

The result is a text representation that is safe for transmission through channels that only reliably support text content, such as email, HTML, and JSON.

Try This Tool

Put what you just read into practice — open the tool now.

Open Tool →

Why Do We Need Base64 Encoding?

Base64 solves a fundamental problem in computing: many communication channels and data formats are designed to handle text, not raw binary data. Here are the primary reasons developers use Base64 encoding:

  • Data integrity over text protocols: Email systems (SMTP), HTTP headers, and URL parameters can corrupt or misinterpret raw binary data. Base64 ensures that binary content travels safely through these channels.
  • Embedding resources in text formats: You can embed images directly in HTML or CSS using Base64-encoded data URIs, eliminating the need for separate image files.
  • API and web authentication: HTTP Basic Authentication encodes credentials as username:password in Base64 before sending them in the Authorization header.
  • Storing complex data in cookies and tokens: JWT (JSON Web Tokens) use Base64URL encoding to represent header, payload, and signature sections as compact strings.
  • XML and JSON transport: Binary files can be wrapped in Base64 strings to be included in XML documents or JSON payloads without breaking the format.

How Base64 Encoding Works: A Step-by-Step Example

Let's walk through how the word Man is encoded into Base64. The ASCII values for M, a, and n are 77, 97, and 110 respectively.

Step 1 -- Convert each character to its 8-bit binary representation:

M  = 01001101
a  = 01100001
n  = 01101110

Step 2 -- Combine the three bytes into a single 24-bit sequence:

010011010110000101101110

Step 3 -- Split into four 6-bit groups:

010011 010110 000101 101110

Step 4 -- Convert each 6-bit group to its decimal value and look up the corresponding Base64 character:

19 -> T
22 -> W
5  -> F
46 -> u

So Man encodes to TWFu. When the input length is not a multiple of three, padding with = characters is added to make the output length a multiple of four.

How to Encode and Decode Base64 Online

Using our free online Base64 encoder and decoder, you can convert text to Base64 and back in seconds. Here is how:

Encoding Text to Base64

  1. Navigate to the Base64 Encoder/Decoder tool on UseEasyTool.
  2. In the input text area, paste or type the text you want to encode. For example, type Hello, World!
  3. Select the Encode option (this is typically the default mode).
  4. Click the Convert or Encode button.
  5. The output area will display the Base64-encoded result: SGVsbG8sIFdvcmxkIQ==
  6. Click Copy to copy the result to your clipboard.

Decoding Base64 to Text

  1. Open the Base64 tool.
  2. Paste your Base64 string into the input area.
  3. Select the Decode option.
  4. Click Convert or Decode.
  5. The original text or data will appear in the output area.

Common Use Cases for Base64 Encoding

Embedding Images in HTML and CSS

One of the most popular uses of Base64 is embedding small images directly in HTML or CSS files using data URIs. This reduces the number of HTTP requests and is particularly useful for small icons and logos.

<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." alt="Icon">

Data Transmission and APIs

When sending binary files (such as images or PDFs) through REST APIs, Base64 encoding allows the binary content to be included as a string field in JSON payloads. Many cloud services, including AWS S3 and SendGrid, accept Base64-encoded file uploads.

HTTP Basic Authentication

APIs that use Basic Auth require you to send credentials in Base64 format. The header format is:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

Where dXNlcm5hbWU6cGFzc3dvcmQ= is the Base64 encoding of username:password.

Email Attachments (MIME)

Email protocols like SMTP are designed for text. MIME (Multipurpose Internet Mail Extensions) uses Base64 to encode binary attachments so they can be sent as part of the email body.

Encoding Base64 Manually in Programming Languages

While our online tool handles the conversion instantly, you may sometimes need to encode or decode Base64 in your code. Here are quick examples in popular languages:

JavaScript / TypeScript

// Encode
const encoded = btoa('Hello, World!');
console.log(encoded); // "SGVsbG8sIFdvcmxkIQ=="

// Decode
const decoded = atob('SGVsbG8sIFdvcmxkIQ==');
console.log(decoded); // "Hello, World!"

Python

import base64

# Encode
encoded = base64.b64encode(b'Hello, World!')
print(encoded)  # b'SGVsbG8sIFdvcmxkIQ=='

# Decode
decoded = base64.b64decode(b'SGVsbG8sIFdvcmxkIQ==')
print(decoded)  # b'Hello, World!'

Java

import java.util.Base64;

// Encode
String encoded = Base64.getEncoder().encodeToString("Hello, World!".getBytes());
System.out.println(encoded); // "SGVsbG8sIFdvcmxkIQ=="

// Decode
byte[] decoded = Base64.getDecoder().decode("SGVsbG8sIFdvcmxkIQ==");
System.out.println(new String(decoded)); // "Hello, World!"

Base64 Variants You Should Know

While standard Base64 is the most common, there are important variants:

  • Base64URL: Replaces + with - and / with _, and removes padding. Used in JWT tokens and URL-safe contexts.
  • Base32: Uses a 32-character alphabet (A-Z and 2-7). Produces longer output but is more human-readable. Used in Google Authenticator TOTP codes.
  • Base16 (Hex): Uses only hexadecimal characters (0-9 and A-F). Each byte becomes two characters. Simple and widely used.

Limitations of Base64 Encoding

While Base64 is incredibly useful, it is important to understand its limitations:

  • Size increase: Base64 encoded data is approximately 33% larger than the original binary data. Three bytes of input become four bytes of output. For large files, this can significantly increase bandwidth and storage requirements.
  • Not encryption: Base64 is an encoding scheme, not encryption. Anyone can decode Base64 strings. Never use it to protect sensitive data. Always combine it with proper encryption (such as AES) for security.
  • No compression: Base64 does not compress data. If file size is a concern, compress the data first (using gzip, for example) and then encode the compressed result.
  • Processing overhead: Encoding and decoding require CPU resources. For very high-throughput systems, this overhead should be considered in performance planning.

Tips for Working with Base64 Effectively

  • Always validate Base64 input before decoding to avoid errors. Our online tool handles validation automatically.
  • When encoding large files, consider chunking the input to avoid memory issues.
  • Use Base64URL variant when the encoded string will appear in URLs or query parameters.
  • For repeated encoding/decoding in applications, use built-in language libraries rather than custom implementations for better performance and security.

Conclusion

Base64 encoding is a fundamental technique that every developer encounters regularly. From embedding images in web pages to authenticating API requests, it bridges the gap between binary data and text-based systems. Whether you need a quick one-off conversion or are debugging an encoding issue in your application, our free Base64 encoder/decoder tool provides a fast, reliable way to encode and decode Base64 online without installing anything.

Try it today -- visit the Base64 Encoder/Decoder and convert your first string in seconds.

Related Articles

Base64 Encoding Explained

A comprehensive guide to Base64 encoding principles and use cases.

Base64 vs URL Encoding: When to Use Which?

Understand the key differences between Base64 and URL encoding.

View All Articles

Browse our complete collection of developer tutorials, guides, and tips.