Base64 to JavaScript Converter
Decode Base64-encoded strings to JavaScript code instantly. Supports UTF-8, URL-safe Base64, syntax highlighting, and file download.
About
Base64 encoding represents binary data as ASCII text using a 64-character alphabet (A - Z, a - z, 0 - 9, +, /) plus = for padding. JavaScript source code is frequently distributed in Base64 form inside data URIs, obfuscated payloads, API responses, and build artifacts. Decoding it incorrectly - especially when multi-byte UTF-8 sequences are present - produces garbled output or silent data corruption. This tool applies the full RFC 4648 decode pipeline with proper TextDecoder reconstruction, so characters outside the ASCII plane (emoji, CJK, diacritics) survive intact.
The converter also accepts URL-safe Base64 (RFC 4648 ยง5), which replaces + with โ and / with _. Padding may be absent in URL-safe variants; the tool re-pads automatically before decoding. Output is syntax-highlighted with a hand-rolled JavaScript lexer - no external dependencies. Note: this tool decodes Base64 to text. It assumes the encoded payload is valid UTF-8 text. Binary payloads (images, WASM) will produce unreadable output.
Formulas
Base64 encoding maps every 3 input bytes (24 bits) to 4 output characters (6 bits each). The output length is:
Where Lin = input byte count, Lout = Base64 character count (with padding). The decoding reversal extracts the original bytes:
Where P = number of padding characters (0, 1, or 2). For URL-safe Base64, the alphabet substitution is: + โ โ and / โ _. The decode pipeline in this tool: (1) strip whitespace, (2) detect and normalize URL-safe characters, (3) re-pad if necessary, (4) validate character set via regex, (5) call native atob, (6) reconstruct UTF-8 via TextDecoder.
Reference Data
| Character Set | Alphabet | Padding | RFC | Common Use |
|---|---|---|---|---|
| Standard Base64 | A - Z, a - z, 0 - 9, +, / | = | RFC 4648 ยง4 | Email (MIME), PEM certificates |
| URL-safe Base64 | A - Z, a - z, 0 - 9, โ, _ | Optional | RFC 4648 ยง5 | URLs, JWT tokens, filenames |
| Base64 (MIME) | Same as standard | = | RFC 2045 | Email attachments, line-wrapped |
| Base32 | A - Z, 2 - 7 | = | RFC 4648 ยง6 | TOTP secrets, DNS |
| Base16 (Hex) | 0 - 9, A - F | None | RFC 4648 ยง8 | Hash digests, color codes |
| Input Byte Length | n bytes โ 4 โ โ n / 3 โ1 Base64 characters (with padding) | |||
| Overhead | 33.3% size increase vs raw binary | |||
| 1 byte input | 4 Base64 chars | 2 data chars + 2 padding | ||
| 2 byte input | 4 Base64 chars | 3 data chars + 1 padding | ||
| 3 byte input | 4 Base64 chars | 4 data chars + 0 padding | ||
| Padding Rule | Pad with = until length is divisible by 4 | |||
| Invalid Characters | Any char outside alphabet causes decode failure | |||
| Line Length (MIME) | Max 76 chars per line (RFC 2045) | |||
| Whitespace | Ignored by most decoders (stripped before processing) | |||
| Empty Input | Decodes to empty string (zero bytes) | |||