If you are a developer, you have definitely encountered Base64. Whether you are dealing with Basic Authentication, embedding images directly into HTML, or passing data through a URL, Base64 encoding is the unsung hero of web development.
But how do you actually encode a string in your daily workflow? In this quick guide, we will break down the most common commands across different languages and show you a faster way to do it online.
1. Base64 Encode in JavaScript
In the browser, you can use the btoa() function. But remember, it only handles ASCII strings. If you need to handle Unicode, you have to do a bit of a workaround:
// Standard ASCII
const encoded = btoa("hello world");
// Unicode safe method
const unicodeSafe = btoa(unescape(encodeURIComponent("Hello 世界")));
2. Base64 Encode in Python
Python is arguably the easiest. You just need the built-in base64 module:
import base64
text = "hello world"
encoded = base64.b64encode(text.encode('utf-8')).decode('utf-8')
3. Base64 Encode in Command Line (Linux/Mac)
If you are a terminal ninja, you can use the base64 command. Note that on Linux you use -w 0 to remove line breaks, while on Mac you use -b 0.
# Linux echo -n "hello world" | base64 -w 0 # Mac echo -n "hello world" | base64
The Faster Way: Browser-Based Encoding
What if you just need to quickly encode a string, a password, or a certificate without opening your IDE? Copying and pasting code snippets every time is a waste of energy.
Try our free Base64 Encoder / Decoder. It runs 100% in your browser via JavaScript, meaning your sensitive text or API keys never touch a server. Just paste your string, hit encode, and you are done.
Stop switching between your terminal and your browser. Bookmark our privacy-first tool and encode strings instantly.