# Binary Protocols

> Why exchanges use compact binary protocols for market data and orders. Learn how ITCH, OUCH and SBE work, how they compare with JSON and FIX, and decoding basics.

Source: https://learn.tradelabsai.com/infrastructure/binary-protocols/  
Track: Trading Infrastructure · Level: Advanced · Updated: 2026-10-03  
Publisher: TradeLabs AI (https://tradelabsai.com). Education, not financial advice.  
Cite as: TradeLabs Learn, "Binary Protocols", https://learn.tradelabsai.com/infrastructure/binary-protocols/

Text formats such as JSON and FIX are readable but relatively slow to parse and large on the wire. For their fastest market data and order entry, many exchanges use binary protocols: messages laid out as fixed fields of raw bytes, each at a known position and size. A program can read a price from a binary message by looking at specific bytes, without searching for delimiters or converting text to numbers. This makes binary protocols smaller, faster and more predictable, at the cost of being unreadable to humans without a decoder.

## Text versus binary

| | JSON | FIX (tag and value) | Binary |
|---|---|---|---|
| Example price field | "price":"185.50" | 44=185.50 | 4 or 8 bytes holding an integer like 1855000 |
| Human readable | Yes | Mostly | No |
| Parsing | Search and convert text | Search tags, convert text | Read fixed offsets |
| Message size | Large | Medium | Small |
| Typical use | Crypto and retail APIs | Institutional order flow | Exchange direct feeds and order entry |

## Well known binary protocols

| Protocol | Venue or body | Purpose |
|---|---|---|
| ITCH | Nasdaq (and others using the name) | Market by order data feed: adds, executions, cancels |
| OUCH | Nasdaq | Low latency order entry |
| SBE (Simple Binary Encoding) | FIX Trading Community | Standard binary encoding, used by CME's MDP 3.0 market data |
| iLink 3 | CME Group | Order entry using SBE |
| Pillar protocols | NYSE | Binary market data and order entry |

## How a binary message is laid out

A simplified "add order" message might look like this:

| Offset | Length | Field | Type |
|---|---|---|---|
| 0 | 1 | Message type ("A") | Character |
| 1 | 8 | Timestamp (nanoseconds since midnight) | Unsigned integer |
| 9 | 8 | Order reference number | Unsigned integer |
| 17 | 1 | Side ("B" or "S") | Character |
| 18 | 4 | Shares | Unsigned integer |
| 22 | 8 | Stock symbol | Text, padded |
| 30 | 4 | Price (in units of 1/10,000 dollar) | Unsigned integer |

This mirrors the style of Nasdaq ITCH, though the real specification has more fields. Prices stored as integers avoid floating point errors: 1,855,000 in units of one ten thousandth of a dollar is $185.50.

```python
import struct
# '>' big endian, c=char, Q=8 byte uint, c, I=4 byte uint, 8s=8 bytes, I
fmt = ">cQQcI8sI"
msg_type, ts, ref, side, shares, sym, px = struct.unpack(fmt, raw[:34])
price = px / 10_000
```

**Example: Size and speed difference**
The JSON message {"type":"add","ts":34200000000123,"ref":91827364,"side":"B","qty":300,"sym":"AAPL","px":185.5} is about 90 bytes, and parsing it means scanning characters and converting text to numbers. The binary layout above carries the same information in 34 bytes, and each field is read with a single memory access at a known offset. During a burst of a million messages per second, that is roughly 56 MB per second less data and far fewer CPU cycles per message, which is why exchanges use binary for their fastest feeds. See [Feed Handlers and Normalization](https://learn.tradelabsai.com/programming/feed-handlers-and-normalization/).

## Byte order and versions

- **Endianness:** multi byte numbers can be stored big endian or little endian; the specification says which.
- **Versioning:** venues update protocols; decoders must check version fields and handle new message types.
- **Schemas:** SBE uses XML schemas from which encoders and decoders can be generated, reducing hand written errors.

## Working with binary protocols

1. **Read the venue specification** carefully; it is the only reliable source.
2. **Use generated or proven decoders** where available.
3. **Test against sample captures** the venue provides.
4. **Track sequence numbers** for gap detection. See [Sequence Numbers, Dropped Packets and Out-of-Order Messages](https://learn.tradelabsai.com/programming/sequence-numbers/).
5. **Log raw bytes** for replay and debugging. See [Market Data Replay](https://learn.tradelabsai.com/programming/market-data-replay/).

## Frequently asked questions

### What is a binary protocol in trading?

A message format where fields are stored as raw bytes at fixed positions, making messages smaller and faster to process than text formats.

### What is Nasdaq ITCH?

Nasdaq's binary market data feed, which reports every order added, executed, modified or cancelled, allowing a full order book to be built.

### What is SBE?

Simple Binary Encoding, a FIX Trading Community standard for compact binary messages, used for example in CME's market data and order entry.

Next, learn how trading systems keep their clocks precise in [Clock Synchronization and PTP](https://learn.tradelabsai.com/infrastructure/clock-synchronization-and-ptp/).

## Continue learning

- Next lesson: [Clock Synchronization and PTP](https://learn.tradelabsai.com/infrastructure/clock-synchronization-and-ptp/)
- Previous lesson: [Lock-Free Programming and Ring Buffers](https://learn.tradelabsai.com/infrastructure/lock-free-programming/)
- Related: [Lock-Free Programming and Ring Buffers](https://learn.tradelabsai.com/infrastructure/lock-free-programming/): Lock free data structures let trading threads share data without waiting on locks. Learn ring buffers, atomics, the LMAX Disruptor pattern and the pitfalls involved.
- Related: [FIX Protocol](https://learn.tradelabsai.com/programming/fix-protocol/): FIX is the standard messaging protocol for institutional trading. Learn how FIX sessions, messages and tags work, a sample order message and when traders use FIX.
- Related: [Feed Handlers and Normalization](https://learn.tradelabsai.com/programming/feed-handlers-and-normalization/): Feed handlers connect to exchange data feeds and convert each venue's format into one standard internal format. Learn the design, symbol mapping and common pitfalls.
- Related: [Order Book Feeds: Snapshots and Incremental Updates](https://learn.tradelabsai.com/programming/order-book-feeds/): How exchanges publish order book data as snapshots and incremental updates, and how to build and maintain an accurate local order book in code without errors.
- Related: [Kernel Bypass and Low-Latency Networking](https://learn.tradelabsai.com/infrastructure/kernel-bypass/): Kernel bypass lets trading software read network packets straight from the network card, skipping the operating system. Learn how it works and the trade offs.
- Related: [Sequence Numbers, Dropped Packets and Out-of-Order Messages](https://learn.tradelabsai.com/programming/sequence-numbers/): Sequence numbers let trading systems detect lost, duplicated or out of order messages. Learn how gap detection, recovery and duplicate handling work in practice.
