How Base64 to Image Decoding Runs in Your Browser
Base64 exists because binary data does not survive text-only channels: email, JSON, and HTML must carry bytes as printable characters. The encoding maps every 3 input bytes to 4 characters from a 64-symbol alphabet, appending = padding when the input length is not divisible by three. Decoding reverses that mapping — and this page does it with atob(), the browser's native Base64 decoder. The string is first trimmed and checked for a data-URI prefix like data:image/png;base64,; when one is present, the declared MIME type is captured and the prefix stripped.
The decoded output of atob() is a binary string, where each character holds one byte's value. That string is copied into a Uint8Array by walking its code units — the same shape a fetched image file would have in memory. When no data-URI prefix was present, the format is resolved by magic-byte sniffing: the first bytes of the array are compared against the signatures of PNG (89 50 4E 47), JPEG (FF D8 FF), GIF (GIF8), and BMP (BM). Each of those signatures was chosen by its format's designers to be unmistakable, which is why sniffing is reliable enough to name the output file correctly.
The byte array is finally wrapped in a Blob with the detected MIME type — image/png, image/jpeg, and so on — and offered for download under an extension matched to the format, defaulting to PNG when nothing is detected. Because the entire pipeline uses only built-in browser primitives, it is instant, works offline, and can never leak the image: the string you paste is processed in memory by your own device and converted straight into a file that belongs to you.