Base64 Encode & Decode — Text, Image, URL

Runs entirely in your browser. Nothing is uploaded, so you can paste client data, tokens or keys without it leaving your machine. 全程本地运行,不上传任何内容。

UTF-8 safe: emoji and Chinese characters encode correctly, not as broken bytes.

如果是二进制内容(图片、压缩包),这里会给出十六进制预览,而不是乱码。

超过 100 KB 的图片转成 data URI 后会让 HTML 变得很重,网页里通常更该直接用图片文件。这里主要是给你做邮件签名、内嵌小图标、或者给 API 传图用。

反过来:data URI → 图片预览

粘贴 data:image/png;base64,...,立刻看到它是哪张图、多大、多少像素。用来判断一段 base64 到底是图片还是别的。

用 encodeURIComponent,会把空格变成 %20、中文变百分号编码——放进 URL 参数才不会断。

[ 广告/联盟位 —— 待填 ]

What Base64 actually does 原理

Base64 doesn't encrypt anything. It takes every 3 bytes (24 bits) and re-splits them into 4 characters of 6 bits each, using A–Z a–z 0–9 + /. The = at the end is padding, not data. So the output is about 33% larger than the input and can be read back by anyone — treat it as an encoding, never as protection.

因为只是编码不是加密,所以永远不要用 Base64 去“保护”密码、身份证号或者 API key——它一眼就能解开。

Base64 image encoder — when it helps and when it hurts

Turning an image into Base64 is only worth it in a few specific cases. In most web pages, a normal image file wins.

Use it whenDon't use it when
内嵌在 HTML 邮件签名或单文件报告里(对方邮箱会挡外链图片)正常网页里的产品图、banner —— 用文件更好,浏览器能缓存
给 API 传图(某些接口只收 base64 字段)图片大于 100 KB —— Base64 会让它变大约 33%,还阻塞首屏
小图标、loading 占位图(省一次请求)需要 CDN、需要响应式多尺寸的图
做离线单文件工具,不能引用外部资源图标多到几十个 —— CSS sprite 或字体图标更省

体积公式可以用:Base64 后大小 ≈ 原文件 × 1.37(含 data: 前缀和 padding)。一张 100 KB 的图会变成约 137 KB 的文本。

Common cases 常见场景

What you haveWhat to do
Windows 记事本存的 CSV 打开是乱码那不是 Base64 问题,是编码/BOM 问题 —— 见 CSV UTF-8 与 BOM
API 返回 {"content":"SGVsbG8="}用 Decode 页签,粘贴字符串(带不带 = 都行)
JWT token 中间那段看不懂那是 base64url(- _ 代替 + /),Decode 页签直接支持
邮件里要内嵌小图标Image 页签 → 转 data URI
URL 里的中文变成乱码URL 页签 → Encode URI

Frequently asked 常见问题

Is Base64 safe to use for passwords?

No. It's reversible by anyone with the string. Use it to move bytes through text-only channels, and use hashing (bcrypt/argon2) or real encryption for secrets.

Why does my decoded text look like gibberish?

The bytes probably aren't UTF-8 text — could be an image, a zip, or Latin-1 data. This tool falls back to a hex preview instead of printing broken characters.

Why is the output longer than the input?

Every 3 bytes become 4 characters, then padding is added. Expect roughly 33% growth, plus line breaks if whatever produced it wrapped lines.

Do you store what I paste?

No. There's no backend — the page is a single HTML file and all conversion happens in your browser's JavaScript. You can even save it and use it offline.

What's the difference between Base64 and Base64URL?

Base64URL swaps + for - and / for _ so the string can sit inside a URL or filename. This decoder accepts both.

How do I convert an image to Base64?

Open the Image tab, pick a file. It converts locally with FileReader.readAsDataURL, so nothing is uploaded. You'll get a data:image/...;base64, string you can paste into HTML, CSS or a JSON field.

How much bigger does Base64 make an image?

About 37% bigger including the data: prefix — a 100 KB PNG becomes roughly 137 KB of text. Base64 is meant for transport, not for storage or performance.

Can I turn a data URI back into an image file?

Yes — paste it into the preview box under the Image tab. It shows the image, its pixel size and its byte size, which is also a quick way to check whether a random Base64 string is an image at all.

为什么解码后中文是乱码?

原字符串不是按 UTF-8 编码的,或者被截断了。先确认它来自哪里(多数 API 用 UTF-8),再试一次。

[ 广告/联盟位 —— 待填 ]