4uToolsFree Online Tools

Base64 Encode and Decode

A simple and efficient online tool to encode text to Base64 and decode Base64 strings back to text. Base64 encoding is widely used in data transmission, email attachments, and storing complex data in text formats.

What is Base64?

Base64 is a group of binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. It is commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with textual data.

Decode - Convert Base64 to Text

Encode - Convert Text to Base64

Understanding Base64 Encoding in Depth

Base64 encoding is one of the most widely used encoding schemes on the internet. It was originally designed as a way to safely transmit binary data through systems that only support text, such as email protocols (SMTP), XML documents, and JSON payloads. The name "Base64" comes from the fact that it uses a set of 64 printable ASCII characters to represent binary data.

The 64 characters used in standard Base64 are: uppercase letters (A–Z), lowercase letters (a–z), digits (0–9), plus sign (+), and forward slash (/). A padding character (=) is used when the input data length is not a multiple of three bytes.

How Does Base64 Encoding Work?

The encoding process works by taking three bytes (24 bits) of binary input and splitting them into four groups of 6 bits. Each 6-bit group maps to one of the 64 characters in the Base64 alphabet. This means that Base64-encoded data is always approximately 33% larger than the original binary data.

For example, the text "Hi" (two ASCII bytes: 72 and 105) would be encoded as follows:

  • Binary: 01001000 01101001 (16 bits)
  • Padded to 24 bits: 01001000 01101001 00000000
  • Split into 6-bit groups: 010010 000110 100100 000000
  • Mapped to Base64: SGk= (the "=" indicates padding)

Common Uses for Base64

  • Embedding images in HTML/CSS: Small images can be embedded directly into web pages using Data URIs, eliminating the need for separate HTTP requests. For example: background-image: url('data:image/png;base64,iVBOR...');
  • Email attachments (MIME): Email protocols use Base64 to encode binary attachments like images, PDFs, and documents so they can be transmitted as text.
  • API data transfer: REST APIs often use Base64 to encode binary data in JSON payloads, such as file uploads or cryptographic signatures.
  • Storing data in URLs: Base64url (a URL-safe variant) is used in JSON Web Tokens (JWT) and other URL-based data formats.
  • Data integrity: Base64 ensures that binary data is not corrupted during transport through text-only channels.

Base64 vs. Other Encoding Schemes

While Base64 is the most popular binary-to-text encoding, there are alternatives depending on the use case:

  • Base32: Uses 32 characters, producing longer output but is case-insensitive and avoids ambiguous characters. Often used in OTP (one-time password) applications.
  • Hexadecimal (Base16): Uses 16 characters (0–9, A–F). Each byte maps to exactly two hex characters, making it very readable but 100% larger than the original data.
  • Base85 (Ascii85): Uses 85 characters and is more space-efficient than Base64, commonly used in PDF files and Git binary patches.

Frequently Asked Questions

Is Base64 the same as encryption?

No. Base64 is an encoding scheme, not an encryption method. It does not provide any security — anyone can decode a Base64 string without a key. If you need to protect data, use proper encryption algorithms like AES or RSA before encoding to Base64.

Why does Base64 make data 33% larger?

Base64 takes every 3 bytes of input and converts them into 4 characters of output. This ratio of 4:3 means the encoded output is always about 33% larger than the original binary data. This trade-off is acceptable because the resulting text is safe to transmit through text-only channels.

What is the difference between Base64 and Base64url?

Standard Base64 uses "+" and "/" characters, which have special meaning in URLs. Base64url replaces these with "-" (minus) and "_" (underscore), making the output safe to use directly in URLs and filenames without encoding.

Can I Base64-encode large files?

While technically possible, encoding large files to Base64 is not recommended because the 33% size increase can be significant. For example, a 10 MB file would become approximately 13.3 MB when Base64-encoded. It's better to use binary transfer methods for large files and reserve Base64 for small data like icons, tokens, or API payloads.

Is Base64 encoding reversible?

Yes, Base64 encoding is fully reversible. Any valid Base64-encoded string can be decoded back to its original binary data without any loss of information. This is what makes it an encoding scheme rather than a hash function.