MQTT Encode/Decode
Online MQTT encode and decode tool for CONNECT, PUBLISH, SUBSCRIBE packet building and hex parsing, suitable for protocol learning and IoT integration debugging.
Paste MQTT packet data captured from Wireshark, logs, or network analyzers.
Example Packets
Decoded Result
Enter packet data and the parser runs automatically
MQTT Protocol Guide
Understanding MQTT
MQTT is a lightweight publish-subscribe protocol for IoT scenarios with low bandwidth and unstable networks. This tool helps you build and parse control packets for protocol learning and integration debugging.
Packet Structure Essentials
- Each MQTT packet contains fixed header, variable header, and payload. The fixed header is at least 2 bytes.
- In the first fixed-header byte, high 4 bits are packet type and low 4 bits are type-specific flags.
- Remaining Length uses variable-length encoding up to 4 bytes and supports values up to 268435455.
- PUBLISH packets must include Packet Identifier when QoS is greater than 0.
MQTT Packet Type Reference
| Code | Name | Direction | Description |
|---|---|---|---|
| 0x10 | CONNECT | C->S | Client connection request |
| 0x20 | CONNACK | S->C | Connection acknowledgment |
| 0x30 | PUBLISH | C<->S | Publish message |
| 0x40 | PUBACK | C<->S | Publish acknowledgment (QoS 1) |
| 0x50 | PUBREC | C<->S | Publish received (QoS 2) |
| 0x60 | PUBREL | C<->S | Publish release (QoS 2) |
| 0x70 | PUBCOMP | C<->S | Publish complete (QoS 2) |
| 0x80 | SUBSCRIBE | C->S | Subscribe request |
| 0x90 | SUBACK | S->C | Subscribe acknowledgment |
| 0xA0 | UNSUBSCRIBE | C->S | Unsubscribe request |
| 0xB0 | UNSUBACK | S->C | Unsubscribe acknowledgment |
| 0xC0 | PINGREQ | C->S | Heartbeat request |
| 0xD0 | PINGRESP | S->C | Heartbeat response |
| 0xE0 | DISCONNECT | C->S | Disconnect |
QoS Semantics
- QoS 0: at most once, lowest overhead, packet loss is possible.
- QoS 1: at least once, delivery guaranteed but duplicates may occur.
- QoS 2: exactly once, highest reliability with the highest handshake cost.
Typical Use Cases
- Parse captured hex packets and inspect control type and field values quickly.
- Generate CONNECT, PUBLISH, and SUBSCRIBE packets for broker and device integration tests.
- Teach MQTT binary structure with practical examples of fixed header and remaining length.
- Troubleshoot protocol-level issues such as connection failure, subscribe mismatch, and delivery anomalies.