I notice online encryption tools encrypt the plaintext and output the ciphertext in base64 format. Why is ciphertext outputted in base64 format? Can the ciphertext be outputted in binary format?

  • 1
    You can translate that data into any base, it just happens that Base64 is well suited for the web; it's composed of characters that are safe to use in URLs. – user229044 Mar 17 '19 at 0:42
  • it avoids issue with special, reserved, and control characters, allowing the ciphertext to use all 255 combos per byte. – dandavis Mar 18 '19 at 18:43

Ciphertext can be output in binary format. For example, gpg defaults to binary format, and you need to specify --armor to make it base64:

    Create ASCII armored output. The default is to create the binary OpenPGP format. 

The reason you see ASCII/base64 more often is that it is easier to transfer and manipulate than binary. SMTP email, for example, cannot handle binary data without encoding it, so having a non-binary format makes it simpler to email encrypted text. FTP may default to non-binary mode which will introduce errors when transferring a binary file. Even something as simple as popping open a file in an editor to make sure it "looks like it's there" is easier with non-binary formats.


A web browser has to print a visual representation of the binary data. The usual visual representation of binary data is the hexadecimal notation.

Now observe: The space overhead of hex-encoded data is factor 2 (we need 2 ascii characters for one byte). The space overhead of base64-encoded data is only 1.33, making it more space-efficient than hex-encoded data.

Moreover, I suspect that the tool support for base64-encoded data is at least as good as for hex-encoded data.

For instance, you can copy-paste a base64-encoded ciphertext directly into a PEM file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.