Hexadecimal Encoding
Hex encoding represents each byte as two hexadecimal characters (0-9, a-f). A byte with value 255 becomes 'ff'. Every byte requires exactly 2 characters, resulting in a 100% size increase. Hex is human-readable in a very direct way — experienced developers can mentally parse hex values. Used for cryptographic hashes, memory dumps, color values, and network protocol debugging.
Base64 Encoding
Base64 packs 3 bytes into 4 characters, achieving 33% overhead versus hex's 100% overhead. This efficiency advantage makes Base64 the choice for encoding larger binary data in text formats. However, Base64 output is less readable to humans.
When Each Is Used
Hex dominates in: cryptographic hash outputs, color codes (#FF5733), IPv6 addresses, UUID strings, MAC addresses, and debugging contexts. Base64 dominates in: email attachments, data URLs, JWT tokens, API authentication headers, and any context where transmission efficiency matters.
URL Safety Variants
Standard Base64 uses + and / which have special meaning in URLs. URL-safe Base64 replaces these with - and _. Hex encoding is naturally URL-safe. When choosing encoding for URL-embedded data, prefer URL-safe Base64 for efficiency or hex for simplicity if the data is short.
Hex for crypto outputs, color values, and debugging where byte readability matters. Base64 for larger binary data in text channels where efficiency matters. Know the URL-safety variants of each.