base32 - Linux


The base32 command is used in Linux to encode and decode data using the Base 32 encoding scheme as defined in RFC 4648. This tool is primarily used for turning binary data into ASCII text so that it can be easily transmitted or stored in environments that handle textual data more effectively than binary data. base32 is particularly useful in email handling and other applications where binary data needs to be encoded to avoid issues with non-printable characters.


The basic usage of the base32 command is as follows:

base32 [OPTION]... [FILE]

If the FILE argument is omitted or if it is -, base32 will read from the standard input. You can specify multiple files, and all files will be encoded sequentially.


Here is a list of the common options available for the base32 command:

  • -d, --decode: Decode data. Convert from Base 32 string back to the original binary form.
  • -i, --ignore-garbage: When decoding, ignore non-alphabet characters.
  • -w, --wrap=COLS: Wrap encoded lines after COLS columns (default is 76). Use 0 to disable line wrapping.
  • --help: Display a help message and exit.
  • --version: Output version information and exit.


Basic Encoding

To encode a file named input.txt:

base32 input.txt

This command will output Base 32 encoded data to the standard output.

Basic Decoding

To decode a file that has been Base 32 encoded:

base32 --decode input.b32

Encoding and Wrapping the Output

To encode a file and wrap the output every 40 characters:

base32 --wrap=40 input.txt

Decoding and Ignoring Non-Alphabet Characters

To decode while ignoring non-alphabet characters (useful when data may contain formatting or spacing):

base32 --decode --ignore-garbage input.b32

Common Issues

  • Incorrect Padding: When decoding, incorrect padding can cause the base32 command to fail or produce incorrect output. Ensuring proper encoding and using the --ignore-garbage option can mitigate some issues.
  • File I/O Errors: Errors related to file permissions or non-existent files. Ensure that the files exist and appropriate permissions are granted.


base32 integrates well with other commands via piping. For instance, to encode and then gzip a file:

cat file.txt | base32 | gzip > file.txt.b32.gz

To decode, revisit the steps in reverse:

gunzip -c file.txt.b32.gz | base32 --decode > original_file.txt
  • base64: Similar to base32 but uses a 64-character set for encoding. Useful when a more compact representation is needed.
  • xxd: A tool to create a hex dump of a given binary file and also to convert a hex dump back to the original.

For additional details, check the man pages (man base32) or the GNU coreutils online documentation.