How to Encode and Decode Base64

Developer

Learn what Base64 encoding is, when to use it, how to encode text or files to Base64 and decode it back — with practical examples.

What is Base64?

Base64 is a binary-to-text encoding that represents any arbitrary bytes using only 64 printable ASCII characters: A–Z, a–z, 0–9, plus (+) and slash (/). It was designed so that data which is not text — images, PDFs, ZIP archives, encryption keys — can safely travel through systems that only accept text, such as email bodies, URL query strings, JSON fields, or XML attributes. Base64 is not encryption: anyone can decode the output back to the original bytes. The trade-off is a ~33% size increase — every 3 bytes of input become 4 characters of output.

Where Base64 is used every day

  • Data URIs in web pages

    A small image or font can be embedded directly in CSS or HTML as data:image/png;base64,iVBORw… which saves an extra HTTP request.

  • Email MIME attachments

    Email protocols were designed for 7-bit ASCII, so every binary attachment is Base64-encoded inside the message body.

  • Storing binary in JSON or XML

    When an API must return a file or a cryptographic key inside a JSON field, Base64 is the standard wrapper because JSON strings cannot hold raw bytes.

Step-by-Step Guide

1

Understand Base64

Base64 encodes binary data into a text string using 64 ASCII characters (A-Z, a-z, 0-9, +, /). It is NOT encryption — it's encoding. Anyone can decode it. It's used to safely transmit binary data through text-only channels.

2

Encode text to Base64

Open our Base64 tool, paste your text in the input field, and click Encode. Example: "Hello, World!" encodes to "SGVsbG8sIFdvcmxkIQ==".

3

Decode Base64 to text

Paste a Base64 string into the decode field and click Decode. The tool converts it back to the original text. Padding characters (=) at the end are part of the format.

4

Common use cases

Embedding images in HTML/CSS (data URIs): data:image/png;base64,iVBOR... Encoding email attachments (MIME). Passing credentials in HTTP Basic Auth headers. Storing binary data in JSON.

5

Base64URL vs standard Base64

Base64URL uses - instead of + and _ instead of / to make strings URL-safe. JWTs use Base64URL encoding. Our tool supports both variants.

Try Our Free Tool

Base64 Encoder/Decoder

Frequently Asked Questions

Q: Does Base64 increase file size?

A: Yes — Base64 encoding increases data size by approximately 33%. A 3-byte input becomes 4 Base64 characters.

Q: Is Base64 the same as encryption?

A: No. Base64 is encoding, not encryption. It provides no security — anyone can decode it without a key. For security, use encryption (AES, RSA, etc.) before encoding.

Q: What does the "=" padding mean?

A: Base64 encodes 3 bytes at a time into 4 characters. If input length isn't a multiple of 3, = characters are added as padding to complete the last 4-character block.