How to Encode Text to Base64 (With Examples)
Base64 Encoding
When to Use Base64 Encoding
Use Base64 encoding when you need to represent binary or text data in an ASCII-safe format — for JSON payloads, data URIs, email attachments, JWT segments, or API fields that only accept text.
Real-World Examples
Plain text: Hello → SGVsbG8=
Credentials header: user:pass → dXNlcjpwYXNz
Unicode: café → UTF-8 bytes encoded as Base64
Common Mistakes
- Treating Base64 as encryption — it is encoding only and fully reversible
- Double-encoding output that was already Base64
- Assuming all Base64 uses the same alphabet (URL-safe variants use
-_instead of+/) - Including line breaks in payloads that expect a single continuous string
Edge Cases
- Empty input returns a validation message — enter text before encoding
- Padding (
=) appears when input length is not a multiple of 3 bytes - Large files inflate size by roughly 33% — avoid Base64 for big binary transfers when raw bytes are supported
Security Considerations
Anyone can decode Base64 instantly. Never use it to hide passwords, API keys, or sensitive data. For secrets, use proper encryption and key management.
Developer Tips
- Browser:
btoa()for ASCII; useTextEncoderfirst for Unicode - Node.js:
Buffer.from(str).toString('base64') - Python:
base64.b64encode(data)
Frequently asked questions
Does Base64 encoding compress data?
No. Base64 increases size by about 33% because it represents 3 bytes as 4 ASCII characters.
Can I encode binary files with this tool?
Yes. Use Upload file to select an image, PDF, or other binary file — bytes are read locally in your browser (up to 5 MB) and never uploaded. You can also paste UTF-8 text as before.
Why does my output end with = or ==?
Padding characters align the output to a multiple of 4 characters. They are normal and required for standard Base64.