Base64 vs Hex vs Binary: Encoding Explained

Shah Fahad
Shah Fahad
Technical Lead & AI Systems Architect
July 14, 2026 · 4 min read
Illustration comparing binary, hexadecimal, and Base64 representations of the same data

Binary, hexadecimal, and Base64 are three ways of representing the same underlying data. They are encodings, not encryption, so none of them hides or secures anything. Each exists to make bytes usable in a different context: raw storage, human inspection, or safe transport through text-only channels. Understanding the trade-offs helps you pick the right one and avoid bloating your payloads.

What Each One Is

Binary is the raw form. Everything a computer stores is ultimately bits grouped into bytes of 8 bits each, so a single byte holds a value from 0 to 255. Binary is compact and native, but a wall of 0s and 1s is unreadable to humans and unsafe to paste into text formats.

Hexadecimal (hex) is base-16, using the digits 0-9 and letters a-f. Because 16 is exactly 2 to the 4th power, each hex digit maps cleanly to 4 bits, and every byte becomes exactly two hex characters. This tidy alignment is why hex is the standard for showing raw bytes to people.

Base64 encodes binary using 64 printable ASCII characters (A-Z, a-z, 0-9, plus + and /). It takes 3 bytes (24 bits) at a time and splits them into 4 groups of 6 bits, producing 4 text characters. This lets you embed arbitrary binary safely inside text-only systems.

Illustration of the same bytes shown as binary, hexadecimal, and Base64

Size Overhead

Overhead is often the deciding factor. Here is how the same data expands:

Encoding Characters per byte Size vs raw binary Alphabet
Binary (raw) Baseline (1x) 0 and 1 (bits)
Hexadecimal 2 chars/byte +100% (2x larger) 16 symbols
Base64 ~1.33 chars/byte About +33% (padding may add a bit) 64 symbols

Base64 is more space-efficient than hex because its 64-symbol alphabet packs more information into each character (6 bits versus hex's 4 bits). The trade-off is that hex is trivially readable byte by byte, while Base64 is denser but not human-parseable at a glance.

A Worked Example

Take the three ASCII bytes for the word Cat:

Text:    C          a          t
Binary:  01000011   01100001   01110100
Hex:     43         61         74
Base64:  Q2F0

Notice the pattern: 3 input bytes (24 bits) become exactly 4 Base64 characters, while the same 3 bytes become 6 hex characters. When the input length is not a multiple of 3, Base64 pads the output with one or two = signs.

Where Each Is Used

Base64 shines when binary must travel through text:

  • Data URIs — embedding a small image or font directly in HTML or CSS with data:image/png;base64,... to save an HTTP request.
  • Email attachments — MIME uses Base64 so binary survives text-only mail transport.
  • JSON and JWTs — since JSON has no binary type, byte fields are Base64-encoded strings.
  • Basic auth headers — credentials are Base64-encoded (encoded, not secured).

Hex is the choice for byte-level readability:

  • Hashes and checksums — MD5, SHA-256, and CRC values are displayed in hex.
  • Colors — CSS uses hex like #ff8800 for RGB bytes.
  • Memory and file inspection — hex editors and debuggers show raw bytes in hex.
  • Encryption keys and MAC addresses — compact, exact, easy to read in pairs.

Binary is what you use when you control the wire format: raw files, network protocols, and storage where every byte counts and no text encoding is needed.

Quick Selection Guide

  • Need to paste binary into HTML, JSON, or an email? Use Base64.
  • Displaying a hash, color, or raw bytes for a human? Use hex.
  • Storing or transmitting data through a channel that is already binary-safe? Keep it raw binary and skip the overhead.

Try the Conversions

You can convert between all three instantly and see the size difference for yourself:

Takeaway

They are three views of the same bytes. Binary is the raw baseline, hex doubles the size but gives clean byte-by-byte readability, and Base64 adds only about 33% while making binary safe to embed in text. Reach for Base64 when you need transport through text formats, hex when a human needs to read the bytes, and remember that none of them provides any security.

Shah Fahad
Shah Fahad
Technical Lead & AI Systems Architect

Shah Fahad is a technical lead and AI systems architect who builds production AI platforms end to end — from multi-tenant backends and agentic systems to the bare-metal infrastructure they run on.

♥ Enjoying these free tools?

FAHAQ keeps every tool free with no paywalls. Donations help cover the servers and keep it fast and growing — even a couple of dollars makes a difference.

Donate

More from the blog