
A Developer Guide to Base64 Encoding and Decoding
Base64 encoding converts binary data into 64 printable ASCII characters so it can safely travel through text-only systems like email, JSON APIs, and HTML. Every 3 bytes of input produce 4 Base64 characters, making the output about 33 percent larger. A Base64 encoder/decoder works bidirectionally — paste text to encode, paste Base64 to decode — entirely client-side with no server upload.
Base64 encoding is one of those things every developer encounters but few truly understand. You see those long strings of letters, numbers, and plus signs in data URIs, JWT tokens, email attachments, and API responses. Here is what Base64 actually does, when you should use it, and how to encode and decode it instantly with a free tool.
What Base64 encoding is
Base64 is a binary-to-text encoding scheme. It takes arbitrary binary data and represents it using only 64 printable ASCII characters: A-Z, a-z, 0-9, plus, and slash. Every 3 bytes of input become 4 Base64 characters. The result is always about 33 percent larger than the original, but it is guaranteed to survive transport through systems that only handle text โ email protocols like MIME, JSON, XML, and URL query strings.
Common use cases
Data URIs. Embed small images directly in CSS or HTML, eliminating an HTTP request at the cost of larger file size. JWT tokens. JSON Web Tokens use Base64URL encoding for the header and payload sections. Decoding the middle section reveals the claims โ use the JWT Decoder for this. API authentication. HTTP Basic Auth encodes username and password in Base64. It is encoding, not encryption โ never rely on Base64 for security. Email attachments. MIME uses Base64 to encode binary attachments.
Encoding and decoding with the tool
The ToolStand Base64 Encoder and Decoder works bidirectionally. Paste any text and click Encode to get the Base64 output. Paste a Base64 string and click Decode to see the original. The tool handles both standard Base64 and Base64URL variants, and it works entirely client-side โ no data sent to any server.
Related encoding tools
The URL Encoder handles percent-encoding for query parameters. The HTML Entity Encoder escapes characters for safe HTML embedding. Keep all three bookmarked.
How Base64 works at the bit level
Take the word “Man” — three bytes: 0x4D, 0x61, 0x6E. In binary: 01001101 01100001 01101110. Base64 splits these 24 bits into four 6-bit groups: 010011, 010110, 000101, 101110. Each group maps to a character in the Base64 alphabet (A-Z, a-z, 0-9, +, /), producing “TWFu.” This is why every 3 input bytes become 4 output characters — a concrete transformation most guides skip.
Platform-specific gotchas
Python: base64.b64encode() adds a newline every 76 characters by default (RFC 2045 MIME compliance). Use b64encode(data).replace(b'\n', b'') for single-line output. JavaScript: btoa() throws on non-Latin1 characters — wrap strings in new TextEncoder().encode(str) first. Node.js: Buffer.toString('base64') produces identical output to browser btoa() but with a different API surface.
Base64URL vs standard Base64
Standard Base64 uses + and / characters that are unsafe in URLs and filenames. Base64URL replaces + with - and / with _, and typically omits trailing = padding. This variant is used in JWT tokens and web-safe data transmission. The Base64 Encoder and Decoder supports both variants with automatic detection.
Frequently asked questions about Base64
Why is my Base64 string about 33% bigger than the original?
Base64 encodes 3 bytes (24 bits) into 4 ASCII characters (32 bits of representation). The math is 4/3 = 1.33x overhead. This is inherent to the encoding scheme.
What’s the difference between Base64 and Base64URL?
Base64URL replaces + with - and / with _, and typically omits trailing = padding. This makes it safe for URLs, filenames, and JWT tokens without percent-encoding.
Why does Python’s base64.b64encode() add newlines?
Python follows RFC 2045 which specifies a 76-character line length limit for MIME email encoding. Use b64encode(data).replace(b'\n', b'') for single-line output.
Can Base64 be used for encryption?
No — Base64 is encoding, not encryption. Anyone can decode it instantly. Never rely on Base64 for security. Use AES or a password hashing algorithm for actual encryption.
Why does JavaScript btoa() fail on non-ASCII characters?
btoa() only accepts Latin1 (0-255) code points. For UTF-8 strings, encode to bytes first using TextEncoder before passing to btoa().
Explore all 109 free tools at toolstand.io. Free, forever. No sign-up. No download. Just tools that work.