Base64 Encode / Decode
Encode text to Base64 or decode Base64 strings back to plain text. Standard and URL-safe variants.
About Base64 Encode / Decode
Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters. It is widely used in web development for embedding images directly in HTML or CSS, transmitting binary data in JSON payloads, storing credentials in HTTP Basic Auth headers, and encoding email attachments.
URL-safe variant
Standard Base64 uses the characters + and / which are special characters in URLs. URL-safe Base64 substitutes - for + and _ for /, making encoded strings safe to include in query parameters without encoding.
Note on security
Base64 is encoding, not encryption. It provides no security — any encoded string can be trivially decoded. Never use it to protect passwords or sensitive data.
Base64 variants: standard, URL-safe, and MIME
Standard Base64 uses A-Z, a-z, 0-9, + and / with = padding. URL-safe Base64 replaces + with - and / with _ to avoid conflicts with URL special characters — used in JWT tokens, OAuth tokens, and URL parameters. MIME Base64 (used in email) inserts line breaks every 76 characters. Most web APIs and JWT libraries use URL-safe Base64 without padding.
- Standard Base64 — RFC 4648, uses +/= characters, not URL-safe
- URL-safe Base64 — replaces + with - and / with _, used in JWTs and web APIs
- Base64URL no-padding — URL-safe without trailing = signs, used in JWTs
- MIME Base64 — adds \r\n every 76 characters, used in email attachments
Frequently Asked Questions
import base64; encoded = base64.b64encode(open("file.bin","rb").read()).decode("utf-8"). For URL-safe Base64 (used in JWTs): base64.urlsafe_b64encode(data).rstrip(b"=").decode(). To decode: base64.b64decode(encoded_string + "==") (adding padding if removed).