TodayTools

Compare protocols

MQTT vs HTTP for IoT: which one should devices use

Donate
What brings you here?

The difference at a glance

MQTT

MQTT

Best for: Sensors that report often

One open link and tiny messages, both ways.
  1. Connect, from Sensor
  2. 21 C, from Sensor
  3. 22 C, from Sensor
  4. Fan on, from Broker

HTTP

Hypertext Transfer Protocol

Best for: Devices that report now and then

A full request and answer for every reading.
  1. POST 21 C, from Sensor
  2. 200 OK, from Web API
  3. POST 22 C, from Sensor
  4. 200 OK, from Web API

The short answer

MQTT keeps one connection open to a broker, and devices publish tiny messages to topics that other devices subscribe to, so updates are pushed at once. HTTP is request and response: a device must ask each time, with larger headers. MQTT suits sensors on weak links and batteries. HTTP suits occasional uploads and devices that talk to web APIs.

Which one fits you?

Tick everything that is true for you.

What do you need?

Your pick shows here

Tick one or more lines and we weigh them for you.

MQTT and HTTP side by side

MQTT vs HTTP for IoT: differences row by row
What differsMQTTHTTP
PatternPublish and subscribe through a brokerRequest and response, client to server
Smallest header2 bytesOften hundreds of bytes
ConnectionKept open, with a keepalive pingOpened for requests, reused with keep-alive
Server sends firstYes, the broker pushes to subscribersNo, the client must ask or poll
Delivery optionsQoS 0, 1 or 2One request, one response
Offline noticeLast Will message when a device dropsNone built in
Ports1883, 8883 with TLS80, 443 with TLS
StandardOASIS MQTT 3.1.1 and 5.0RFC 9110

Watch each one work

Each page plays the real packets on a map, step by step, with every header explained.

Test yourself

Each line describes one of the two. Which one?

Question 1 of 8

Pattern

Publish and subscribe through a broker

Questions people ask

Is MQTT faster than HTTP?

For many small messages, yes. There is no new request each time and the header is tiny. For one big file, HTTP is just as good.

Does MQTT need a server?

Yes, a broker. Devices never talk to each other directly. They publish to the broker, which sends each message to every subscriber of that topic.

Can a browser use MQTT?

Yes, through MQTT over WebSockets, which most brokers support.

Is MQTT secure?

Plain MQTT on port 1883 is not encrypted. Use port 8883 with TLS, plus usernames or client certificates.

More comparisons

Donate