Convert text to or from Base64.
Output length = ⌈n / 3⌉ × 4
Base64 works by splitting the input bytes into groups of 3 bytes (24 bits), then dividing each 24-bit group into four 6-bit chunks. Each 6-bit value (0–63) is mapped to one of the 64 characters in the Base64 alphabet. If the input length is not divisible by 3, padding characters (=) are appended to make the output length a multiple of 4.
Output length formula:
For an input of n bytes, the Base64-encoded output length is ⌈n / 3⌉ × 4 characters (including padding).
Step 1 — Concatenate the 24 bits: 010011010110000101101110 Step 2 — Split into four 6-bit groups: 010011 | 010110 | 000101 | 101110 Step 3 — Convert each 6-bit group to decimal: 19, 22, 5, 46 Step 4 — Map to Base64 alphabet: 19→T, 22→W, 5→F, 46→u Step 5 — No padding needed (n=3, divisible by 3) Output length check: ⌈3/3⌉ × 4 = 1 × 4 = 4 characters
Result: TWFu
The plain text Man (3 bytes) encodes to the 4-character Base64 string TWFu — no padding required because the input length is exactly divisible by 3. Decoding TWFu through the reverse mapping returns Man exactly. If the input were only 1 byte (e.g., M), the result would be TQ== (two = padding characters); for 2 bytes (e.g., Ma), the result would be TWE= (one = padding character).
Base64 is a binary-to-text encoding scheme defined in RFC 4648. It was designed to safely transmit binary data — such as images, files, or cryptographic keys — over channels that were originally designed to carry only ASCII text, such as SMTP email or HTTP headers.
The 64 characters used are:
Standard Base64 uses + and /, which have special meanings in URLs. URL-safe Base64 (also defined in RFC 4648) replaces + with - and / with _, making the encoded string safe for use directly in URLs and filenames without percent-encoding.
Base64 is not encryption. It provides no security — anyone can decode a Base64 string without a key. It exists purely for data compatibility and transport, not confidentiality. Do not use Base64 to protect sensitive data.
Base64 encoding increases the data size by approximately 33% (every 3 bytes become 4 characters). For example, a 900 KB image becomes approximately 1,200 KB when Base64-encoded. This overhead is the trade-off for text-safe compatibility.
data:image/png;base64,...)Authorization: Basic <base64(user:pass)>)Use the built-in atob() function: atob('SGVsbG8=') returns 'Hello'. For encoding, use btoa('Hello') which returns 'SGVsbG8='. For Node.js, use Buffer.from('SGVsbG8=', 'base64').toString('utf8').
Decoding fails with an error. Valid Base64 strings contain only A–Z, a–z, 0–9, +, / (or - and _ for URL-safe), with optional = padding at the end, and a total length divisible by 4.
Hexadecimal uses 16 characters (0–9, A–F) and represents each byte as 2 hex digits, doubling the size. Base64 uses 64 characters and represents 3 bytes as 4 characters, giving ~33% overhead — making Base64 more space-efficient than hex.
Yes, Base64 is fully reversible (lossless). Decoding a Base64 string always returns the exact original bytes, as long as the encoded string is valid and complete.
No. Base64 is an encoding scheme, not encryption. It has no key and provides zero security — any Base64 string can be decoded by anyone instantly. Use proper encryption (such as AES) if you need to protect data.
The '=' characters are padding. Base64 output must always be a multiple of 4 characters long. When the input byte count isn't divisible by 3, one or two '=' characters are appended to reach the required length. One '=' means 2 remaining input bytes; '==' means 1 remaining input byte.
URL-safe Base64 replaces '+' with '-' and '/' with '_' to avoid characters that have special meanings in URLs. Use URL-safe Base64 when embedding encoded data in a URL query parameter, path segment, or filename.
Yes, by approximately 33%. Every 3 bytes of input become 4 characters of output. A 1 MB binary file becomes roughly 1.33 MB when Base64-encoded.
Yes. Browsers support inline images via data URIs: set the src attribute to 'data:image/png;base64,' followed by the Base64-encoded image bytes. This removes the need for a separate HTTP request but increases page size.
Only sources that have been reviewed are shown. Unverified citations are never published.
Spotted an inaccuracy or have an idea to improve this calculator? Let us know.
We use cookies to operate the site, and — with your consent — to show advertising and measure usage. You can change your choice anytime in Cookie Settings.