Skip to main content

MQTT Packet Types

MQTT 5.0 defines 15 control packet types. Each packet starts with a fixed header where bits 7–4 encode the packet type (1–15) and bits 3–0 encode packet-specific flags. Packet type 0 is reserved.

Fixed header byte 1: [Packet Type (bits 7-4)] [Flags (bits 3-0)]
Remaining length: variable-length encoding, 1–4 bytes (MQTT 5.0 §2.1.4)
Source: OASIS MQTT 5.0 §2.1.2 Table 2-1

Connection

Publish Flow

3PUBLISH
0x30Both

PUBLISH carries an application message from publisher to broker, or from broker to subscriber. The fixed header flags encode DUP (retransmission flag), QoS (0, 1, or 2), and RETAIN. For QoS 1, the broker responds with PUBACK. For QoS 2, the broker responds with PUBREC starting a four-part handshake. QoS 0 has no acknowledgement.

4PUBACK
0x40Both

PUBACK is the acknowledgement for a QoS 1 PUBLISH packet. The receiver sends PUBACK after it has accepted responsibility for the message. In MQTT 5.0, PUBACK carries a reason code – 0x00 = Success, 0x10 = No matching subscribers (message accepted but no one is subscribed), 0x80+ = failure codes.

5PUBREC
0x50Both

PUBREC is the first broker response in the QoS 2 four-part handshake: PUBLISH → PUBREC → PUBREL → PUBCOMP. When the broker receives a QoS 2 PUBLISH it stores the packet identifier and responds with PUBREC. The publisher must then send PUBREL. PUBREC in MQTT 5.0 carries a reason code.

6PUBREL
0x62Both

PUBREL is the publisher's release command in the QoS 2 handshake. Sent after receiving PUBREC. When the broker receives PUBREL, it delivers the message to subscribers and responds with PUBCOMP. PUBREL fixed header flags are 0010 – bit 1 must always be set to 1 per the MQTT 5.0 spec §3.6.1.

7PUBCOMP
0x70Both

PUBCOMP is the final packet in the QoS 2 handshake. Sent by the broker to the publisher after PUBREL is received and the message has been delivered. Both sides release the packet identifier after PUBCOMP. The QoS 2 flow is complete.

Subscribe