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.
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
}| 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 |
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'sidin the schema—10000forTradesStreamEvent).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
orderTypesin the Binance Spot API sample): bit field inside an unsigned integer. - Constant (such as
isBestMatchinTradesStreamEvent/trades): value lives in the schema and occupies zero bytes on the wire. - Optional (such as
orderListIdinNewOrderAckResponse): 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:
- Repeating groups in schema order (variable-sized data and lists). Each group starts with a dimension composite (
dimensionType, holdingblockLengthandnumInGroup, and optionallynumGroupsandnumVarDataFieldsso 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 wireblockLength, and checknumInGroup == 0before reading entries. - 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
- https://www.fixtrading.org/what-is-the-fix-protocol/
- https://www.fixtrading.org/standards/sbe/
- https://github.com/FIXTradingCommunity/fix-simple-binary-encoding
- https://github.com/binance/binance-spot-api-docs/blob/master/sbe/schemas/stream_1_0.xml
- https://github.com/real-logic/simple-binary-encoding/wiki/FIX-SBE-XML-Primer
Reviewed by Structure on 2026-11-24. Last changed 2026-11-23.