Base64 Encoder/Decoder
Encode text to Base64 or decode Base64 back to text. UTF-8 safe, handles Unicode and emoji. No signup required.
TL;DR. Switch between Encode and Decode, paste your text or Base64 string, and the result updates instantly. This tool wraps btoa() and atob() with a UTF-8 safety layer so Chinese characters, emoji, and any Unicode input encode correctly. Common use cases: embedding images as data URIs, decoding a JWT segment, building an HTTP Basic Auth header, or checking what a Base64 payload actually says.
How to use the Base64 converter
- Choose a direction. Select Encode to convert plain text to Base64, or Decode to convert a Base64 string back to text. The mode toggle is at the top left.
- Paste your input. For encoding, paste any text including Unicode characters. For decoding, paste a Base64 string. If you are decoding a JWT, paste only one segment at a time (the part between the dots), and swap any
-for+and_for/first (JWT uses URL-safe Base64 without padding). - Read the output. The result appears on the right in real time. If the output shows an error, you likely have non-Base64 characters in the input (spaces, line breaks from a copy-paste, or a URL-safe string that needs character substitution).
- Copy and use. For a data URI, prepend
data:image/png;base64,to the encoded output. For a Basic Auth header, encodeusername:passwordand prependAuthorization: Basic.
Base64 reference cheatsheet
Quick reference for the alphabet, size formula, data URI prefixes, and language APIs. Keep this open when building integrations.
| Item | Detail |
|---|---|
| Alphabet (standard) | A-Z (0-25), a-z (26-51), 0-9 (52-61), + (62), / (63) |
| Alphabet (URL-safe) | Same as standard but + replaced by -, / replaced by _ |
| Padding character | = appended to reach output length % 4 == 0 |
| Output size formula | ceil(n / 3) * 4 bytes, roughly 4/3 of input size |
| data:image/png;base64, | CSS/HTML data URI prefix for PNG images |
| data:image/jpeg;base64, | CSS/HTML data URI prefix for JPEG images |
| data:image/svg+xml;base64, | CSS/HTML data URI prefix for SVG images |
| Authorization: Basic ... | HTTP header value; payload is base64("user:password") |
| JWT header segment | First dot-separated part; URL-safe Base64, no padding |
| JWT payload segment | Second dot-separated part; URL-safe Base64, no padding |
| btoa() / atob() | Browser built-in encode / decode (Latin-1 only, UTF-8 needs wrapper) |
| Buffer.from(str, "base64") | Node.js decode (handles URL-safe and padding automatically) |
| base64.b64encode() / b64decode() | Python standard library standard variant |
| base64.urlsafe_b64encode() | Python standard library URL-safe variant |
Common patterns, ready to use
- HTTP Basic Authentication: Encode
myuser:mysecretto getbXl1c2VyOm15c2VjcmV0, then send the headerAuthorization: Basic bXl1c2VyOm15c2VjcmV0. Anyone who intercepts this can decode it instantly, so always use HTTPS. Basic Auth is transport-layer protection only. - Decoding a JWT header: Take the first segment before the dot, e.g.
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. Swap-for+and_for/, then decode. Result:{"alg":"HS256","typ":"JWT"}. The payload (second segment) reveals claims the same way. The signature (third segment) is binary - it will decode to garbage characters, which is expected. - Inline image in CSS: Encode a small PNG or SVG, then use it as
background-image: url('data:image/png;base64,iVBORw0K...'). This eliminates an HTTP request and is useful for icons under ~4 KB. Above that, a separate image file is smaller due to HTTP/2 multiplexing. - Storing binary in JSON: JSON has no binary type. If your API needs to carry an image, a PDF, or cryptographic bytes inside a JSON field, Base64-encode them and use a string field. Document the field as base64-encoded to avoid confusion for API consumers.
- Email MIME attachments: MIME (RFC 2045) uses
Content-Transfer-Encoding: base64to embed binary attachments in a text-based email message. Libraries like nodemailer and Python's email.mime handle this automatically, but if you are debugging a raw email, each attachment block is standard Base64 that this tool can decode.
Frequently asked questions
What is Base64 encoding and when should I use it?+
Is Base64 encryption? Can I use it to secure passwords?+
Why does my Base64 string end with = or ==?+
What is URL-safe Base64 and when does it matter?+
How do I encode a file to Base64?+
Why does encoding non-ASCII text (Chinese, emoji) sometimes fail?+
Related developer tools
- URL Encoder/Decoder
Percent-encode and decode URL components
- JSON Formatter
Pretty-print and validate JSON
- Hash Generator
MD5 / SHA-1 / SHA-256 in the browser
- Password Generator
Generate secure random passwords
Measured Base64 payload growth
The familiar "Base64 adds about 33%" rule is accurate only for larger inputs. The exact encoded length is 4 * ceil(bytes / 3), so padding dominates tiny values. We checked representative payload sizes before and after encoding; the table below is useful when deciding whether a Base64 field belongs in JSON or should move to object storage.
| Raw input | Encoded length | Growth | Practical implication |
|---|---|---|---|
| 1 byte | 4 bytes | 300% | Padding dominates |
| 100 bytes | 136 bytes | 36% | Fine for small API fields |
| 1 MiB | 1,398,104 bytes | 33.33% | Meaningful bandwidth cost |
| 10 MiB | 13,981,016 bytes | 33.33% | Prefer upload plus URL |
A worked example: a mobile client uploading ten 10 MiB images sends roughly 133 MiB of Base64 text before JSON framing, versus 100 MiB as binary multipart data. Base64 is still the right choice for compact tokens, certificates, and small embedded assets, but it is usually the wrong transport for large files. Also remember that readable Base64 is not protected data. For a side-by-side demonstration of the difference between encoding and actual authenticated encryption, use the browser-based encrypt and decrypt tool.