Guide

How Base64 Encoding Works (and When to Use It)

Understand what Base64 is, how it encodes binary as text, and the common use cases and pitfalls.

Base64 encodes binary data as text using a 64-character alphabet, so it can travel through systems that only handle text. A Base64 encoder/decoder converts text or images to a Base64 string and back.

What Base64 is

Base64 maps every 3 bytes of input to 4 characters from a set of 64 (A–Z, a–z, 0–9, +, /, with = for padding). The result is pure text, safe to embed in JSON, HTML, URLs, or email. The trade-off is size: encoded output is about 33% larger than the input.

When to use Base64

  • Embedding small images directly in HTML or CSS as data URLs.
  • Sending binary data inside a JSON API payload.
  • Storing binary in a text-only field or config file.
  • Encoding credentials for HTTP Basic auth headers.

How to use an encoder/decoder

  1. To encode: paste text or upload an image and copy the Base64 string.
  2. To decode: paste a Base64 string and read the original text or image.
  3. For URLs, use the URL-safe variant that replaces + and / with - and _.

Examples

The text "Hello" encodes to "SGVsbG8=". A small PNG can be embedded as <img src="data:image/png;base64,iVBORw..."> so the page loads with no separate image request. Decoding "SGVsbG8=" returns "Hello".

Common pitfalls

Base64 is encoding, not encryption — it is trivially reversible, so never use it to protect secrets. The 33% size overhead matters for large files, and some systems choke on line breaks in long Base64 strings. Use URL-safe Base64 where + and / would cause problems.

Put it into practice

Use the Base64 Encoder / Decoder right now — free, in your browser, no sign-up required.

Try the Base64 Encoder / Decoder