Base64 : Java Glossary


Introduction Implementations
Three Kinds of Base64 Learning More
Under the Hood Links


A way of encoding 8-bit characters using only ASCII (American Standard Code for Information Interchange) printable characters similar to UUENCODE. UUENCODE embeds a filename where BASE64 does not. You will see BASE64 used in encoding digital certificates, in encoding user:password string in an Authorization: header for HTTP (Hypertext Transfer Protocol) . The spec is described in RFC (Request For Comment) 2045.

Don’t confuse it with x-www-form-urlencoded which is handled by encode/decode.

This process of converting binary data to printable characters as sometimes called armouring because it protects the data from transport systems that meddle with, ignore or act on control characters embedded in the data.

Three Kinds of Base64

There are actually three kinds of base64:

  1. Basic. Single line. Uses table 1 of RFC 4648 and RFC 2045.
  2. URL (Uniform Resource Locator) and Filename safe. Single line. uses table 2 of RFC 4648
  3. MIME (Multipurpose Internet Mail Extensions) Multiline. What is usually meant by base64. Uses Table 1 of RFC 2045

Under the Hood

BASE64 is a scheme where 3 bytes are concatenated, then split to form 4 groups of 6-bits each; and each 6-bits gets translated to an encoded printable ASCII character, via a table lookup. An encoded string is therefore longer than the original by about 1/3. The = character is used to pad the end out to an even multiple of four.

Base 64 armouring uses only the characters A-Z, a-z, 0-9 and +/=. This makes it suitable for encoding binary data as SQL (Standard Query Language) strings, that will work no matter what the encoding. Unfortunately + / and = all have special meaning in URLs (Uniform Resource Locators).


I have written source code for encoding/decoding BASE64 that you can download. Oracle has an undocumented method called sun.misc. BASE64Encoder. encode. There is a non-public class in Java 1.4+ called java.util.prefs.Base64. JavaMail MimeUtility.decode can encode and decode a number of encodings.

Learning More

Starting with JDK (Java Development Kit) 1.8, Java now has official Base64 support built in.

Oracle’s Javadoc on Base64 class : available:
Oracle’s Javadoc on javax.xml.bind.DataTypeConverter.printBase64 : available:

This page is posted
on the web at:

Optional Replicator mirror
on local hard disk J:

Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number