B64
Encoding
Base64 Encoding FAQ — Encode, Decode & Data URIs
Everything you need to know about Base64 encoding and decoding. Learn when to use Base64, how data URIs work, and the difference between Base64 and encryption.
Q1 What is Base64 encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into a sequence of 64 printable ASCII characters (A-Z, a-z, 0-9, +, /). It is used to safely transmit binary data over text-only channels like email (MIME), JSON, and URLs. Use the Base64 Encoder/Decoder to encode or decode instantly.
Q2 How do I decode Base64?
Paste the Base64 string into the Base64 Decoder and click "Decode". In code: JavaScript —
atob(base64String); Python — import base64; base64.b64decode(encoded).decode("utf-8"); CLI — echo "SGVsbG8=" | base64 -d.
Q3 Is Base64 the same as encryption?
No. Base64 is an encoding, not encryption. It transforms data into a different representation but provides zero confidentiality — anyone can decode it. Never use Base64 to protect secrets. For encryption, use AES-256 or RSA. Base64 is for transport safety (ensuring binary data survives text channels), not data security.
Q4 Why does Base64 increase file size?
Base64 represents every 3 bytes of input as 4 ASCII characters, resulting in a ~33% size increase. Additionally, the padding character
= is added to make the output length a multiple of 4. This overhead is the trade-off for safe text-based transport. For large files, prefer binary transfer (multipart upload) over Base64.
Q5 What is a Base64 data URI?
A data URI embeds a file directly in HTML or CSS using the format
data:[mediatype];base64,[data]. Example: data:image/png;base64,iVBOR.... This eliminates an HTTP request but increases page size by ~33%. Use data URIs for small images (<5 KB) like icons. Convert images with the Image to Base64 Converter.
Q6 How do I encode Base64 in JavaScript?
Use
btoa(string) to encode and atob(string) to decode. For Unicode text: btoa(unescape(encodeURIComponent(text))) or use TextEncoder: btoa(String.fromCharCode(...new TextEncoder().encode(text))). In Node.js: Buffer.from(text).toString('base64').
Q7 How do I encode Base64 in Python?
Use the
base64 module: import base64; encoded = base64.b64encode(b'Hello').decode('ascii'). To encode a string: base64.b64encode(text.encode('utf-8')).decode('ascii'). To decode: base64.b64decode(encoded).decode('utf-8').
Q8 What is Base64url encoding?
Base64url is a URL-safe variant that replaces
+ with - and / with _, and omits padding (=). This makes it safe for URLs, query parameters, and filenames without percent-encoding. JWTs use Base64url for their header and payload segments.
Q9 When should I use Base64?
Use Base64 when: (1) embedding binary data in JSON or XML; (2) encoding email attachments (MIME); (3) creating data URIs for small images in HTML/CSS; (4) storing binary data in text-only databases; (5) passing binary data in URL parameters. Avoid Base64 for large files (use binary upload) or for security (use encryption instead).
Q10 How do I decode Base64 in the command line?
macOS/Linux:
echo 'SGVsbG8gV29ybGQ=' | base64 -d. Windows PowerShell: [System.Convert]::FromBase64String('SGVsbG8='). To encode: echo -n 'Hello' | base64. The -n flag prevents a trailing newline from being included.
Q11 Can Base64 contain special characters?
Standard Base64 output uses only A-Z, a-z, 0-9, +, /, and = (padding). It never contains spaces, newlines, or other special characters in the encoded output. However, some implementations insert line breaks every 76 characters (MIME standard). The input can be anything — Base64 safely encodes all binary data.
Q12 What is the difference between Base64 and Base32?
Base64 uses 64 characters (A-Z, a-z, 0-9, +, /) and produces shorter output. Base32 uses 32 characters (A-Z, 2-7) and produces ~60% longer output but is case-insensitive, which makes it better for contexts where case matters (DNS, file systems). TOTP codes (Google Authenticator) use Base32 for secrets.
Q13 How do I Base64 encode a file?
CLI:
base64 < file.pdf > encoded.txt. Python: import base64; encoded = base64.b64encode(open('file.pdf','rb').read()). JavaScript (Node): fs.readFileSync('file.pdf').toString('base64'). For images, use the Image to Base64 Converter for a visual drag-and-drop experience.
Q14 Is Base64 encoding reversible?
Yes, Base64 encoding is fully reversible. You can always decode Base64 back to the original binary data without any loss. This is by design — Base64 is a lossless encoding scheme, not a hash or compression algorithm.
Q15 Why do APIs use Base64?
APIs use Base64 to embed binary data (images, PDFs, certificates) in JSON payloads, which only support text. HTTP Basic Authentication also uses Base64 to encode
username:password in the Authorization header. It ensures safe transport through systems that might corrupt raw binary data.
Q16 How do I encode an image to Base64?
Drag your image into the Image to Base64 Converter to get a ready-to-use data URI. In code: Python —
base64.b64encode(open("img.png","rb").read()).decode(). The result can be used directly in <img src="data:image/png;base64,...">.
Q17 What is the padding in Base64?
Base64 processes input in 3-byte blocks. If the input length is not a multiple of 3, padding characters (
=) are added to make the output a multiple of 4 characters. One leftover byte produces == padding; two leftover bytes produce =. Base64url encoding often omits padding since it can be inferred.
Q18 Can I use Base64 in CSS?
Yes. Use data URIs in CSS
background-image: background-image: url(data:image/svg+xml;base64,PHN2Zy...);. This eliminates an HTTP request and is ideal for small icons and SVGs under 5 KB. For larger images, use regular URLs with caching — Base64 increases CSS file size and blocks rendering.
Q19 How do I decode Base64 in Java?
Java 8+:
byte[] decoded = java.util.Base64.getDecoder().decode(encodedString); and String text = new String(decoded, StandardCharsets.UTF_8);. To encode: String encoded = java.util.Base64.getEncoder().encodeToString(bytes);. For URL-safe encoding, use getUrlEncoder().
Q20 Does Base64 work with Unicode?
Yes, but you must encode the text to bytes first (UTF-8), then Base64-encode those bytes. In JavaScript:
btoa(unescape(encodeURIComponent(unicodeString))). In Python: base64.b64encode(text.encode("utf-8")). Direct btoa() in browsers throws an error for characters outside Latin-1.
Free Encoding Tools
All tools run in your browser — no signup, no data sent to servers.