MQTT Control Packet Utility

MQTT Packet Decoder

Decode raw MQTT control packet bytes and inspect packet type, fixed-header flags, Remaining Length, QoS, DUP, RETAIN, topic name, packet identifier, payload and common CONNECT, PUBLISH and subscription fields.

✓ CONNECT ✓ PUBLISH ✓ SUBSCRIBE ✓ ACK Packets ✓ Remaining Length ✓ UTF-8 Payload
MQTT
MQTT Control Packet Decode
● Ready
Enter one complete MQTT control packet beginning with the fixed-header byte. Spaces, commas, colons, hyphens, line breaks and continuous hexadecimal are accepted.
Remaining Length determines the number of bytes following the MQTT fixed header.
Decoder scope: this page decodes one MQTT control packet from its fixed header through its declared Remaining Length. It focuses on the standard packet structure used by MQTT 3.1.1-style packets. MQTT 5 properties introduce additional fields that require version-specific interpretation.
MQTT Packet Decode Result Packet Decoded
Decoded MQTT Packet
Packet Type
Type Value
DUP
QoS
RETAIN
Remaining Length
Header Bytes
Total Packet Size
Topic
Packet Identifier
Protocol
Client ID
Packet-Specific Fields
Payload
Fixed Header Breakdown
Validation

What Is an MQTT Control Packet?

MQTT communication is carried in control packets. Every packet begins with a fixed header containing a four-bit packet type, four flag bits and a variable-byte Remaining Length field.

Depending on the packet type, a variable header and payload can follow the fixed header.

MQTT Fixed Header

First Byte: Bits 7:4 Control Packet Type Bits 3:0 Packet-specific flags Following Bytes: Remaining Length

MQTT Control Packet Types

Value Packet Purpose
1CONNECTClient connection request
2CONNACKConnection acknowledgement
3PUBLISHPublish application message
4PUBACKQoS 1 publish acknowledgement
5PUBRECQoS 2 publish received
6PUBRELQoS 2 publish release
7PUBCOMPQoS 2 publish complete
8SUBSCRIBESubscribe to topic filters
9SUBACKSubscribe acknowledgement
10UNSUBSCRIBERemove subscriptions
11UNSUBACKUnsubscribe acknowledgement
12PINGREQKeep-alive request
13PINGRESPKeep-alive response
14DISCONNECTDisconnect notification

MQTT Remaining Length

Remaining Length uses a variable-byte encoding. Each byte contributes seven data bits, and bit 7 indicates whether another length byte follows.

Example: 0x7F = 127 bytes 0x80 0x01 = (0 & 127) + (1 × 128) = 128 bytes

MQTT PUBLISH Packet

A PUBLISH packet carries an application message. Its fixed-header flags include DUP, QoS and RETAIN.

PUBLISH First Byte: Bit 3: DUP Bits 2:1: QoS Bit 0: RETAIN

The variable header begins with a UTF-8 Topic Name. A Packet Identifier follows the topic when QoS is greater than zero.

MQTT Topic Name Encoding

MQTT UTF-8 strings are preceded by a two-byte big-endian length field.

00 04 74 65 73 74 00 04: Length = 4 74 65 73 74: "test"

MQTT CONNECT Packet

CONNECT is the first packet sent by an MQTT client after the network connection has been established. Its variable header includes protocol name, protocol level, connect flags and keep-alive value.

The payload can contain Client Identifier, Will Topic, Will Payload, User Name and Password depending on the Connect Flags.

MQTT CONNECT Flags

Bit Meaning
7User Name Flag
6Password Flag
5Will Retain
4:3Will QoS
2Will Flag
1Clean Session in MQTT 3.1.1
0Reserved

MQTT SUBSCRIBE Packet

SUBSCRIBE contains a Packet Identifier followed by one or more topic-filter entries. In MQTT 3.1.1 each entry contains a UTF-8 topic filter and a requested QoS byte.

MQTT QoS Levels

QoS Meaning
0At most once
1At least once
2Exactly once

MQTT Packet Decoder FAQs

What does MQTT packet byte 0x30 mean?
The upper nibble is 3, identifying PUBLISH. The lower four bits are zero, so DUP=0, QoS=0 and RETAIN=0.
How is MQTT Remaining Length encoded?
It uses one to four bytes with seven value bits per byte and bit 7 as the continuation flag.
Where is the MQTT topic in a PUBLISH packet?
The PUBLISH variable header starts with a two-byte UTF-8 string length followed by the Topic Name bytes.
Does QoS 0 PUBLISH contain a Packet Identifier?
No. A PUBLISH Packet Identifier is present only when the QoS level is greater than zero.
What is MQTT packet type 12?
Packet type 12 is PINGREQ.
Can this decoder parse MQTT 5 packets?
It can decode the common fixed-header structure, but MQTT 5 adds property lengths and property fields that require version-specific parsing. This page focuses on the classic MQTT 3.1.1 packet layout.
Scroll to Top