Base64 is a way to represent binary data as text. It isn’t encryption and it isn’t compression: it’s just an alphabet of 64 “safe” characters (letters, digits and two symbols) you can use to write any sequence of bytes so that it passes unharmed through text-only channels — email, JSON, URLs, config files. Whoever receives it decodes it and gets the original bytes back, identical.

The alphabet: 64 characters plus padding

The name says it: 64 symbols. They are the 26 uppercase letters, the 26 lowercase, the 10 digits and the two characters + and / — 64 in all, i.e. the values from 0 to 63. To these is added the padding character =, which carries no data but completes the last block.

index  0..25  →  A B C ... Z
index 26..51  →  a b c ... z
index 52..61  →  0 1 2 ... 9
index   62    →  +
index   63    →  /
padding       →  =

How it’s computed: 3 bytes become 4 characters

The trick is in the numbers: 3 bytes are 24 bits, and 24 splits exactly into four groups of 6 bits. Each 6-bit group is a number from 0 to 63 → one character of the alphabet. So every 3 input bytes produce 4 Base64 characters. Here it is on ABC:

text:         A           B           C
ASCII:       65          66          67
binary:   01000001    01000010    01000011
24 bits:  010000 010100 001001 000011     (regrouped by 6)
values:     16     20     9      3
alphabet:    Q      U     J      D
Base64:  ABC  →  QUJD

And when the bytes aren’t a multiple of 3? You complete the last group with zeros and add = to signal how many “real” bytes there were: 2 bytes → three characters + one =; 1 byte → two characters + ==.

"AB"  (2 bytes)  →  QUI=      (one =)
"A"   (1 byte)   →  QQ==      (two ==)

That’s why Base64 is about one third longer (+33%) than the original: you pay 4 characters for every 3 bytes. It’s the price of turning bytes into “pure text”.

What it’s actually for

Whenever you have to fit binary data into a container that accepts only text:

  • Email attachments (MIME): an image or a PDF travels as Base64 inside a text message.
  • Data URIs: an icon embedded straight into a page, data:image/png;base64,iVBOR….
  • JSON and APIs: binary fields (a photo, a signature) inside JSON, which is text.
  • HTTP Basic Auth: the Authorization: Basic … header is user:password in Base64 (careful: it’s encoding, not protection — it’s read in an instant; confidentiality comes only from HTTPS).
  • PEM certificates and keys: that -----BEGIN CERTIFICATE----- block followed by lines of letters and digits is the DER certificate in Base64.
  • Tokens and secrets printed “on one line” so you can copy them easily.

Remember: Base64 is reversible and public. It hides nothing — anyone can decode it. If a value must stay secret, you need encryption, not Base64.

The two variants (when the symbols get in the way)

The characters + and / cause trouble inside a URL (/ is a path separator) or in a file name. That’s why “URL-safe” Base64 exists, identical but with - instead of + and _ instead of /, often without the = padding. It’s what you find in tokens (e.g. JWT) and in many URL parameters. The content is the same: only which two symbols it uses changes.

RouterOS has the converter built in (RouterOS 7)

Yes: from the RouterOS 7 console the :convert command encodes and decodes Base64 on the fly, with no external tools.

# encode a string
:put [:convert "MikroTik Dojo" to=base64]
TWlrcm9UaWsgRG9qbw==

# decode
:put [:convert "TWlrcm9UaWsgRG9qbw==" from=base64]
MikroTik Dojo

# check the example above
:put [:convert from=raw to=base64 "ABC"]
QUJD

The same :convert also handles other representations (for example hex), handy when you need to move between formats inside a script. It’s useful for embedding a small file in an .rsc script, preparing an Authorization header for /tool fetch, or quickly reading an encoded value found in a config.

The Dojo’s online converter

If you need a quick conversion without opening a terminal, the Dojo has an online Base64 converter (encode and decode, text and files), in the Tools section:

→ The Dojo’s Base64 converter

Does Base64 encrypt data?

No. It’s just a reversible representation: anyone decodes it in an instant. To hide a value you need encryption; Base64 is for carrying bytes through text channels, not for protecting them.

Why is the result longer than the original?

Because every 3 bytes become 4 characters: about 33% more. It’s the cost of using only “safe” characters.

What are the trailing = for?

They are padding: they indicate that the last block had fewer than 3 bytes. One = = 2 real bytes, two == = 1 real byte. They carry no data.

Can RouterOS do Base64 on its own?

Yes, from RouterOS 7 with :convert … to=base64 (encode) and :convert … from=base64 (decode), straight from the console or a script.

What’s the difference with the “URL-safe” variant?

It uses - and _ instead of + and / (which cause trouble in URLs), often without the trailing =. Same data, two different symbols.