---
title: Encoding / Decoding base64 Strings in the Terminal
description: Sometimes you need to deal with base64 strings, here are a couple commands that make it easy to encode/decode those strings using the terminal
date: 2021-01-22
tags: base64, Terminal
source: https://brianchildress.co/blog/encoding-decoding-base64-terminal
---

# Encoding / Decoding base64 Strings in the Terminal

Sometimes you need to deal with base64 strings, here are a couple commands that make it easy to encode/decode those strings using the terminal. I deal with various types of authentication strings a lot, which are often base64 encoded, and often need to quickly test and verify the base64 values I'm using.

In your terminal you have access to the _base64_ program from the _coreutils_ package installed on your machine by default. Using a simple `echo` statement we can encode/decode a base64 string. Here's an example:

### Encoding

```sh
echo -n < string to interpret > | base64
```

```sh
echo -n testuser:testpass | base64
```
** Note: adding the `-n` flag to the echo statement prevents `echo` from inserting a new line statement by default, with possible unintended consequences (Thanks Tomasz 🎉)

### Decoding

Decoding a base64 string just requires us to use the `--decode` flag.

```sh
echo -n < string to interpret > | base64 --decode
```

```sh
echo -n dGVzdHVzZXI6dGVzdHBhc3MK | base64 --decode 
```

_**Result:** testuser:testpass_
