Skip to main content
Back to Tools

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

  1. 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.
  2. 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).
  3. 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).
  4. Copy and use. For a data URI, prepend data:image/png;base64, to the encoded output. For a Basic Auth header, encode username:password and prepend Authorization: Basic .

Base64 reference cheatsheet

Quick reference for the alphabet, size formula, data URI prefixes, and language APIs. Keep this open when building integrations.

ItemDetail
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 formulaceil(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 segmentFirst dot-separated part; URL-safe Base64, no padding
JWT payload segmentSecond 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:mysecret to get bXl1c2VyOm15c2VjcmV0, then send the header Authorization: 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: base64 to 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?+
Base64 encodes binary data as ASCII text using a 64-character alphabet (A-Z, a-z, 0-9, +, /). Use it when you need to embed binary data in a text-only context: JSON payloads carrying image bytes, email attachments (MIME), CSS data URIs (data:image/png;base64,...), and HTTP Basic Auth headers (Authorization: Basic dXNlcjpwYXNz). It is the standard answer to "how do I put binary in a string" without corrupting it.
Is Base64 encryption? Can I use it to secure passwords?+
No. Base64 is encoding, not encryption or hashing. Anyone can decode it in one function call. Never use Base64 to protect passwords, API keys, or sensitive data. For passwords use bcrypt or Argon2. For secrets in transit use TLS. Base64 only solves the "binary-to-text transport" problem, not the security problem.
Why does my Base64 string end with = or ==?+
Base64 groups input bytes in sets of 3 (24 bits) and encodes each group as 4 characters. If the input length is not divisible by 3, padding characters (=) are added to make the output length a multiple of 4. One = means 1 padding byte was added; == means 2. Some systems (JWTs, URL-safe Base64) strip the padding and require you to re-add it before decoding.
What is URL-safe Base64 and when does it matter?+
Standard Base64 uses + and / which have special meaning in URLs (+ is a space in query strings; / is a path separator). URL-safe Base64 replaces + with - and / with _ so the encoded string can sit directly in a URL without percent-encoding. JWT tokens use URL-safe Base64 without padding. If you paste a JWT segment into this tool and see garbled output, replace - with + and _ with / first.
How do I encode a file to Base64?+
In a browser you can use FileReader.readAsDataURL() which returns a full data URI (data:image/png;base64,...) or FileReader.readAsBinaryString() and then btoa(). In Node.js: Buffer.from(fs.readFileSync(path)).toString("base64"). In Python: base64.b64encode(open(path,"rb").read()).decode(). This tool handles text only; for binary files use one of those code paths.
Why does encoding non-ASCII text (Chinese, emoji) sometimes fail?+
The browser's btoa() only accepts Latin-1 (byte values 0-255). Multi-byte characters like Chinese glyphs or emoji have code points above 255, so calling btoa() directly throws "The string to be encoded contains characters outside of the Latin1 range". The fix is to UTF-8 encode first: btoa(unescape(encodeURIComponent(text))). This tool applies that automatically so you can safely encode any Unicode input.

Related developer tools

Sponsored

Ad served by Adsterra. OpenAIToolsHub is not responsible for advertiser content.