Base64 Encoder.
Encode and decode text, files, and images to Base64. Generate data URLs, encode for JWT, and convert to URL-safe Base64 — all 100% in your browser.
Loading Encoder...
How to Use
Choose a Mode
Text ⇌ Base64 for strings, File → Base64 to encode any file, Image Preview to render a Base64 image, or URL-Safe for JWT/URL-compatible encoding.
Enter or Upload
For text modes: paste your input and choose Encode or Decode. For File mode: drag-and-drop or click to select any file type — image, PDF, document, etc.
Copy or Download
The result appears instantly. Copy to clipboard with one click, download as a .txt file, or use the data URL directly in your HTML or CSS.
How Base64 Works
Encoding Algorithm
3 bytes → 4 chars | size × 4/3 ≈ +33%
Each 3-byte group is split into four 6-bit values. Each 6-bit value maps to one of 64 characters.
A–Z (0–25), a–z (26–51), 0–9 (52–61), + (62), / (63)
Added when input bytes are not divisible by 3
+ → −, / → _, = stripped for URL/JWT safety
Worked Examples
Example 1: Encoding "Man" to Base64
ASCII bytes: M=77, a=97, n=110
- 01Binary: 01001101 01100001 01101110 (24 bits)
- 02Split into 6-bit groups: 010011 | 010110 | 000101 | 101110 → 19, 22, 5, 46
- 03Map to characters: T, W, F, u
"Man" → "TWFu" (4 characters, no padding needed)
3 input bytes → 4 output characters. Exactly the 4/3 ratio.
Example 2: Encoding "Ma" (padding required)
Input is 2 bytes — not divisible by 3
- 01Binary: 01001101 01100001 (16 bits)
- 02Pad to 18 bits: 010011 | 010110 | 000100 → 19, 22, 4
- 03Map to: T, W, E + one = padding
"Ma" → "TWE=" (one padding character)
2 bytes → 4 chars with one =. Only 1 byte → 4 chars with two ==.
Example 3: Image data URL in HTML
Embedding a small icon directly in HTML without a separate HTTP request
- 01Encode icon.png → Base64 string (e.g. iVBORw0KGgo...)
- 02Construct data URL: data:image/png;base64,iVBORw0KGgo...
- 03Use in HTML: <img src="data:image/png;base64,iVBORw0KGgo...">
Image loads inline with zero HTTP requests
Ideal for icons under ~2 KB. Above that, a separate file request is faster due to browser caching.
Complete Guide
Base64 is one of those encoding schemes that quietly underpins a huge portion of the internet — from the images in your email newsletter to the authentication token in your app's HTTP header. Understanding it is essential for any web developer, and having a reliable, private encoder/decoder is a daily tool in the developer toolkit.
Pro Tip: If you need to debug a JWT token, use the Text ⇌ Base64 mode in Decode direction. A JWT is three Base64URL segments separated by dots. Decode the first two (header and payload) to read the token claims — just remember to add back = padding if needed before decoding (URL-safe Base64 strips it).
The Four Modes Explained
Text ⇌ Base64 is the most common mode. It handles full Unicode text correctly — including Hindi (Devanagari), Tamil, emoji, and CJK characters — using TextEncoder for UTF-8 encoding before btoa(). The Flip button swaps input and output, letting you round-trip data without copy-pasting. Input and output sizes are shown in bytes, and the size ratio is displayed so you can see the overhead of encoding.
File → Base64 reads any local file using the browser's FileReader API and outputs both the raw Base64 string and the complete data URL (data:[mimeType];base64,[data]). This is the fastest way to get a data URL for a CSS background image, an email-embedded image, or a self-contained HTML attachment.
Image Preview takes a Base64 string or data URL and renders it visually, letting you verify the image before using it in production. This is invaluable when debugging Base64 images that aren't displaying correctly — you can immediately see whether the encoding is valid or if there is a MIME type mismatch.
URL-Safe Base64 produces output compatible with URLs, filenames, and JWT tokens by substituting the two problematic characters: + becomes - (hyphen) and / becomes _ (underscore), and padding = is stripped. This is the format specified in RFC 4648 §5 and used by OAuth 2.0, PKCE code challenges, and all modern JWT implementations.
Base64 in Web Development
The most common use case developers encounter is embedding small assets — icons, logos, loading spinners — directly in CSS or HTML as data URLs. This trades file size (the 33% Base64 overhead) for reduced HTTP requests. For small files below about 2 KB, the tradeoff is usually worthwhile, especially for critical above-the-fold assets. For larger assets, a cached HTTP request is almost always more efficient.
Font embedding is another powerful use case. Embedding a subset of a custom font in your CSS eliminates the FOUT (Flash of Unstyled Text) on first load. Use File → Base64 mode, encode your .woff2 file, and construct the @font-face rule with the data URL as the source. This approach is particularly useful for email templates where linked font URLs are often blocked by email clients.
Base64 vs Encryption: A Critical Distinction
A very common misconception is that Base64-encoded data is "hidden" or "secure." It is not — at all. Base64 is purely a representational format. Any tool, including this one, can decode Base64 instantly with no key or secret. If you need to protect data, use real encryption: AES-256 for symmetric encryption or RSA/ECDH for asymmetric. Base64 is often used alongside encryption (e.g., the ciphertext might be Base64-encoded for transmission), but the encoding itself contributes zero security.
This matters in practice: never Base64-encode passwords, API keys, or sensitive personal data and assume they are safe. HTTPS protects data in transit, but if Base64-encoded credentials are stored in browser localStorage, cookies, or source code, they are trivially extractable.
Unicode and Charset Handling
JavaScript's built-in btoa() function only accepts "binary strings" — strings where each character's code point is between 0 and 255. Passing a Unicode string with characters above U+00FF (like most Indian scripts, CJK characters, or emoji) directly to btoa() throws an InvalidCharacterError. Our tool handles this correctly by first encoding the text to UTF-8 bytes using TextEncoder, then passing the resulting byte string to btoa(). The reverse decoding uses TextDecoder for clean UTF-8 interpretation.
More Developer Tools
Free utility and developer tools
Binary Converter
Decimal, binary, hex, octal
Random Password Generator
Strong secure passwords
URL Encoder Decoder
Percent-encode URLs
Hash Generator
MD5, SHA-1, SHA-256
JSON Formatter
Beautify & validate JSON
Word Counter
Words, chars & reading time
Time Calculator
Add & subtract time
Date Calculator
Days between dates
GPA Calculator
Semester GPA & CGPA
Countdown Timer
Study & Pomodoro timer
Base64 FAQ Hub
Everything you need to know about Base64 encoding and decoding.
1. What is Base64 encoding?
Base64 converts binary data to 64 printable ASCII characters (A-Z, a-z, 0-9, +, /). Every 3 bytes become 4 characters, increasing size by ~33%. Used to pass binary data through text-only protocols.
2. Why is Base64 used?
Used to embed images in HTML/CSS as data URLs, encode email attachments (MIME), transmit binary in JSON APIs, and encode JWT tokens.
3. How does Base64 work?
3 bytes (24 bits) → 4 groups of 6 bits → 4 Base64 characters. If input is not divisible by 3, = padding is added.
4. How do I decode a Base64 string?
Paste your Base64 string, select Decode direction, click Convert. Invalid strings show an error with guidance on what to fix.
5. What is URL-safe Base64?
Replaces + with -, / with _, and removes = padding. Safe for use directly in URLs, query strings, filenames, and JWT tokens without percent-encoding.
6. What is a Base64 data URL?
Format: data:[mediatype];base64,[data]. Embeds file content directly in HTML/CSS without a separate HTTP request. Best for small files under ~10 KB.
7. Does Base64 encrypt data?
No — Base64 is encoding, not encryption. It provides zero security. Anyone can decode it instantly. Use AES/RSA for actual encryption.
8. Why does Base64 increase file size?
3 bytes → 4 characters = 33% overhead. A 100 KB file becomes ~133 KB encoded. This is the tradeoff for text-compatibility.
9. Standard Base64 vs Base64URL difference?
Standard: + and / as special chars, = padding. Base64URL: - and _ instead of + and /, no padding. Used in JWTs and OAuth tokens.
10. How do I convert an image to Base64?
Use File → Base64 mode. Drop/select your image. Tool outputs the Base64 string and a ready-to-use data URL for HTML or CSS.
11. Is online Base64 encoding safe?
Yes — HQCalc runs 100% in your browser using btoa()/atob() and FileReader API. Nothing is sent to any server.
12. What does = padding in Base64 mean?
= (one) or == (two) appended when input is not divisible by 3. Makes output length a multiple of 4. URL-safe Base64 strips padding.
13. Can I use Base64 in HTML email?
Yes. MIME uses Base64 for attachments. You can also embed small images as data URLs to avoid broken image links in email clients.
14. What is Base64 in JWT?
JWT uses Base64URL for its three parts (header, payload, signature). Each JSON part is Base64URL-encoded and joined by dots.
15. What characters are valid in Base64?
A-Z, a-z, 0-9, +, / (64 chars) plus = for padding. Any other character is invalid. URL-safe replaces + with - and / with _.
16. How do I embed a font as Base64 in CSS?
File → Base64 mode, encode your .woff2 file, then use: @font-face { src: url('data:font/woff2;base64,[B64]') format('woff2'); }
17. Max file size for Base64 in browser?
No algorithmic limit, but data URLs over ~2 MB can cause browser performance issues. For large files, prefer direct upload instead.
18. How do I decode a Base64 image?
Use Image Preview mode. Paste the Base64 or full data URL — the tool renders the image in browser so you can visually verify it.
19. Which charset should I use?
Always UTF-8 for modern text (handles all Unicode including Hindi/Tamil scripts, emoji). Use ISO-8859-1 only for legacy Latin data.
20. btoa() vs Buffer.from() in JavaScript?
btoa() needs a binary string (must encode UTF-8 first). Buffer.from(str, "utf8").toString("base64") is the Node.js equivalent. Our tool handles UTF-8 correctly with TextEncoder + btoa().