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

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

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](https://structure.fi/guides/sbe-schema-file/) 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](https://structure.fi/guides/binary-message/)).

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](https://structure.fi/guides/binary-message/#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 in the Binance Spot Streams SBE schema, as the Market Data Visualizer's text view writes it:

```text
TradesStreamEvent :: message @10000 {
    eventTime:     utcTimestampUs;  @1
    transactTime:  utcTimestampUs;  @2
    priceExponent: exponent8;       @3
    qtyExponent:   exponent8;       @4
    trades:        group            @100 {
        id:           tradeId;                        @1
        price:        mantissa64;                     @2
        qty:          mantissa64;                     @3
        isBuyerMaker: boolEnum;                       @4
        isBestMatch:  boolEnum const = boolEnum.True; @5
    }
    symbol:        data varString8; @200
}
```

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 |

[Open TradesStreamEvent in the Market Data Visualizer](https://structure.fi/tools/market-data-visualizer/app/#open?sample=binance-stream&node=m10000&place=text&guide=sbe-message-layout&section=block-6)

## The message header

Every SBE message starts with a fixed-size [composite](https://structure.fi/guides/sbe-schema-file/#composites) 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](https://structure.fi/guides/sbe-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](https://structure.fi/guides/binary-message/#fields-and-padding)). Multi-byte numbers use the schema's `byteOrder` (little-endian by default; see [endianness](https://structure.fi/guides/binary-message/#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](https://structure.fi/tools/market-data-visualizer/app/#open?sample=binance-stream&node=m10000%2Ff1&place=layout&guide=sbe-message-layout&section=block-16)

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](https://structure.fi/guides/binary-message/#null-values).

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](https://structure.fi/guides/schema-versioning/)).

## Groups and variable-length data

After the root block come:

1. **Repeating groups** in schema order ([variable-sized data and lists](https://structure.fi/guides/variable-sized-data/#sbe-count-prefixed-groups-and-length-prefixed-data)). 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](https://structure.fi/guides/sbe-variable-length-data/)** 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.
