# SBE: the message header and how a decoder picks a message

> Learn how the fixed header at the start of every SBE message lets a trading decoder pick the right message layout, handle schema versions and skip unknown trailing bytes.

Page: https://structure.fi/guides/sbe-message-header/

Simple Binary Encoding (SBE) is the FIX Trading Community's fixed-offset binary format used by exchanges and trading desks for low-latency market data and order entry ([how an SBE message is laid out](https://structure.fi/guides/sbe-message-layout/)). One live market-data stream mixes many message types—trades, top-of-book quotes, order-book snapshots, and status updates—with no field names on the wire.

Every SBE message therefore opens with a small, fixed-size **message header** so the decoder can immediately tell which schema and message layout apply, which schema version the sender used, and where the fixed-size body ends. This page covers the header's four fields, the exact dispatch sequence a decoder follows, why `blockLength` travels on the wire, and how the SBE header differs from outer [framing](https://structure.fi/guides/binary-message/#framing).

## The four fields

The schema declares the header as a [composite](https://structure.fi/guides/sbe-schema-file/#composites), named `messageHeader` unless `headerType` overrides it. In the bundled Binance Spot Streams sample, `messageHeader` is 8 bytes—four `uint16` fields:

- `blockLength`: byte size of the root block (excludes the header, [repeating groups](https://structure.fi/guides/variable-sized-data/#sbe-count-prefixed-groups-and-length-prefixed-data), and [variable-length data](https://structure.fi/guides/sbe-variable-length-data/)).
- `templateId`: message id matching `<message id="…">` (`10000` for `TradesStreamEvent`).
- `schemaId`: schema id matching `<messageSchema id="…">` (`1` for `binance_stream_1_0_sbe.xml`, `3` for `binance_spot_3_6_sbe.xml`).
- `version`: schema version used by the sender (`0` for `binance_stream_1_0_sbe.xml`, `6` for `binance_spot_3_6_sbe.xml`).

[Open the Binance streams message header in the Market Data Visualizer](https://structure.fi/tools/market-data-visualizer/app/#open?sample=binance-stream&node=t%2FmessageHeader&place=detail&guide=sbe-message-header&section=block-5)

## How a decoder dispatches

1. Read the header at byte 0 of the SBE message using the schema's [byte order](https://structure.fi/guides/binary-message/#endianness).
2. Match `schemaId` to select the protocol schema.
3. Match `templateId` to select the message layout. If `templateId` is unknown and the message may contain groups or data, `blockLength` alone cannot skip it—you need the outer [framing](https://structure.fi/guides/binary-message/#framing) length.
4. Read root-block fields at their schema offsets, counted from the byte immediately after the header.
5. Advance `blockLength` bytes from the start of the root block to begin reading groups and variable-length data.

## Why blockLength is on the wire

The root block's size is already in the schema—18 bytes for `TradesStreamEvent`—but sending `blockLength` on the wire makes schema evolution work. When a newer sender appends fields to the root block, an older decoder advances by the received `blockLength` and lands cleanly on the first group instead of misreading the new bytes. When an older sender omits fields added in later versions, `version` tells a newer decoder which `sinceVersion` fields are absent ([schema versioning](https://structure.fi/guides/schema-versioning/)).

Layout of TradesStreamEvent in the Binance Spot Streams SBE schema, as the Market Data Visualizer lays it out:

| Offset | Size | Name | Type | Presence | Since |
| --- | --- | --- | --- | --- | --- |
| 0 | 18 | TradesStreamEvent | block |  | 0 |
| 0 | 8 |  eventTime | utcTimestampUs | required | 0 |
| 8 | 8 |  transactTime | utcTimestampUs | required | 0 |
| 16 | 1 |  priceExponent | exponent8 | required | 0 |
| 17 | 1 |  qtyExponent | exponent8 | required | 0 |
| 18 | 6 |  trades | group groupSizeEncoding |  | 0 |
| 18 | 2 |   .blockLength | uint16 |  |  |
| 20 | 4 |   .numInGroup | uint32 |  |  |
| 24 | 25 |   [0] | entry |  |  |
| 24 | 8 |    .id | tradeId | required | 0 |
| 32 | 8 |    .price | mantissa64 | required | 0 |
| 40 | 8 |    .qty | mantissa64 | required | 0 |
| 48 | 1 |    .isBuyerMaker | enum boolEnum | required | 0 |
| — | 0 |    .isBestMatch | const enum boolEnum | constant | 0 |
| 49 | 1 |  symbol | data varString8 |  | 0 |

## Variations and framing

- **Header layouts vary by schema.** Because the schema declares the header composite, a venue can widen fields or add fields. The SBE standard recommends also including `numGroups` and `numVarDataFields` so older decoders can skip unknown groups and data fields. Inspect each venue's header composite rather than assuming 8 bytes.
- **The header is not the frame.** It never gives total message length. On TCP streams or packet captures, an outer frame supplies total length: either the FIX **Simple Open Framing Header (SOFH)** (standard SOFH is a 4-byte big-endian total length including SOFH plus a 2-byte big-endian encoding type, though venues such as [CME iLink 3](https://structure.fi/guides/cme-ilink3/#a-message-from-the-first-byte) and [B3 Binary UMDF](https://structure.fi/guides/b3-umdf/#a-packet-from-the-first-byte) use a 4-byte little-endian variant: a 2-byte length and a 2-byte encoding type) or a venue-specific prefix such as [CME MDP 3.0's `MsgSize`](https://structure.fi/guides/cme-mdp3/#a-packet-from-the-first-byte). See [framing](https://structure.fi/guides/binary-message/#framing). In the Market Data Visualizer, layouts start after the message header, at byte 0 of the root block, until you pick a frame in the **Framing** select of the pane bar; then the frame and the header are drawn as layers in front of the root block.

## What to check when decoding

- Verify the header's field types and total size in the venue's schema before hard-coding an 8-byte offset.
- Check both `schemaId` and `templateId` before decoding; a single connection can multiplex schemas.
- Never use `blockLength` to skip an unrecognized `templateId`; rely on the framing length prefix.

See [how an SBE message is laid out](https://structure.fi/guides/sbe-message-layout/) for the body after the header, and [reading the XML message schema](https://structure.fi/guides/sbe-schema-file/) for `headerType` and schema ids.

## Sources

- https://www.fixtrading.org/what-is-the-fix-protocol/
- https://cmegroupclientsite.atlassian.net/wiki/spaces/EPICSANDBOX/pages/457638617/MDP+3.0+-+SBE+Technical+Headers
- https://www.fixtrading.org/standards/sbe/
- https://github.com/FIXTradingCommunity/fix-simple-binary-encoding/blob/master/v1-0-STANDARD/doc/03MessageStructure.md
- https://github.com/FIXTradingCommunity/fix-simple-binary-encoding/blob/master/v1-0-STANDARD/doc/05SchemaExtensionMechanism.md
- https://github.com/real-logic/simple-binary-encoding/wiki/FIX-SBE-XML-Primer
- https://github.com/real-logic/simple-binary-encoding/wiki/Message-Versioning

Reviewed by Structure on 2026-11-24. Last changed 2026-11-25.
