Base64 Encode / Decode
Encode text or files to Base64, decode Base64 strings back to text, and convert images to Base64 data URIs. Supports standard, URL-safe, and MIME formats.
What Is Base64 and How Does It Work?
Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 printable ASCII characters: AโZ (26), aโz (26), 0โ9 (10), and two special characters (+ and /), plus = as padding. It was designed to safely transmit binary data (images, files, cryptographic keys) through systems that only handle text โ such as email (MIME), HTML data URIs, JSON APIs, and HTTP headers. Base64 is not encryption โ it is a reversible encoding. For URL-specific encoding, see our URL Encode/Decode tool.
How Base64 Encoding Works โ The Algorithm
1. Convert input text to bytes using UTF-8 (or Latin-1)
2. Group bytes into chunks of 3 bytes (24 bits)
3. Split each 24-bit chunk into four 6-bit groups
4. Map each 6-bit value (0โ63) to a Base64 alphabet character
5. If input isn't divisible by 3: pad with = or == at the end
Example: "Hi" (72, 105) โ 010010000110100100 โ 010010 000110 100100
โ 18, 6, 36 โ S, G, k โ "SGk=" (padded with =)
Base64 output is always 4/3 ร input size, rounded up to nearest multiple of 4 characters.
Base64 Variants
Standard Base64 (RFC 4648)
Uses A-Z a-z 0-9 + / with = padding. The most common variant. Used in email attachments (MIME), PEM certificates, and basic data encoding.
URL-Safe Base64 (RFC 4648 ยง5)
Replaces + with - and / with _. Safe to use directly in URLs and filenames without percent-encoding. Used in JWTs and OAuth tokens.
MIME Base64 (RFC 2045)
Same alphabet as standard but inserts a line break (CRLF) every 76 characters. Used specifically in email encoding (Content-Transfer-Encoding: base64).
Data URIs (images)
Format: data:image/png;base64,.... Embeds images directly in HTML/CSS without a separate HTTP request. Use the File encoder above to convert any image.
Common Uses for Base64
Base64 is used everywhere in modern web development and systems: JWT tokens (header.payload.signature โ each part is Base64url encoded); HTML data URIs (embedding images, fonts, icons directly in HTML/CSS); Email attachments (SMTP only supports ASCII, so binary attachments are Base64 encoded); API authentication (HTTP Basic Auth sends username:password as Base64); Cryptographic keys and certificates (PEM format is Base64-encoded DER data wrapped in BEGIN/END headers); Storing binary data in JSON (JSON is text-only, so binary blobs are Base64 encoded). See also our URL Encode/Decode tool for HTTP/URL-specific encoding needs.
Frequently Asked Questions
Common questions about Base64 encoding, decoding, and when to use it
username:password Base64-encoded), JWT tokens (JSON Web Tokens use Base64url for header and payload), and PEM certificates (cryptographic keys stored as Base64 text). Base64 is a standard encoding โ it's not encryption and provides no security. Anyone can decode it instantly. For URL-specific encoding (spaces, special chars in URLs), use our URL Encode/Decode tool instead.
+ and / as the 62nd and 63rd characters. These are special characters in URLs โ + means space in query strings, and / is a path separator. If you embed standard Base64 in a URL without further encoding, these characters will be misinterpreted. Base64URL (also called URL-safe Base64) simply replaces + with - and / with _, making the output safe for URLs without percent-encoding. The alphabet and all other aspects are identical. Base64URL is used in: JWTs (JSON Web Tokens), OAuth 2.0 tokens, cookie values, and URL parameters. Select "URL-Safe" in this calculator to use Base64URL encoding. For general URL encoding of arbitrary text, use our URL Encode/Decode tool.
data:[media type];base64,[Base64-encoded data]. Use the "File / Image โ Base64" section above: drag and drop your image file, and the tool generates the complete data URI automatically (e.g. data:image/png;base64,iVBORw0KGgo...). You can then use it directly in an <img> tag: <img src="data:image/png;base64,...">, or in CSS: background-image: url("data:image/png;base64,..."). Best practices: use data URIs for small images (icons, logos under ~5KB) and avoid for large images, as it increases HTML size and prevents browser caching of the image separately. MIME type must match the actual image format (image/png, image/jpeg, image/svg+xml, image/gif, etc.).
btoa('Hello World') โ encode; atob('SGVsbG8gV29ybGQ=') โ decode. For Unicode: btoa(unescape(encodeURIComponent(str))). JavaScript (Node.js): Buffer.from('Hello').toString('base64') โ encode; Buffer.from('SGVsbG8=','base64').toString() โ decode. Python: import base64; base64.b64encode(b'Hello') โ encode; base64.b64decode('SGVsbG8=') โ decode. For URL-safe: base64.urlsafe_b64encode(). PHP: base64_encode('Hello') โ encode; base64_decode('SGVsbG8=') โ decode. Java: Base64.getEncoder().encodeToString(bytes). This online calculator handles all these scenarios instantly without writing any code. See also our URL Encode/Decode tool for URL encoding functions.