AskDB
·4 min read

A Developer's Guide to Base64 Encoding

Base64 is one of those encoding schemes that every developer encounters but few fully understand. This guide explains what it is, how it works, and the practical situations where you need it.

What is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data using 64 ASCII characters: A-Z, a-z, 0-9, +, and /. It converts arbitrary bytes into a string of safe, printable characters.

How It Works

Base64 takes every 3 bytes (24 bits) of input and converts them into 4 Base64 characters (6 bits each). This increases the output size by approximately 33%. Padding with = characters is added when the input length is not a multiple of 3.

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

Common Use Cases

  • Data URLs: Embedding images directly in HTML/CSS using data:image/png;base64,...
  • Email attachments: MIME encoding for email attachments
  • HTTP Basic Auth: Encoding username:password in Authorization headers
  • JWT tokens: Encoding the header and payload parts
  • API payloads: Sending binary data in JSON bodies

Base64 is NOT Encryption

Base64 is an encoding, not encryption. Anyone can decode a Base64 string. Never use it to hide sensitive data. It only ensures data survives transport through systems that handle text.

Try It Yourself

Use the Base64 Encoder/Decoder to encode text to Base64 or decode Base64 back to text. The tool runs in your browser with no data uploaded.

URL-Safe Base64

Standard Base64 uses + and / which have special meanings in URLs. URL-safe Base64 replaces these with - and _ respectively. Many libraries provide this variant for use in query strings and path segments.

Understanding Base64 helps you debug API responses, work with data URLs, and handle binary data in text-based protocols. It is a fundamental tool in every developer toolkit.