Base64 Encoder/Decoder

Encode text to Base64 format and decode Base64 strings to plain text

Base64 Encoder/Decoder

Convert text and files to/from Base64

Mode
encode
Input Size
0 B
Output Size
0 B
Size Change
0%
0 B
0 B

Base64 encoding converts binary data to ASCII text using 64 characters (A-Z, a-z, 0-9, +, /). It increases data size by approximately 33% but ensures safe transmission over text-based protocols.

Standard
A-Z, a-z, 0-9, +, /
URL-safe
Uses - and _ instead
Padding
= for alignment
Size
~33% larger

About Base64 Encoding

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It's commonly used when binary data needs to be transmitted over media designed to handle text.

Key aspects of Base64 encoding:

  • Character Set: Base64 uses a set of 64 characters (A-Z, a-z, 0-9, + and /) plus a padding character (=).
  • Padding: The equals sign (=) is used as padding at the end of encoded data to make the length a multiple of 4.
  • Expansion: Base64 encoding increases the size of data by approximately 33% (4 characters for every 3 bytes).
  • Universally Supported: Almost all programming languages have built-in functions to encode and decode Base64.

This tool performs all encoding and decoding in your browser, ensuring your data remains private and secure.

Base64 Examples and Use Cases

Here's a simple example of Base64 encoding:

Plain TextBase64 Encoded
Hello, World!SGVsbG8sIFdvcmxkIQ==
HelloSGVsbG8=
Base64QmFzZTY0

Common Use Cases for Base64 Encoding

Use CaseDescription
Email AttachmentsMIME format uses Base64 to encode binary attachments in emails
Data URIsEmbedding images and other resources directly in HTML/CSS using Base64 encoding
Basic AuthenticationHTTP Basic Authentication encodes username:password pairs in Base64
JSON Web Tokens (JWT)JWTs use Base64 encoding for transmitting data between parties
XML/Binary DataXML sometimes uses Base64 to include binary content

Base64 in Different Programming Languages

Here are examples of how to encode and decode Base64 in different programming languages:

JavaScript:


// Encoding to Base64
const text = "Hello, World!";
const encoded = btoa(text);  // "SGVsbG8sIFdvcmxkIQ=="

// Decoding from Base64
const decoded = atob("SGVsbG8sIFdvcmxkIQ==");  // "Hello, World!"

// For UTF-8 support
const utf8Encode = new TextEncoder();
const utf8Decode = new TextDecoder();

// Encode UTF-8 text to Base64
const utf8Text = "Hello, World!";
const bytes = utf8Encode.encode(utf8Text);
const base64 = btoa(String.fromCharCode.apply(null, bytes));

// Decode Base64 to UTF-8 text
const binaryString = atob(base64);
const bytesDecoded = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
  bytesDecoded[i] = binaryString.charCodeAt(i);
}
const decodedText = utf8Decode.decode(bytesDecoded);  // "Hello, World!"
                

Python:


import base64

# Encoding to Base64
text = "Hello, World!"
encoded = base64.b64encode(text.encode('utf-8'))
print(encoded.decode('utf-8'))  # "SGVsbG8sIFdvcmxkIQ=="

# Decoding from Base64
decoded = base64.b64decode("SGVsbG8sIFdvcmxkIQ==").decode('utf-8')
print(decoded)  # "Hello, World!"
                

Java:


import java.util.Base64;

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

// Decoding from Base64
byte[] decodedBytes = Base64.getDecoder().decode("SGVsbG8sIFdvcmxkIQ==");
String decoded = new String(decodedBytes);
System.out.println(decoded);  // "Hello, World!"
                
100% Client-Side
No Data Upload
Instant Processing

DevToolCafe's free online Base64 encoder and decoder is the most versatile tool for converting text and files to Base64 format. Whether you're embedding images in HTML, encoding API credentials, or working with data URIs, our client-side Base64 tool processes everything locally in your browser. No data is ever uploaded to servers, making it perfect for encoding sensitive information like passwords and authentication tokens. Support for URL-safe Base64, file encoding, and batch operations makes this the best Base64 converter for developers.

What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that converts binary data into a sequence of printable ASCII characters. It uses 64 characters (A-Z, a-z, 0-9, +, /) plus padding (=) to represent data. Base64 encoding increases data size by approximately 33% but ensures safe transmission over text-based protocols like email, HTTP headers, and JSON. It's essential for embedding binary data in text formats, encoding authentication credentials, and creating data URIs for web applications.

Base64 encoder online
Base64 decoder
Text to Base64 converter
Base64 to text
File to Base64
Image to Base64
URL-safe Base64
Base64 string converter

Why Use Our Base64 Tool?

Complete Privacy

All encoding and decoding happens in your browser. Your sensitive data like passwords and API keys never leave your device.

File Support

Convert any file to Base64 including images, PDFs, and documents. Generate data URIs for embedding directly in HTML or CSS.

URL-Safe Mode

Generate URL-safe Base64 that replaces + and / with - and _, perfect for use in URLs and filenames without encoding issues.

Instant Conversion

Real-time encoding and decoding as you type. No waiting, no page reloads, just instant results.

How to Encode/Decode Base64

1

Choose Mode

Select 'Encode' to convert text to Base64, or 'Decode' to convert Base64 back to readable text.

2

Enter Your Data

Type or paste your text in the input field. For files, switch to the 'File to Base64' tab and upload your file.

3

Configure Options

Enable URL-safe mode if needed, or set line wrapping for formatted output.

4

Copy Result

Click 'Copy' to copy the encoded/decoded result. For files, you can also copy the complete data URI.

Frequently Asked Questions

Home/Security Tools/Base64 Encoder/Decoder