MQTT Codec
Encode and decode MQTT protocol packets
Paste MQTT packet data captured from Wireshark, network analyzer or broker logs
Example Packets
Decoded Result
Enter packet data and click Decode to see results
Byte Viewer
Encoded Result
Configure parameters and click Build Packet to generate
Byte Viewer
Packet Structure Preview
MQTT Packet Types 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 part 1) |
| 0x60 | PUBREL | C↔S | Publish release (QoS 2 part 2) |
| 0x70 | PUBCOMP | C↔S | Publish complete (QoS 2 part 3) |
| 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 | Ping request (keep-alive) |
| 0xD0 | PINGRESP | S→C | Ping response |
| 0xE0 | DISCONNECT | C→S | Client disconnect |
MQTT Protocol Guide
Understanding MQTT Protocol
MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol built on TCP/IP. Developed by IBM in 1999 for satellite link monitoring, it has become the de facto standard for IoT communication. The protocol uses a publish-subscribe pattern where clients communicate through a central broker, making it ideal for unreliable networks and resource-constrained devices.
Packet Binary Structure
Every MQTT packet begins with a fixed header (1-5 bytes), followed by an optional variable header and payload. The first byte contains the packet type in bits 7-4 and type-specific flags in bits 3-0. The remaining length field uses variable-length encoding.
| Bit Range | Field Name | Description |
|---|---|---|
| 7-4 | Packet Type | Control packet type (1-15) |
| 3-0 | Flags | Type-specific flags (DUP, QoS, RETAIN for PUBLISH) |
Variable Length Encoding
MQTT uses a compact encoding for the remaining length field. Each byte uses 7 bits for data and 1 bit as a continuation flag. Values 0-127 need 1 byte, 128-16383 need 2 bytes, up to 4 bytes maximum for lengths up to 268,435,455.
| Bytes | Min Value | Max Value |
|---|---|---|
| 1 | 0 | 127 |
| 2 | 128 | 16,383 |
| 3 | 16,384 | 2,097,151 |
| 4 | 2,097,152 | 268,435,455 |
CONNECT Packet Details
The CONNECT packet is sent first after TCP connection establishment. It contains protocol version, keep-alive interval, client ID, and optional credentials. Connect flags control session behavior including Clean Session, Will message configuration, and authentication.
PUBLISH Packet Mechanics
PUBLISH packets carry application messages. Fixed header flags indicate QoS level, retain behavior, and duplicate status. QoS 0 is fire-and-forget, QoS 1 guarantees at-least-once delivery, QoS 2 ensures exactly-once via four-way handshake.
QoS Delivery Guarantees
Practical Applications
- Analyzing packet captures from Wireshark or tcpdump for debugging
- Building test packets to verify MQTT broker or client implementations
- Learning MQTT protocol internals through hands-on packet inspection
- Troubleshooting IoT device connectivity and message delivery issues
- Generating sample packets for automated testing scenarios
Protocol Versions
Three major MQTT versions are in use: MQTT 3.1 (protocol level 3), MQTT 3.1.1 (protocol level 4, ISO/IEC 20922:2016), and MQTT 5.0 (protocol level 5) with enhanced features. This tool primarily targets MQTT 3.1.1, the most widely deployed version.
Related Tools
MQTT WebSocket Client
Browser-based MQTT client for connecting, publishing, subscribing, and debugging IoT messages via WebSocket
MQTT Topic Tester
Test and validate MQTT topic patterns with + and # wildcards against topic names for subscription testing
Modbus RTU/ASCII/TCP Parser
Parse, encode, and debug Modbus RTU/ASCII/TCP protocol frames with CRC-16/LRC calculation and serial debugging
Base Converter
Convert between binary, octal, decimal, and hexadecimal number systems with custom base support (2-36)