💻

Base64 Encoder/Decoder

Encode and decode Base64 strings.

Base64 Encoder

Convert text to Base64 encoding

Enter your text above to convert it to Base64 encoding

Base64 Encoded Text

Base64 encoded text will appear here...

About Base64 Encoding

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It's commonly used when there is a need to encode binary data that needs to be stored and transferred over media designed to deal with text.

Common UsesEmail attachments, data URLs, API responses
Character SetA-Z, a-z, 0-9, +, /, = (padding)
Size Increase~33% larger than original binary data
URL SafeUses - and _ instead of + and /

Base64 Tool FAQ

1. What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It converts binary data into a set of 64 printable characters (A-Z, a-z, 0-9, '+', '/', and '=' for padding).

  • Example: The string "Hello" in Base64 is "SGVsbG8=".

2. Why is Base64 Encoding Used?

  • Safely transmit binary data over text-based protocols (e.g., email, JSON, XML)
  • Embed binary files (images, PDFs) in text formats like HTML or CSS
  • Avoid data corruption in systems that only support ASCII

3. How Does Base64 Encoding Work?

Base64 encoding works by:

  • Take 3 bytes (24 bits) of binary data
  • Split into four 6-bit chunks
  • Convert each 6-bit chunk into a corresponding Base64 character
  • If input isn't divisible by 3, padding (=) is added

4. What Characters Are Used in Base64?

  • Uppercase letters: A-Z
  • Lowercase letters: a-z
  • Digits: 0-9
  • Special characters: +, /
  • Padding: =

5. What is Base64 Padding (=)?

Padding (=) ensures the encoded string length is a multiple of 4:

  • If input length % 3 = 1 → Two = added
  • If input length % 3 = 2 → One = added
  • Example: "A" → "QQ=="
  • Example: "AB" → "QUI="

6. Is Base64 Encryption?

No, Base64 is encoding, not encryption. It does not provide security; it only changes data representation.

7. How to Encode a String to Base64 in Python?

Python Encoding:
import base64
encoded = base64.b64encode(b"Hello").decode('utf-8')
print(encoded)  # Output: "SGVsbG8="

8. How to Decode Base64 in Python?

Python Decoding:
import base64
decoded = base64.b64decode("SGVsbG8=").decode('utf-8')
print(decoded)  # Output: "Hello"

9. Can Base64 Data Contain Line Breaks?

Yes, some implementations (e.g., MIME email) insert line breaks every 76 characters for readability.

10. How to Encode/Decode Base64 in JavaScript?

JavaScript Encoding/Decoding:
// Encode
let encoded = btoa("Hello");  // "SGVsbG8="  

// Decode
let decoded = atob("SGVsbG8=");  // "Hello"

11. Does Base64 Increase Data Size?

Yes, by ~33%:

  • 3 bytes → 4 Base64 characters
  • Example: 6-byte input → 8-byte output

12. How to Encode a File to Base64?

Python File Encoding:
import base64
with open("image.png", "rb") as file:
    encoded = base64.b64encode(file.read()).decode('utf-8')

13. Is Base64 URL-Safe?

Standard Base64 uses + and /, which are unsafe in URLs. Use Base64URL (-, _, no padding).

  • Example: "Hello!" → "SGVsbG8h" (standard) → "SGVsbG8h" (Base64URL)

14. How to Handle Base64 in JSON?

JSON with Base64:
{
  "image": "SGVsbG8="
}

15. Can Base64 Decoding Fail?

Yes, if:

  • The string has invalid characters
  • Padding is incorrect

16. How to Remove Padding in Base64?

Some libraries allow encoding without padding (e.g., base64.urlsafe_b64encode in Python with omit_padding=True).

17. What's the Difference Between Base64 and Hex?

Comparison between Base64 and Hex encoding:

  • Base64: 6 bits/char (33% size increase)
  • Hex (Base16): 4 bits/char (100% size increase)
  • Example: "A" → Hex: "41", Base64: "QQ=="

18. How to Check if a String is Base64?

Python Validation:
import re
pattern = r'^[A-Za-z0-9+/]+={0,2}$'
is_base64 = bool(re.match(pattern, "SGVsbG8="))

19. Why Does Base64 Use = for Padding?

= is unused in Base64, making it a safe choice for padding.

20. How to Decode Base64 in Command Line (Linux)?

Linux Command Line:
echo "SGVsbG8=" | base64 --decode  # Output: "Hello"