Bytes → Base64
Hex to Base64 Converter
Repack hexadecimal bytes into Base64 — the same data, roughly a third the characters.
—
—
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.
| Hex | Base64 | |
|---|---|---|
| Alphabet size | 16 | 64 |
| Bits per character | 4 | 6 |
| Size versus raw data | 200% | 133% |
| Readable by eye | Byte boundaries are obvious | Boundaries are invisible |
| Typical use | Dumps, hashes, debugging | Transport, embedding, APIs |
How the packing works
- Take the bytes three at a time. Three bytes is 24 bits.
- Re-slice those 24 bits into four groups of six.
- Each six-bit group is a number from 0 to 63.
- 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 over | Base64 characters | Padding | Example |
|---|---|---|---|
| 0 | 4 | none | SGVs |
| 1 | 2 | == | SA== |
| 2 | 3 | = | 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
FFor 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.
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.