JSONHack
Validator · Formatter · Base64
Encoding Guide

Base64 vs Hex Encoding

📅Last updated:

Base64 and hexadecimal (hex) are both methods of representing binary data as text strings. They are used in different contexts and have different trade-offs in terms of output size, readability, and compatibility. This guide explains how each works and when to use each one.

How They Work

Base64

Encodes every 3 bytes of binary data into 4 ASCII characters using a 64-character alphabet (A–Z, a–z, 0–9, +, /). Output size is approximately 33% larger than the input.

Example: HelloSGVsbG8=

Hexadecimal

Encodes every byte as exactly 2 hex characters (0–9, a–f). Output size is exactly 2× the input size. Each hex character represents 4 bits (a nibble).

Example: Hello48656c6c6f

Size Comparison

Base64 Size

Output is ~133% of input size. 3 bytes → 4 characters. A 100-byte input produces ~136 characters of Base64.

Hex Size

Output is exactly 200% of input size. 1 byte → 2 characters. A 100-byte input produces exactly 200 hex characters.

Winner for size: Base64 — Base64 is more compact than hex for the same binary data.

Readability

Neither format is human-readable for arbitrary binary data, but hex has an advantage for specific use cases:

When to Use Base64

When to Use Hex

Base64URL — A URL-Safe Variant

Standard Base64 uses + and / characters which have special meaning in URLs. Base64URL replaces + with - and / with _, making it safe for use in URLs and filenames without percent-encoding. JWT tokens use Base64URL encoding for their header and payload sections.

Quick Reference

Use Base64 for

  • File/image embedding
  • API binary transfer
  • JWT tokens
  • Email attachments

Use Hex for

  • Hash display
  • Color codes
  • Crypto keys
  • Byte inspection
Encode or decode Base64 now

Use JSONHack's free Base64 encoder and decoder — instant, browser-based, private.

Open Base64 Tool →