
Base64 is a binary-to-text encoding scheme that represents binary data using only 64 printable ASCII characters: A–Z, a–z, 0–9, and the symbols + and /, with = used for padding. The goal is to safely transmit binary data through systems that were designed to handle text — email protocols, URLs, JSON payloads, and HTML attributes.
It is important to understand that Base64 is not encryption. It provides zero security. Anyone who sees Base64-encoded data can decode it instantly. Its purpose is encoding for safe transport, not concealment.
The algorithm takes every 3 bytes (24 bits) of input and splits them into four 6-bit groups. Each 6-bit group maps to one of the 64 characters in the Base64 alphabet. Since 3 input bytes become 4 output characters, Base64 encoding increases data size by approximately 33%.
If the input length is not divisible by 3, padding characters (= or ==) are appended to the output to make the total length a multiple of 4. This allows decoders to correctly identify the length of the original data.
Data URIs in web development: You can embed images, fonts, or other binary files directly into HTML or CSS by encoding them as Base64. For example, a small icon can be embedded as <img src="data:image/png;base64,iVBORw0K...">, eliminating an HTTP request. This is useful for small assets but impractical for large files due to size overhead.
Email attachments: The MIME standard uses Base64 to encode binary attachments (images, PDFs, etc.) into text that can travel through SMTP servers, which were built to handle ASCII text. Every time you attach a file to an email, Base64 is involved behind the scenes.
Storing binary data in JSON or XML: These formats are text-based and cannot natively represent arbitrary binary data. When an API needs to transmit a file, an image, or cryptographic material as part of a JSON response, Base64 encoding is the standard solution.
Basic authentication in HTTP: The HTTP Basic Auth scheme encodes credentials as Base64 in the Authorization header: Authorization: Basic dXNlcjpwYXNz. Again — this is not encryption. It should only ever be used over HTTPS.
Cryptographic keys and certificates: PEM format, widely used for TLS certificates and SSH keys, wraps binary DER-encoded data in Base64 between -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- headers.
Standard Base64 uses + and /, which have special meanings in URLs. URL-safe Base64 substitutes - for + and _ for /, making the encoded string safe to include in a URL without percent-encoding. You'll encounter this variant in JWTs (JSON Web Tokens) and OAuth flows.
Decoding reverses the process exactly. Each group of 4 Base64 characters maps back to 3 bytes of binary data. Most programming languages have built-in Base64 support:
btoa(str) to encode, atob(str) to decode (browser); Buffer.from(str, 'base64') in Node.jsimport base64; base64.b64encode(data) and base64.b64decode(data)echo -n "hello" | base64 and echo "aGVsbG8=" | base64 --decodeBase64 is not appropriate when you need actual security — use proper encryption instead. It also adds overhead, so don't use it for large binary transfers where a direct binary stream is available. When storing data in a database that supports binary column types (BLOB, BYTEA), storing raw binary is more efficient than Base64-encoded text.
Understanding Base64 helps you read API documentation, debug network traffic, and work confidently with certificates, tokens, and media — a foundational skill for any web developer.
Open the free Base64 encoder & decoder — convert text or binary data instantly. Runs entirely in your browser; nothing is sent to a server.