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.

View as Markdown

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). 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.

The four fields

The schema declares the header as a composite, 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, and 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

How a decoder dispatches

  1. Read the header at byte 0 of the SBE message using the schema's byte order.
  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 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).

Layout of TradesStreamEvent in the Binance Spot Streams SBE schema, as the Market Data Visualizer lays it out
OffsetSizeNameTypePresenceSince
018TradesStreamEventblock0
08eventTimeutcTimestampUsrequired0
88transactTimeutcTimestampUsrequired0
161priceExponentexponent8required0
171qtyExponentexponent8required0
186tradesgroup groupSizeEncoding0
182.blockLengthuint16
204.numInGroupuint32
2425[0]entry
248.idtradeIdrequired0
328.pricemantissa64required0
408.qtymantissa64required0
481.isBuyerMakerenum boolEnumrequired0
—0.isBestMatchconst enum boolEnumconstant0
491symboldata varString80

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 and B3 Binary UMDF 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. See 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 for the body after the header, and reading the XML message schema for headerType and schema ids.

Sources

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