What is Base64?
Base64 represents binary data using 64 safe characters (A–Z, a–z, 0–9, + and /). It's how bytes travel through text-only channels: email attachments, data URIs, JSON fields, HTTP Basic auth headers and the parts of a JWT.
Base64 vs Base64URL
| Base64 | Base64URL | |
|---|---|---|
| Characters 62 and 63 | + and / | - and _ |
| Padding | Required (=) | Usually omitted |
| Used in | Email, data URIs, Basic auth, JSON | JWTs, URLs, filenames |
Base64 in code
// UTF-8 safe in the browser (btoa alone breaks on non-ASCII text)
const encoded = btoa(String.fromCharCode(...new TextEncoder().encode("héllo")));
const decoded = new TextDecoder().decode(Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0)));
// Node.js
Buffer.from("héllo").toString("base64"); // or "base64url"
Buffer.from(encoded, "base64").toString("utf8");import base64
encoded = base64.b64encode("héllo".encode()).decode()
decoded = base64.b64decode(encoded).decode()
url_safe = base64.urlsafe_b64encode(b"data").decode()echo -n "héllo" | base64 # encode
echo "aMOpbGxv" | base64 --decode # decodeencoded := base64.StdEncoding.EncodeToString([]byte("héllo"))
decoded, err := base64.StdEncoding.DecodeString(encoded)
urlSafe := base64.RawURLEncoding.EncodeToString(data) // Base64URL, no paddingBase64 and APIs
You'll meet Base64 in API work when sending Basic auth credentials, embedding images in JSON (e.g. to OCR or image APIs), and decoding tokens. If an API returns Base64 data, paste it here to see what's inside, or format the surrounding response with the JSON formatter.