User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
0 characters
Decoded JavaScript
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

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.

base64 javascript decoder converter base64-to-js code-utilities encoding

Formulas

Base64 encoding maps every 3 input bytes (24 bits) to 4 output characters (6 bits each). The output length is:

Lout = 4 โ‹… โŒˆ Lin3 โŒ‰

Where Lin = input byte count, Lout = Base64 character count (with padding). The decoding reversal extracts the original bytes:

Ldecoded = 34 โ‹… Lout โˆ’ P

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 SetAlphabetPaddingRFCCommon Use
Standard Base64A - Z, a - z, 0 - 9, +, /=RFC 4648 ยง4Email (MIME), PEM certificates
URL-safe Base64A - Z, a - z, 0 - 9, โˆ’, _OptionalRFC 4648 ยง5URLs, JWT tokens, filenames
Base64 (MIME)Same as standard=RFC 2045Email attachments, line-wrapped
Base32A - Z, 2 - 7=RFC 4648 ยง6TOTP secrets, DNS
Base16 (Hex)0 - 9, A - FNoneRFC 4648 ยง8Hash digests, color codes
Input Byte Lengthn bytes โ†’ 4 โ‹… โŒˆ n / 3 โŒ‰1 Base64 characters (with padding)
Overhead33.3% size increase vs raw binary
1 byte input4 Base64 chars2 data chars + 2 padding
2 byte input4 Base64 chars3 data chars + 1 padding
3 byte input4 Base64 chars4 data chars + 0 padding
Padding RulePad with = until length is divisible by 4
Invalid CharactersAny char outside alphabet causes decode failure
Line Length (MIME)Max 76 chars per line (RFC 2045)
WhitespaceIgnored by most decoders (stripped before processing)
Empty InputDecodes to empty string (zero bytes)

Frequently Asked Questions

The native atob function decodes Base64 to a binary string where each character represents one byte. For multi-byte UTF-8 sequences (any codepoint above 127), a single character is split across 2 - 4 bytes. Reading them as individual Latin-1 characters produces mojibake. This tool converts the binary string to a Uint8Array and passes it through TextDecoder("utf-8") to correctly reassemble multi-byte sequences.
URL-safe Base64 replaces + with โˆ’ and / with _ to avoid conflicts in URLs and filenames. The tool auto-detects URL-safe encoding by checking for the presence of โˆ’ or _ characters, then substitutes them back to standard alphabet before calling atob. Missing padding is also restored automatically: if the length modulo 4 is 2, two = are appended; if 3, one = is appended.
This error occurs when the input contains characters outside the Base64 alphabet. Common culprits: curly quotes from word processors, BOM markers (U+FEFF), zero-width spaces, or accidental inclusion of surrounding JSON quotes. The tool pre-validates input with a strict regex and reports the exact position and character that caused the failure.
This converter targets text output (JavaScript source code). Binary payloads decoded as UTF-8 text will produce replacement characters (U+FFFD) or unreadable sequences. For binary data, you need a tool that outputs the raw byte stream as a downloadable file rather than displaying it as text.
The tool includes a hand-rolled JavaScript lexer that scans the decoded output character by character. It classifies tokens into categories: keywords (const, function, return), strings (single-quote, double-quote, backtick with template literal support), numbers (decimal, hex, binary, octal, exponential), comments (line and block), regex literals, operators, and punctuation. Each token is wrapped in a <span> with a CSS class for coloring. The lexer handles edge cases like regex vs division disambiguation and escaped characters within strings.
The tool processes input in the browser's main thread using native atob, which is highly optimized. Practical limits depend on available memory. Inputs up to approximately 5MB of Base64 text (decoding to ~3.75MB) work reliably in modern browsers. Syntax highlighting is disabled automatically above 100,000 characters of decoded output to prevent UI freezing.