SBE: how a message is laid out

Learn how Simple Binary Encoding (SBE) orders every message on the wire—header, fixed root block, repeating groups and variable-length data—so trading decoders read fields without parsing.

View as Markdown

Simple Binary Encoding (SBE) is the FIX Trading Community's binary wire format for low-latency trading messages. Exchanges and trading firms—including CME Group, B3, and Binance—use SBE for real-time market data and order entry. Unlike JSON or tag-value FIX, SBE puts no field names or tags on the wire: an external XML message schema fixes every field's byte offset so a decoder reads values straight from the receive buffer without parsing earlier bytes (how a binary message is put together).

This page walks through the four sections of one SBE message in exact wire order—message header, fixed root block, repeating groups, and trailing variable-length data—using a real trade-stream message from Binance. Any outer packet header or length prefix around the message belongs to framing outside the SBE schema.

TradesStreamEvent, laid out

Look at TradesStreamEvent from the bundled Binance Spot Streams sample below. The text declaration's gutter shows where each field starts inside its block (parent offset) and its size; the layout table's Offset counts every buffer offset from byte 0 of the root block. Notice the three sections in order: fixed-size fields (eventTime through qtyExponent), a repeating group (trades), and variable-length data (symbol).

TradesStreamEvent :: message @10000 {
    eventTime:     utcTimestampUs :: type int64; // UTC timestamp in microsecondsutcTimestampUs;  @1
    transactTime:  utcTimestampUs :: type int64; // UTC timestamp in microsecondsutcTimestampUs;  @2
    priceExponent: exponent8 :: type int8; // Exponent for a decimal floating point number.exponent8;       @3
    qtyExponent:   exponent8 :: type int8; // Exponent for a decimal floating point number.exponent8;       @4
    trades:        group            @100 {
        id:           tradeId :: type int64;tradeId;                        @1
        price:        mantissa64 :: type int64; // 64-bit mantissa for a decimal floating point number. The name of the field containing the exponent value is specified in the mbx:exponent attribute of the mantissa64 field. The exponent field will always precede the mantissa field.mantissa64;                     @2
        qty:          mantissa64 :: type int64; // 64-bit mantissa for a decimal floating point number. The name of the field containing the exponent value is specified in the mbx:exponent attribute of the mantissa64 field. The exponent field will always precede the mantissa field.mantissa64;                     @3
        isBuyerMaker: boolEnum :: enum uint8 // 1 BboolEnum;                       @4
        isBestMatch:  boolEnum :: enum uint8 // 1 BboolEnum const = boolEnum.True; @5
    }
    symbol:        data varString8 :: composite // Variable length UTF-8 string.varString8; @200
}
TradesStreamEvent in the Binance Spot Streams SBE schema, as the Market Data Visualizer's text view writes it
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

Open TradesStreamEvent in the Market Data Visualizer

The message header

Every SBE message starts with a fixed-size composite header (usually messageHeader) holding four fields:

  • templateId: identifies the message (matches the message's id in the schema—10000 for TradesStreamEvent).
  • schemaId: identifies the schema.
  • version: schema version used by the sender.
  • blockLength: byte length of the root block that follows.

See the message header for the full dispatch sequence.

The root block

Immediately after the header comes the root block: all fixed-size fields in schema order, packed with no implicit alignment padding (fields and padding). Multi-byte numbers use the schema's byteOrder (little-endian by default; see endianness).

A schema can still introduce deliberate padding in three ways: an explicit field offset (skipping bytes to align a field or match a struct), a message blockLength larger than its fields (trailing root padding), or a group blockLength larger than its entry fields (trailing entry padding). Writers fill padding bytes with zeros, and readers never read them as data.

Open eventTime, the first field of the root block, in the Market Data Visualizer

Four field kinds behave specially inside a block:

  • Composite: laid out inline, member after member.
  • Set (such as orderTypes in the Binance Spot API sample): bit field inside an unsigned integer.
  • Constant (such as isBestMatch in TradesStreamEvent/trades): value lives in the schema and occupies zero bytes on the wire.
  • Optional (such as orderListId in NewOrderAckResponse): always occupies its full byte width, signalling absence with a reserved null value.

After reading the root block, advance by the header's blockLength—not by your local schema's block size—so fields appended in newer schema versions are skipped cleanly (schema versioning).

Groups and variable-length data

After the root block come:

  1. Repeating groups in schema order (variable-sized data and lists). Each group starts with a dimension composite (dimensionType, holding blockLength and numInGroup, and optionally numGroups and numVarDataFields so older decoders can skip unknown nested groups or data fields), followed by its entries back to back. Inside each entry, members repeat the message's three-part order (fixed fields, nested groups, entry-level variable-length data). Advance past every entry's fixed part by the wire blockLength, and check numInGroup == 0 before reading entries.
  2. Variable-length data fields last, each a length prefix followed by that many bytes.

Because group counts and data lengths are only known at run time, decoders walk groups and data fields sequentially in schema order.

What to check when decoding

  • Strip outer venue framing before reading the SBE header; the app's layouts start at byte 0 of the root block.
  • Advance past the root block using the wire blockLength, never your compiled struct size.
  • Read groups and variable-length fields strictly in schema order.

Sources

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