Session and utilities
The base64 command
Encodes data as plain text using the Base64 alphabet, and decodes it back.
Most useful options
-d, --decodeDecodes instead of encoding-i, --ignore-garbageWhen decoding, ignores characters that are not in the alphabet-w, --wrap COLSWraps the output every COLS characters (76 by default). With 0, everything on one line--helpShows the help and exits--versionShows the version and exitsCopy-ready examples
$ echo hola | base64encodes the text that comes through the pipe.Example output
aG9sYQo=
$ printf 'aG9sYQo=\n' > b64.txt && base64 -d b64.txtdecodes a file and shows the original text.Example output
hola
$ echo 'aG9s!YQo=' | base64 -d -iignores the character that is not in the alphabet and decodes the rest.Example output
hola
$ echo 'texto largo para una sola linea' | base64 -w 0encodes without line breaks, useful when the result goes to another program.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| base64: invalid input | The data has characters that are not Base64 or is malformed. The file may not have been encoded at all. | Check the source. If there is noise or extra line breaks, try -i. |
| base64: noexiste: No such file or directory | The file you passed does not exist or is misspelled. | List the folder with ls and copy the exact name. |
| base64: extra operand 'archivo2.txt' | You passed more than one file: base64 accepts only one, or standard input. | Encode each file separately, or join the contents first with cat. |
Typical mistakes
- base64 does not encrypt or protect: anyone can decode it. It is not security.
- Without -w 0, the output is split into lines of 76 characters. If you will use it on one line, pass -w 0.
- Decoding something that was not Base64 does not give back the original: it gives an error or meaningless bytes. Check what you have first.
Differences from similar commands
basenc: also encodes in base32 or base16, among other alphabets, with the same -d and -i options.- xxd: shows the bytes in hexadecimal, to inspect them. base64 turns them into text to carry them around.
FAQ
Why does the output have line breaks?
Because base64 wraps lines every 76 characters by default. With -w 0 everything is printed in one run.
Does base64 hide a password?
No. It is a reversible encoding with no key: anyone can decode it in seconds.
What does invalid input mean when decoding?
The input contains characters that are not in the Base64 alphabet. With -i they are ignored, although the result may not be the original.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course