User Rating 0.0 β˜…β˜…β˜…β˜…β˜…
Total Usage 0 times
0 bytes 0 chars
Is this tool helpful?

Your feedback helps us improve.

β˜… β˜… β˜… β˜… β˜…

About

Base64 encodes binary data into a 64-character ASCII subset defined by RFC 4648. The native btoa() function in browsers only handles Latin-1 codepoints (U+0000 to U+00FF). Feed it a multibyte UTF-8 character and it throws. This tool bridges that gap by routing input through encodeURIComponent before encoding, preserving full Unicode. A 1 KB plaintext input expands to roughly 1.37 KB in Base64 due to the 43 ratio. Misapplied encoding corrupts data silently in APIs, email attachments (MIME mandates 76-character lines), and data URIs. This tool validates input, reports byte sizes, and supports URL-safe variants where + and / are replaced with - and _.

base64 btoa encode decode data encoding binary to ascii

Formulas

Base64 maps every group of 3 input bytes (24 bits) to 4 ASCII characters (6 bits each). The output length formula:

Lout = 4 β‹… ceil(Lin3)

Where Lin = input byte length, Lout = output character count. The size overhead ratio is exactly 43 1.333. With MIME line breaks every 76 characters (RFC 2045), CRLF pairs add further overhead.

For UTF-8 safe encoding in browsers, the pipeline is:

btoa(unescape(encodeURIComponent(str)))

encodeURIComponent converts each multibyte codepoint into percent-encoded octets. unescape interprets those octets as raw Latin-1 bytes. btoa then safely encodes the Latin-1 string. Decoding reverses the chain: decodeURIComponent(escape(atob(b64))).

URL-safe Base64 substitutes index 62 (+ β†’ -) and index 63 (/ β†’ _), then strips trailing = padding.

Reference Data

CharacterIndexCharacterIndexCharacterIndexCharacterIndex
A0Q16g32w48
B1R17h33x49
C2S18i34y50
D3T19j35z51
E4U20k36052
F5V21l37153
G6W22m38254
H7X23n39355
I8Y24o40456
J9Z25p41557
K10a26q42658
L11b27r43759
M12c28s44860
N13d29t45961
O14e30u46+62
P15f31v47/63
Padding= (appended when input byte count mod 3 β‰  0)

Frequently Asked Questions

The native btoa() function only accepts characters in the Latin-1 range (U+0000 to U+00FF). Any character outside this range - including emoji, CJK, Cyrillic, or Arabic - causes the error. This tool solves it by first converting the input to UTF-8 percent-encoded octets via encodeURIComponent(), then reinterpreting those octets as Latin-1 bytes via unescape() before calling btoa(). The decode path reverses this precisely.
Base64 produces 4 output characters for every 3 input bytes, yielding a fixed 33.33% size increase. For an input of L bytes, the output is 4 Γ— ceil(L/3) characters. If MIME line wrapping is enabled (76 characters per line + CRLF), the overhead increases further by approximately 2.6% due to the inserted line breaks.
Standard Base64 uses "+" and "/" which are reserved characters in URLs and filenames. URL-safe Base64 (RFC 4648 Β§5) replaces "+" with "-" and "/" with "_", and typically omits padding "=" characters. Use it for JWT tokens, URL query parameters, filename-safe identifiers, and any context where the encoded string travels through URL parsers or filesystem APIs.
Yes. The file input reads the file as a data URI via FileReader.readAsDataURL(), which produces a full Base64 data URI including the MIME type prefix (e.g., 'data:image/png;base64,...'). You can also extract the raw Base64 portion without the prefix. Files up to 5 MB are supported; larger files risk browser memory constraints.
Padding ensures the output length is always a multiple of 4. If the input byte count mod 3 is 1, two "=" are appended; if mod 3 is 2, one "=" is appended. Many decoders (including this tool and most modern parsers) can infer the missing bytes without padding, so stripping it is safe in controlled environments. However, strict RFC 4648 Β§3.2 decoders will reject unpadded input.
No. Base64 is a reversible encoding scheme with no key, no secret, and no security. Any observer can decode the output instantly. It exists solely to represent binary data in text-safe formats (email, JSON, XML, URLs). For confidentiality, apply actual encryption (AES, ChaCha20) before Base64-encoding the ciphertext for transport.