Canonical: https://nitride.xyz/docs/shreds/parse-header

# Parsing the shred header

Every datagram in the feed is one shred. This page gives the byte layout Agave uses today, a small parser you can test on your own machine, and how to pin the Agave crate for production.

Read the first 83 bytes of a datagram and you have the common header, which every shred carries. Byte 64 then tells you whether a data header or a coding header follows, and where the Merkle trailer starts. The layout below matches the Agave source on GitHub as read on 2026-11-17 (the `master` branch and release v4.4.1). It changes with the protocol, so check it against the release the cluster runs before you depend on a fixed offset. For background on what each field means, see [the shred header, field by field](https://nitride.xyz/learn/shred-header). This page belongs to the [Nitride.xyz docs](https://nitride.xyz/docs).

All integers are little-endian.

## The common header
| Bytes | Field | Type |
| --- | --- | --- |
| 0 to 63 | Leader signature | 64 bytes |
| 64 | Variant | u8 |
| 65 to 72 | Slot | u64 |
| 73 to 76 | Index within the slot | u32 |
| 77 to 78 | Shred version | u16 |
| 79 to 82 | FEC set index | u32 |

The signature is the leader's signature over the Merkle root of the erasure batch, so every shred in one batch carries the same 64 bytes. Data and coding shreds count their `index` with separate counters that both restart at zero in each slot. A data shred and a coding shred of the same slot often share an index; only `(slot, index, type)` names one shred. The FEC set index is the index of the first data shred in the batch, and every shred of that batch, coding shreds included, carries the same value. The version is the cluster's shred version, which nodes use to drop shreds from another cluster.

## What does the variant byte mean?
The high four bits give the type. The low four bits give the number of entries in the Merkle proof.

| High nibble | Type | Byte with a 6-entry proof |
| --- | --- | --- |
| `0x6` | Coding, chained | `0x66` |
| `0x7` | Coding, chained, resigned | `0x76` |
| `0x9` | Data, chained | `0x96` |
| `0xB` | Data, chained, resigned | `0xB6` |

Chained means the shred embeds the Merkle root of the previous erasure batch; the source notes that every variant in use is chained. Resigned means the shred reserves 64 bytes at its end for a retransmitter signature. Only the last erasure batch of a slot is resigned, and each node that forwards it down the Turbine tree signs it again, leaving the leader's signature as it was. Two copies of the same resigned shred can therefore differ in their last 64 bytes.

Batches are a fixed 32 data and 32 coding shreds, a 64-leaf tree, so the proof has 6 entries. Read the count from the low nibble anyway: the source still computes the layout from it while the fixed 32:32 rule is being enforced.

Older Agave releases also defined legacy shreds (`0xA5` data, `0x5A` coding) and unchained Merkle shreds (high nibble `0x4` for coding and `0x8` for data). The current source rejects those bytes as invalid variants. Log them instead of crashing, in case you replay an old capture.

## Data shred header
| Bytes | Field | Type |
| --- | --- | --- |
| 83 to 84 | `parent_offset`: slot minus the parent slot | u16 |
| 85 | `flags` | u8 |
| 86 to 87 | `size`: headers plus entry bytes | u16 |

The headers end at byte 88, and the entry bytes are `payload[88:size]`. `size` is an end offset, not a length, so it never falls below 88. A shred whose `size` is exactly 88 carries no entry data and pads a short batch.

The flags byte packs three things:

- bits 0 to 5 (`0x3F`): the reference tick, capped at 63 (under Alpenglow it no longer measures time within the slot);
- `0x40`, `DATA_COMPLETE_SHRED`: the last shred of a run of entry data that deserializes on its own;
- `0xC0`, `LAST_SHRED_IN_SLOT`: the last data shred of the slot. Its value sets the `0x40` bit too, so test `flags & 0xC0 == 0xC0`.

## Coding shred header
| Bytes | Field | Type |
| --- | --- | --- |
| 83 to 84 | `num_data_shreds` | u16 |
| 85 to 86 | `num_coding_shreds` | u16 |
| 87 to 88 | `position` among the coding shreds of the batch | u16 |

The headers end at byte 89. Both counts are 32 today. A coding shred's place in the erasure batch is `num_data_shreds + position`, because data shreds take the lower places. How recovery uses them is covered in [recovering and decoding](https://nitride.xyz/docs/shreds/recover-and-decode). For how the two kinds of shred relate, see [data and coding shreds](https://nitride.xyz/learn/data-and-coding-shreds).

## Where does the Merkle trailer start?
After the body, each shred ends with a fixed trailer, counted back from the end of the payload:

| Part | Size |
| --- | --- |
| Chained Merkle root of the previous batch | 32 bytes |
| Merkle proof | 20 bytes per entry (120 with 6 entries) |
| Retransmitter signature, resigned variants only | 64 bytes |

A data shred's payload is 1,203 bytes and a coding shred's is 1,228 bytes. With 6 proof entries, a data shred holds at most 963 bytes of entry data, or 899 when resigned. The proof and the leader signature are what [Merkle shreds](https://nitride.xyz/learn/merkle-shreds) explains in detail.

## A parser in Python
This parser uses only the standard library. It checks the variant and the `size` field and returns a dict. It does not verify the signature or the Merkle proof.

```python file="shred_header.py"
import struct

SIG = 64            # leader signature, bytes 0 to 63
DATA_HEADERS = 88   # signature + common header (19) + data header (5)
CODE_HEADERS = 89   # signature + common header (19) + coding header (6)

# high nibble of byte 64: (kind, resigned)
VARIANTS = {0x60: ("code", False), 0x70: ("code", True),
            0x90: ("data", False), 0xB0: ("data", True)}

def parse_shred(buf):
    if len(buf) < CODE_HEADERS:
        raise ValueError(f"too short: {len(buf)} bytes")
    variant = buf[64]
    if variant & 0xF0 not in VARIANTS:
        raise ValueError(f"unknown variant {variant:#04x}")
    kind, resigned = VARIANTS[variant & 0xF0]
    proof_entries = variant & 0x0F
    slot, index, version, fec_set_index = struct.unpack_from("<QIHI", buf, 65)
    shred = {"kind": kind, "resigned": resigned, "proof_entries": proof_entries,
             "slot": slot, "index": index, "version": version,
             "fec_set_index": fec_set_index}
    # trailer: chained Merkle root (32), proof (20 per entry), retransmitter signature (64)
    trailer = 32 + 20 * proof_entries + (64 if resigned else 0)
    body_end = len(buf) - trailer
    if kind == "data":
        parent_offset, flags, size = struct.unpack_from("<HBH", buf, 83)
        if not DATA_HEADERS <= size <= body_end:
            raise ValueError(f"bad size field {size}")
        shred.update(parent_slot=slot - parent_offset,
                     reference_tick=flags & 0x3F,
                     data_complete=bool(flags & 0x40),
                     last_in_slot=flags & 0xC0 == 0xC0,
                     data=bytes(buf[DATA_HEADERS:size]))
    else:
        num_data, num_coding, position = struct.unpack_from("<HHH", buf, 83)
        if position >= num_coding:
            raise ValueError(f"bad position {position}")
        shred.update(num_data_shreds=num_data, num_coding_shreds=num_coding,
                     position=position)
    return shred
```

Feed it from a socket on your port:

```python file="listen.py"
import socket
from shred_header import parse_shred

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("0.0.0.0", 9000))
while True:
    pkt, _ = sock.recvfrom(1228)
    try:
        s = parse_shred(pkt)
    except ValueError as err:
        print("skipped:", err)
        continue
    print(s["slot"], s["kind"], s["index"], s["fec_set_index"])
```

We tested the parser on 127.0.0.1 with crafted 1,203-byte data shreds (`0x96`, and `0xB6` with `LAST_SHRED_IN_SLOT`), 1,228-byte coding shreds (`0x66` and `0x76`) and a legacy `0xA5` datagram. It returned the fields we wrote and rejected the legacy byte. A Rust version of the common-header part is on the [Rust receiver](https://nitride.xyz/docs/rust) page.

## Use the Agave crate in production
Fixed offsets are fine for counting and routing. For anything that must be correct across upgrades, such as signature checks, Merkle proofs or recovery, use the `shred` module of the `solana-ledger` crate from the Agave release the cluster runs. `Shred::new_from_serialized_shred` parses a payload, and the `Shred` type exposes `slot()`, `index()`, `fec_set_index()`, `data_complete()`, `last_in_slot()` and `verify()`.

Pin the exact version, because the crate's API sits behind the `agave-unstable-api` feature and can change between releases:

```toml file="Cargo.toml"
[dependencies]
solana-ledger = { version = "=4.4.1", features = ["agave-unstable-api"] }
```

The `=` stops Cargo from moving to a newer release on its own. Commit `Cargo.lock` too. To choose the version, compare the `version` field that the `getClusterNodes` RPC method returns for validators, and bump the pin when the network upgrades. Recent releases need a recent Rust toolchain; Cargo names the minimum if yours is too old.
