← Back to Blog

Base64 Encode in JavaScript: btoa, Buffer, TextEncoder

Complete guide to Base64 encoding in JavaScript: btoa/atob, Node.js Buffer, TextEncoder for Unicode, and handling binary data.

Browser: btoa() and atob()

// Encode\nconst encoded = btoa('Hello World');\n// Decode\nconst decoded = atob(encoded);\n\n// Unicode-safe (btoa fails on non-Latin1)\nconst utf8Encode = btoa(unescape(encodeURIComponent('Hello 🌍')));\nconst utf8Decode = decodeURIComponent(escape(atob(utf8Encode)));

Node.js: Buffer

// Encode\nBuffer.from('Hello').toString('base64')\n// Decode\nBuffer.from(b64, 'base64').toString('utf-8')\n// URL-safe\nBuffer.from('Hello').toString('base64url')

Try It Free

Use our free online tool — 100% client-side, no data leaves your browser.

Open Base64 Tool

Related Tools & Articles