How to Use Base64 Encoding and Decoding

What is Base64?

Base64 is a method to encode binary data as text using only ASCII characters. It's commonly used when transferring images, files, or other binary content through systems that only support plain text, such as email (MIME), JSON, or URLs.

Why Use Base64?

  • Encode binary data (like files or images) to embed in HTML, CSS, or XML
  • Transfer sensitive data as strings through APIs or headers
  • Avoid character encoding issues during transport

How It Works

Base64 divides your data into 3-byte blocks and maps them into 4 ASCII characters. Each Base64 character represents 6 bits.

Original:  Hello
Binary:    01001000 01100101 01101100 01101100 01101111
Base64:    SGVsbG8=
    

Common Use Cases

  • Embedding images directly in HTML: <img src="data:image/png;base64,...">
  • Transferring files via JSON or APIs
  • Encoding credentials for HTTP Basic Auth

Base64 vs URL Encoding

Base64 is not URL-safe by default. For URLs, use base64.URLEncoding or manually replace + with - and / with _.

Try It Now

Use our free Base64 Encoder / Decoder Tool to test it on your own input.