ASCII to Base64 String Converter
Convert ASCII and UTF-8 strings to Base64 encoding and decode Base64 back to text. Real-time, client-side, with full UTF-8 support.
About
Base64 encoding maps arbitrary binary data onto a 64-character ASCII subset (A - Z, a - z, 0 - 9, +, /) defined in RFC 4648. Every group of 3 input bytes (24 bits) produces 4 Base64 characters; when the input length is not divisible by 3, the output is padded with = symbols. A common mistake is feeding multi-byte UTF-8 text into the native btoa function, which throws a DOMException for any codepoint above 127. This tool handles both pure ASCII and full UTF-8 input by first encoding the string into a byte stream via TextEncoder, then performing the 6-bit chunking manually. Mishandling this step corrupts data silently in data URIs, email MIME attachments, and JWT payloads.
This converter operates entirely client-side. No data leaves your browser. It approximates instant conversion for inputs up to several megabytes. Note: the output size is always approximately 133% of the input due to the 3 - to - 4 byte expansion ratio. Pro tip: if you are encoding binary files, use a file-to-Base64 tool instead, as pasting raw binary into a text field causes data loss at null bytes.
Formulas
The Base64 encoding algorithm processes the input byte stream in groups of 3 octets. Each group of 24 bits is split into four 6-bit indices, each mapped to a character in the Base64 alphabet.
where nin is the byte length of the input and nout is the character count of the Base64 output including padding.
For each triplet of bytes b0, b1, b2, the four indices are extracted via bitwise operations:
Each index i β [0, 63] maps to alphabet[i] where the alphabet is the string ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/. When fewer than 3 bytes remain, missing bytes are treated as 0 and the corresponding output positions are replaced with =.
For UTF-8 input, the string is first encoded via TextEncoder into a Uint8Array, then the same algorithm is applied to the resulting byte sequence. This ensures codepoints above 127 (multi-byte sequences) are correctly represented.
Reference Data
| ASCII Character | Decimal | Binary (8-bit) | Base64 Index | Base64 Char |
|---|---|---|---|---|
| A | 65 | 01000001 | 0 | A |
| B | 66 | 01000010 | 1 | B |
| Z | 90 | 01011010 | 25 | Z |
| a | 97 | 01100001 | 26 | a |
| z | 122 | 01111010 | 51 | z |
| 0 | 48 | 00110000 | 52 | 0 |
| 9 | 57 | 00111001 | 61 | 9 |
| + | 43 | 00101011 | 62 | + |
| / | 47 | 00101111 | 63 | / |
| = (pad) | 61 | 00111101 | - | = |
| Space | 32 | 00100000 | - | - |
| Newline (LF) | 10 | 00001010 | - | - |
| Tab (HT) | 9 | 00001001 | - | - |
| ! | 33 | 00100001 | - | - |
| @ | 64 | 01000000 | - | - |
| # | 35 | 00100011 | - | - |
| Input: 1 byte | Remainder 1 | Output: 2 chars + == | ||
| Input: 2 bytes | Remainder 2 | Output: 3 chars + = | ||
| Input: 3 bytes | Remainder 0 | Output: 4 chars (no pad) | ||
| Input: n bytes | General | Output: 4 Γ βn Γ· 3β chars | ||