Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


A robust base64 encoder/decoder that is fully compatible with `atob()` and btoa()`, written in JavaScript.

Subscribe to updates I use base64

Statistics on base64

Number of watchers on Github 281
Number of open issues 4
Average time to close an issue 1 day
Main language JavaScript
Open pull requests 2+
Closed pull requests 1+
Last commit over 4 years ago
Repo Created almost 6 years ago
Repo Last Updated about 2 years ago
Size 18 KB
Organization / Authormathiasbynens
Page Updated
Do you use base64? Leave a review!
View open issues (4)
View base64 activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating base64 for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

base64 Build status Code coverage status Dependency status

base64 is a robust base64 encoder/decoder that is fully compatible with atob() and btoa(), written in JavaScript. The base64-encoding and -decoding algorithms it uses are fully RFC 4648 compliant.


Via npm:

npm install base-64

Via Bower:

bower install base-64

Via Component:

component install mathiasbynens/base64

In a browser:

<script src="base64.js"></script>

In Narwhal, Node.js, and RingoJS:

var base64 = require('base-64');

In Rhino:


Using an AMD loader like RequireJS:

    'paths': {
      'base64': 'path/to/base64'
  function(base64) {



A string representing the semantic version number.


This function takes a byte string (the input parameter) and encodes it according to base64. The input data must be in the form of a string containing only characters in the range from U+0000 to U+00FF, each representing a binary byte with values 0x00 to 0xFF. The base64.encode() function is designed to be fully compatible with btoa() as described in the HTML Standard.

var encodedData = base64.encode(input);

To base64-encode any Unicode string, encode it as UTF-8 first:

var base64 = require('base-64');
var utf8 = require('utf8');

var text = 'foo  bar  baz';
var bytes = utf8.encode(text);
var encoded = base64.encode(bytes);
//  'Zm9vIMKpIGJhciDwnYyGIGJheg=='


This function takes a base64-encoded string (the input parameter) and decodes it. The return value is in the form of a string containing only characters in the range from U+0000 to U+00FF, each representing a binary byte with values 0x00 to 0xFF. The base64.decode() function is designed to be fully compatible with atob() as described in the HTML Standard.

var decodedData = base64.decode(encodedData);

To base64-decode UTF-8-encoded data back into a Unicode string, UTF-8-decode it after base64-decoding it:

var encoded = 'Zm9vIMKpIGJhciDwnYyGIGJheg==';
var bytes = base64.decode(encoded);
var text = utf8.decode(bytes);
//  'foo  bar  baz'


base64 is designed to work in at least Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.9, PhantomJS 1.9.0, Rhino 1.7RC4, as well as old and modern versions of Chrome, Firefox, Safari, Opera, and Internet Explorer.

Unit tests & code coverage

After cloning this repository, run npm install to install the dependencies needed for development and testing. You may want to install Istanbul globally using npm install istanbul -g.

Once thats done, you can run the unit tests in Node using npm test or node tests/tests.js. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use grunt test.

To generate the code coverage report, use grunt cover.


Mathias Bynens


base64 is available under the MIT license.

base64 open issues Ask a question     (View All Issues)
  • about 4 years Legal comment is removed when package is bundled and uglified
  • over 5 years Float32Array supported?
base64 open pull requests (View All Pulls)
  • base64 import
  • Add yarn command
base64 questions on Stackoverflow (View All Questions)
  • How to save a picture in database sent from android by base64 encoding through PHP?
  • image onload not firing javascript when source is base64 websocket data
  • Getting Error Domain=NSCocoaErrorDomain Code=3840 while sending base64 string to the server
  • Paperclip::AdapterRegistry::NoHandlerError while image upload from base64 using paperclip gem in ruby on rails?
  • PHP Base64 encoding for JSON slash issue
  • How to display a base64 image within a UIImageView?
  • blob filereader output appears to be empty (data:;base64,/9j/4AAAAAA...)
  • Create image file (Base64 to blob) using Google Appscript
  • JSZip won't load a zip from a base64 string?
  • php function for encrypt/decrypt (like base64)
  • Meteor displaying base64 image in HTML
  • Upload Base64 string to Google Cloud Storage
  • Noisy audio clip after decoding from base64
  • Powershell 2.0 broken Base64 file conversion
  • how to convert image url to dataurl (base64 data) with javascript
  • Submitting Base64 CSR to a Microsoft CA (via cURL)
  • Angularjs convert bitmap object to base64 format
  • Fmx TMemo unable to show a base64 string appropriately
  • Sending a string over Base64 in Soap request
  • reverse base64 encode and gzcompress
  • NSData won't accept valid base64 encoded string
  • java mail Base64 encoded string to image attachment
  • Convert Base64 from PDF to Bitmap
  • How to cache base64 encode image
  • Base64 Image upload with Laravel and S3 resulting in blank white square with border
  • How to convert bitmap to PNG and then to base64 in Android?
  • Re-sizing an image which in Base64 format and converting to Base64 again in java
  • Binary Data in JSON String. Something better than Base64
  • Ionic broken base64-encoded image
  • Nodemailer send base64 data URI as attachment. How?
base64 list of languages used
Other projects in JavaScript