Image ⇄ Base64 Converter
Convert images to Base64 (data URLs or raw) and Base64 back to images. Everything runs locally in your browser.
Base64 in popular programming languages
Short, practical snippets + official docs.
const fs = require('fs'); // Encode file to base64 const b64 = fs.readFileSync('in.png').toString('base64'); // Decode base64 to file fs.writeFileSync('out.png', Buffer.from(b64, 'base64'));
const file = input.files[0]; const r = new FileReader(); r.onload = () => console.log(r.result); // data:image/png;base64,.... r.readAsDataURL(file);
import base64 b64 = base64.b64encode(open('in.png','rb').read()).decode('ascii') open('out.png','wb').write(base64.b64decode(b64))
$b64 = base64_encode(file_get_contents('in.png')); file_put_contents('out.png', base64_decode($b64, true));
import ("encoding/base64"; "os") b, _ := os.ReadFile("in.png") s := base64.StdEncoding.EncodeToString(b) d, _ := base64.StdEncoding.DecodeString(s) _ = os.WriteFile("out.png", d, 0644)
var bytes = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get("in.png")); var b64 = java.util.Base64.getEncoder().encodeToString(bytes); var out = java.util.Base64.getDecoder().decode(b64); java.nio.file.Files.write(java.nio.file.Paths.get("out.png"), out);
var b64 = Convert.ToBase64String(File.ReadAllBytes("in.png")); File.WriteAllBytes("out.png", Convert.FromBase64String(b64));
require "base64" b64 = Base64.strict_encode64(File.binread("in.png")) File.binwrite("out.png", Base64.decode64(b64))
base64 in.png > out.b64 base64 -d out.b64 > out.png
Learn more about Base64
Background & specification: → Wikipedia: Base64 · RFC 4648 — The Base16, Base32, and Base64 Data Encodings
Base64 FAQ
A binary-to-text encoding that represents bytes using 64 ASCII characters. Useful for embedding or transporting binary data in text channels.
No. It increases size by about ~33% (4 bytes for every 3 input bytes), plus any headers if you use a data URL.
A string like data:image/png;base64,....
that
inlines the bytes with a MIME type. This tool can include or strip this prefix.
Yes. The encoded string represents the original bytes exactly when decoded.
A variant that replaces +
//
with
-
/_
. This tool recognizes and decodes it.
Modern Base64 (RFC 4648) doesn’t require line breaks. Some older tools wrap at 76 chars; decoding ignores whitespace.
Browsers allow fairly large data URLs, but memory and performance will be your practical limits. For very large images, prefer file URLs.
Yes, if you encode the original bytes. Base64 is just a different representation of the same bytes.
No. Everything runs locally in your browser; files never leave your device.