wire / wire-format / mqtt-fixed-header
Every MQTT control packet begins with a 2+ byte fixed header: one byte holding a 4-bit packet type and 4 bits of type-specific flags, followed by a variable-length 'Remaining Length' encoded as 1-4 bytes of a base-128 varint (7 bits payload, top bit continuation). It is a compact type-then-length framing.
aka: MQTT control packet header · MQTT remaining length
spec: OASIS MQTT v5.0
MQTT's fixed header is a control-packet-type nibble + flags byte, then a Variable Byte Integer 'Remaining Length' giving the number of bytes in the variable header plus payload. The Variable Byte Integer is MQTT's own little-endian base-128 varint, capped at 4 bytes (max 268435455).
| field | size | meaning |
|---|---|---|
| Packet type | 4 bits | Control packet type, e.g. 1 CONNECT, 2 CONNACK, 3 PUBLISH, 8 SUBSCRIBE, 12 PINGREQ, 14 DISCONNECT, 15 AUTH. |
| Flags | 4 bits | Type-specific flags; for PUBLISH: DUP (bit 3), QoS (bits 2-1), RETAIN (bit 0). Other packet types use fixed reserved values. |
| Remaining Length | 1-4 bytes | Variable Byte Integer (7 bits payload per byte, high bit = continuation, little-endian groups) counting variable header + payload bytes that follow. |
example:
30 0C
PUBLISH with no flags: 0x30 = type 3 (PUBLISH), flags 0 (QoS 0, no DUP/RETAIN); 0x0C = Remaining Length 12 (single varint byte, high bit clear), so 12 more bytes follow.
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/mqtt-fixed-header
or /wire-format/mqtt-fixed-header.json