You're staring at a screen right now. Maybe it's a phone. Even so, maybe it's a laptop. That's why doesn't matter. Somewhere between your eyes and the server holding this article, something happened to the bits carrying these words. So naturally, they got encoded. Then decoded. Also, then encoded again. Over and over.
Most people never think about it. But encoding? They click a link, the page loads, and they move on. It's the reason any of this works at all Small thing, real impact..
What Is Message Encoding
At its simplest, encoding is translation. You have information in one format — text, audio, video, raw sensor data — and you need to move it somewhere else. The destination might not speak the same language. The wire, the fiber, the radio wave — they don't understand "hello" or "0x48656c6c6f". Now, they understand voltage levels. Light pulses. Frequency shifts Small thing, real impact. Still holds up..
So you encode. You map your data into a form the medium can carry.
It's Not Encryption
Let's clear this up immediately. Worth adding: encoding ≠ encryption. Encoding is about compatibility. Also, encryption is about secrecy. Base64 is encoding. AES is encryption. You can encode encrypted data. You can encrypt encoded data. They're different layers, different jobs. Conflating them is a classic beginner mistake — and honestly, some senior engineers still mix them up when they're tired.
The Universal Problem
Every communication system faces the same core problem: the sender's representation doesn't match the channel's requirements. Even so, binary data chokes on text-only protocols. Think about it: aSCII text won't survive a 7-bit clean email gateway unscathed. Unicode characters explode in legacy systems that expect Latin-1.
Encoding solves the mismatch.
Why It Matters
You've seen the symptoms. The diamond-question-mark characters () scattered through a webpage. The email attachment that arrives corrupted. The emoji that shows up as a blank box on your friend's older phone. The JSON API that chokes on a stray byte.
All encoding failures.
Data Integrity
Without proper encoding, bits flip. Here's the thing — boundaries blur. A receiver can't tell where one field ends and the next begins. Because of that, in financial systems, a single encoding error can mean the difference between $1,000. 00 and $100,000. In medical devices, it can mean a dosage error. This isn't academic.
Interoperability
The internet works because we agreed on standards. UTF-8 for text. Base64 for binary-in-text. But protocol Buffers, MessagePack, Avro for structured data. Day to day, when everyone encodes the same way, systems talk. When they don't, you get the Tower of Babel — and debugging sessions that last three days.
Efficiency
Raw data is often wasteful. Worth adding: great encoding compresses and adds error detection. Think about it: video has massive temporal correlation. Images have patterns. Good encoding compresses. Plus, text has redundancy. The best encoding does all that while staying fast enough for real-time use Most people skip this — try not to..
How It Works
Encoding schemes vary wildly depending on what you're moving and where it's going. But they all follow a pattern: map → transform → transmit → reverse.
Character Encoding: The Text Problem
Text seems simple. It's not.
ASCII and Its Legacy
ASCII gave us 128 characters. 7 bits. English letters, digits, punctuation, control codes. Day to day, perfect for 1960s teletypes. Terrible for literally every other language on Earth The details matter here..
Extended ASCII (ISO-8859 family) used the 8th bit for 128 more characters. The Content-Type: text/html; charset=iso-8859-1 header wasn't decorative. You see the problem — you had to know which encoding a file used, or it rendered as garbage. ISO-8859-6 added Arabic. ISO-8859-5 added Cyrillic. So iSO-8859-1 covered Western Europe. It was survival Which is the point..
Not obvious, but once you see it — you'll see it everywhere Most people skip this — try not to..
Unicode Changed Everything
Unicode assigns a unique code point (number) to every character in every writing system — past, present, and even fictional (looking at you, Klingon). 0. That's why over 149,000 characters as of Unicode 15. Emoji included The details matter here..
But Unicode isn't an encoding. It's a character set. You still need to serialize those code points into bytes Worth keeping that in mind..
UTF-8 Won
UTF-8 encodes Unicode code points into 1–4 bytes. Even so, aSCII characters (U+0000 to U+007F) stay exactly one byte, identical to ASCII. That backward compatibility is why UTF-8 dominates the web — over 98% of pages now. Because of that, it's self-synchronizing: you can drop into a byte stream mid-character and find the next boundary. And it handles every language. It's reasonably compact for Latin scripts. It's the default for JSON, XML, HTML5, Go, Rust, Python 3 source files.. Which is the point..
Use UTF-8. Always. On the flip side, unless you have a very specific reason not to. And even then, reconsider.
UTF-16 and UTF-32 Exist
UTF-16 uses 2 or 4 bytes per code point. Worth adding: windows APIs love it. And simple indexing, massive waste. UTF-32 uses 4 bytes fixed. JavaScript strings are UTF-16 under the hood (which is why 😀.length === 2 — it's a surrogate pair). Neither is ideal for interchange.
Binary-to-Text Encoding: Moving Bytes Through Text Pipes
Email (SMTP) was designed for 7-bit ASCII. Because of that, hTTP headers? Text. In practice, jSON? Text. XML? Text. But you need to send images, PDFs, certificates, encrypted blobs — raw binary.
Enter binary-to-text encoding.
Base64
The workhorse. That said, takes 3 bytes (24 bits), splits into four 6-bit chunks, maps each to an ASCII character (A–Z, a–z, 0–9, +, /). Data URLs. Consider this: padding with = if needed. TLS certificates (PEM format). 33% overhead. Email attachments (MIME). JWT tokens. Everywhere. Basic Auth credentials.
It's not compression. It's expansion. But it's safe.
Base64url
Variant for URLs and filenames. And replaces + → - and / → _. Strips padding. Used in JWT, OAuth tokens, anywhere a / or + would break parsing Which is the point..
Base32, Base58, Others
Base32 uses A–Z, 2–7. Case-insensitive. Good for human transcription (no 0/O, 1/I confusion). Used in TOTP secrets, some DNS records.
Base58 drops more confusing chars (0, O, I, l). Bitcoin addresses use it. IPFS uses it. Shorter than Base64 for same data, but slower to compute Turns out it matters..
Hex Encoding
Two hex chars per byte. Human-readable. So openssl rand -hex 16 gives you a 32-char string. 100% overhead. Debugging-friendly. Not efficient for transport, but great for logs and configs.
Structured Data Encoding: Beyond Text
Text formats (JSON, XML, CSV, YAML) are verbose. Parsing is slow. Schema evolution is painful. Binary formats solve this.
Protocol Buffers (protobuf)
Google's baby. Because of that, protofiles, generate code in Go, Python, Java, C++, etc. Varint encoding for integers (small numbers = fewer bytes). Binary wire format is compact, fast, backwards/forwards compatible. Here's the thing — schema-first. Worth adding: field numbers replace field names on the wire. You define.Used in gRPC, Kubernetes, etcd, and half of Google's internal systems.
MessagePack
"JSON
is a binary format for structured data. Practically speaking, think of it as JSON’s binary cousin—smaller, faster, but less human-readable. It’s a compact, efficient alternative to JSON, using type prefixes and variable-length encodings. It’s fast to parse and serialize, with support for multiple languages. Use it when JSON’s verbosity is a bottleneck, like in APIs or storage systems.
Binc (Binary Encoding for C)
A C-centric binary format optimized for performance and minimal memory usage. It avoids indirection and focuses on speed. Ideal for systems programming, embedded systems, or high-frequency trading where every nanosecond counts Which is the point..
CBOR (Concise Binary Object Representation)
A binary alternative to JSON that’s both human-readable and machine-friendly. It uses a tagging system for extensibility and supports binary data directly. Popular in IoT devices and constrained environments where bandwidth and processing power are limited Simple as that..
Binary Formats: The Unseen Workhorses
While text formats dominate human-readable workflows, binary formats rule the backend. They’re faster to parse, smaller in size, and better suited for machine-to-machine communication. As an example, a JSON payload describing a user’s profile might be 500 bytes, while its MessagePack or CBOR equivalent could be 100–200 bytes. This efficiency is critical for mobile apps, IoT devices, and cloud services where bandwidth and latency matter The details matter here. Nothing fancy..
The Hybrid Approach: Combining Encodings
Real-world systems often layer encodings. A TLS certificate (binary) is Base64-encoded to fit into a PEM file (text). A JSON payload might be compressed with gzip (binary-to-text) before being Base64-encoded for transmission over SMTP. These layers ensure compatibility across protocols while maintaining data integrity.
Conclusion
Encoding choices shape how we interact with data. UTF-8 unifies text across the digital landscape, Base64 bridges the gap between binary and text, and structured binary formats like protobuf and MessagePack optimize performance. The right encoding depends on context: UTF-8 for text, Base64 for safe transport, binary formats for efficiency. As systems grow more complex, understanding these tools ensures data flows naturally—whether it’s a tweet, a ciphertext, or a Kubernetes cluster. Choose wisely, and let the bytes flow.