# MQTT Protocol

> A small way for devices to send messages. They post to a topic on a broker.

**Field:** Software Development  
**Category:** Embedded & IoT  
**Also known as:** MQTT, MQTT Broker, Mosquitto, MQTT Topic

## Think of it like

It is like a notice board. Devices pin notes under a topic. All who follow it get a copy.

## Definition

MQTT is a light messaging protocol made for small devices on the Internet of Things. Devices do not talk to each other straight. They send messages to a server called a broker, under a name called a topic. This is called publishing. Any device or app that subscribes to that topic gets the message. It is an OASIS standard.

## Example

Lucy's greenhouse sensor publishes to the topic greenhouse/temp. Her phone app and the fan both subscribe, so both get each reading.

## Example code

```console
$ mosquitto_pub -h localhost -t greenhouse/temp -m 24.5
$ mosquitto_sub -h localhost -t greenhouse/temp
24.5
```

One command publishes a reading to a topic. Anyone subscribed to it gets 24.5.

## Why it matters

Its messages are tiny, so it works on weak links and small chips. Adding a new listener needs no change to the sensor.

## Common mistake

Running a broker on the open internet with no password. Anyone can then read your sensors and send your devices orders.

## Three principles

- **Broker in the middle.** Devices never talk straight.
- **Topics.** Messages go under a name.
- **Small messages.** Built for weak links.

## Related terms

- [Publish-Subscribe (Pub/Sub)](https://learn.benibix.com/term/development/publish-subscribe)
- [Internet of Things (IoT)](https://learn.benibix.com/term/development/internet-of-things)
- [Message Queue](https://learn.benibix.com/term/development/message-queue)
- [ESP32 Microcontroller](https://learn.benibix.com/term/development/esp32)
- [Bluetooth Low Energy (BLE)](https://learn.benibix.com/term/development/bluetooth-low-energy)

![A temperature sensor in a greenhouse publishes a reading to a topic named greenhouse/temp on an MQTT broker in the middle, lit up. A phone app and a fan controller both subscribe to that topic and get the reading. Separately, a fitness band sends data a few metres to a phone over Bluetooth Low Energy, drawn as a short dotted link.](https://learn.benibix.com/diagrams/dev4-iot-mqtt.svg)

---

Source: https://learn.benibix.com/term/development/mqtt
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
