Skip to main content

RFC 4648 Base64 Encoder & Data URI Generator

Rate this tool 0 of 0 ratings
Additional page content: Editable from the admin panel -> tools content.

Programmatic Code Snippets: Base64 Encode String

How to implement Base64 Encode String programmatically in Python, Node.js, PHP, and CLI
CLI & API Syntax
Encode utf-8 text to base64 in Python 3
import base64

text = "Hello World! Toolbox24"
encoded_bytes = base64.b64encode(text.encode('utf-8'))
encoded_str = encoded_bytes.decode('utf-8')
print(encoded_str) # Output: SGVsbG8gV29ybGQhIFRvb2xib3gyNA==
Encode string to base64 in Node.js / JavaScript
const text = "Hello World! Toolbox24";
const encodedStr = Buffer.from(text, 'utf-8').toString('base64');
console.log(encodedStr); // Output: SGVsbG8gV29ybGQhIFRvb2xib3gyNA==
Encode string to base64 in PHP
<?php
$text = "Hello World! Toolbox24";
$encoded_str = base64_encode($text);
echo $encoded_str; // Output: SGVsbG8gV29ybGQhIFRvb2xib3gyNA==
Encode string to base64 in Linux / macOS Terminal
echo -n "Hello World! Toolbox24" | base64
Embed
Need this Base64 Encoder calculator on your website, lab portal, or research blog?
Free HTML Widget 100% Responsive Zero Cookie Tracking
Notice a calculation discrepancy, rounding error, or glitch?
Help us maintain 100% scientific precision and report any issues directly to engineering.