0xCONVERTER-HEX

Bytes → Base64

Hex to Base64 Converter

Repack hexadecimal bytes into Base64 — the same data, roughly a third the characters.

Hexadecimal in

Base64

Size

Two ways of writing the same bytes

Hex and Base64 solve the same problem: representing arbitrary bytes using characters that survive being printed, logged, emailed or pasted. They differ only in how much they cost.

Hex uses sixteen symbols and spends two characters per byte, so the output is exactly twice the size of the data. Base64 uses sixty-four symbols and spends four characters per three bytes, so the output is about a third larger than the data. For the same bytes, Base64 is roughly 33% shorter than hex.

HexBase64
Alphabet size1664
Bits per character46
Size versus raw data200%133%
Readable by eyeByte boundaries are obviousBoundaries are invisible
Typical useDumps, hashes, debuggingTransport, embedding, APIs

How the packing works

  1. Take the bytes three at a time. Three bytes is 24 bits.
  2. Re-slice those 24 bits into four groups of six.
  3. Each six-bit group is a number from 0 to 63.
  4. Look each number up in the Base64 alphabet: A–Z, then a–z, then 0–9, then + and /.

Worked example

48 65 6C   (three bytes — a full group)

  bits    01001000 01100101 01101100
  reslice 010010 000110 010101 101100
  values      18      6     21     44
  alphabet     S      G      V      s

  result → SGVs

Padding, and what the = signs mean

Base64 works in groups of three bytes. When the data does not divide evenly, the last group is short, and = characters mark how short.

Bytes left overBase64 charactersPaddingExample
04noneSGVs
12==SA==
23=SGU=

The padding carries no data. It exists so a decoder can tell how many bytes the final group actually held, which is why some systems strip it and others require it. If you paste Base64 without padding above, it is accepted and restored automatically.

Where each format wins

  • Hex is better for inspection. Byte boundaries are visible, individual bytes can be read directly, and you can spot patterns like a run of FF or an ASCII string inside binary data.
  • Base64 is better for transport. Smaller payloads, and the standard way to embed binary in JSON, data URLs, email attachments and JWTs.
  • Neither is encryption. Both are reversible by anyone in one step. Encoding is not obscuring, and Base64 in particular is often mistaken for a security measure when it offers none.
URL-safe Base64

The standard alphabet ends with + and /, which both have meaning inside a URL. The URL-safe variant swaps them for - and _. JWTs use this variant, which is why a token contains dashes and underscores but never slashes.

Frequently asked questions

How do I convert hex to Base64?

Turn the hex into bytes, take those bytes three at a time, re-slice each 24-bit group into four six-bit values and map each to the Base64 alphabet.

Why is Base64 shorter than hex?

Base64 packs six bits into each character; hex packs only four. The same data takes about a third fewer characters.

What do the equals signs mean?

They pad the final group when the data does not divide evenly into three bytes. One equals means two bytes in the last group, two means one byte.

Is Base64 a form of encryption?

No. It is a reversible encoding with no key and no secret. Anyone can decode it instantly.

What is URL-safe Base64?

A variant that replaces + and / with - and _ so the result can sit in a URL. JWTs use it.

Can I convert Base64 back to hex?

Yes, with the Base64 to hex converter. The round trip is exact.