Base64 Encoding — Complete Guide with Examples
Learn how Base64 encoding works with practical examples. Encode and decode strings instantly with our Base64 Encode/Decode tool.
What is Base64?
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It uses 64 characters (A-Z, a-z, 0-9, +, /) plus = for padding. Base64 is widely used for transmitting binary data over text-based protocols like HTTP, email (MIME), and embedding images in HTML/CSS as data URIs.
Base64 Encoding Examples
Input
Hello, World!Base64 Output
SGVsbG8sIFdvcmxkIQ==Input
https://example.com/api/data?page=1Base64 Output
aHR0cHM6Ly9leGFtcGxlLmNvbS9hcGkvZGF0YT9wYWdlPTE=Input (user:pass)
admin:secret123Base64 Encoded
YWRtaW46c2VjcmV0MTIzInput
{"name":"John","role":"admin"}Base64 Output
eyJuYW1lIjoiSm9obiIsInJvbGUiOiJhZG1pbiJ9Data URI Example
Base64 is commonly used to embed images directly in HTML or CSS:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..." alt="Embedded Image">
/* CSS background */
background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0i...');Common Use Cases
HTTP Basic Authentication
Username:password pairs are Base64-encoded in the Authorization header
Email Attachments (MIME)
Binary file attachments in emails are Base64-encoded for safe transmission
Data URIs
Embed images, fonts, and other resources directly in HTML/CSS without separate HTTP requests
JWT Tokens
JSON Web Tokens use Base64url encoding for the header, payload, and signature parts
API Authentication
API keys and tokens are often Base64-encoded for safe transport in headers