What is Topic?
Updated: Oct 27

A topic is a name used to organise and route messages in a messaging system. In MQTT, the publisher attaches a concrete topic name to each application message, and subscribers register topic filters that describe the names they want to receive. A matching filter selects a message; it does not describe the message’s contents or prove that an application processed it.
For example, a home monitoring controller might publish a reading on home/boiler-01/temperature. A dashboard interested in temperature readings from every device could subscribe to home/+/temperature. The broker compares the name with the filter, then delivers qualifying messages under the relevant permissions and delivery settings.
This guide concentrates on MQTT because topic names and wildcard filters are central to that protocol. Other systems also use the word topic, but their naming, storage and subscription rules can be substantially different. A Kafka topic is not simply an MQTT topic with another separator.
How does a topic fit into MQTT messaging?
A topic supplies application-level routing information. It is separate from the broker’s hostname or IP address, which tells the client where to establish its connection. Two clients can use the same broker endpoint while publishing to entirely different topic names.
Concept | Role in the example |
|---|---|
Topic name | home/boiler-01/temperature labels one publication. |
Topic filter | home/+/temperature expresses a subscriber’s interest. |
Payload | A reading such as {"value":21.5,"unit":"C"} carries application data. |
Broker endpoint | The host and port where the MQTT connection is established. |
The normal MQTT topic matcher does not inspect a JSON value and decide whether the temperature exceeds a threshold. A consumer, processing rule or additional product feature must perform that work. Changing the payload from 21.5 to 25 does not change whether the name matches home/+/temperature.
The MQTT guide explains the surrounding connection and publication process. Here, the important distinction is between the concrete label sent by a producer and the selection expression registered by a consumer.
Do topics need to be created first?
MQTT does not require every client application to create a queue-like topic object before it can publish or subscribe. However, that is not a promise that every syntactically valid name will be accepted. The server can use predefined resources, dynamic topic resources, authorisation policies and operational limits.
A cloud service can also impose an application-specific topic layout. A name can be valid MQTT syntax while still being outside that service’s supported namespace or the connecting identity’s permissions. Check the broker or service contract as well as the protocol.
How do topic levels and wildcard filters work?
A forward slash separates MQTT topic levels. The name home/boiler-01/temperature has three levels: home, boiler-01 and temperature. A subscriber can select that exact name or replace complete levels with the permitted wildcard characters.
The MQTT 5.0 standard defines + as a single-level wildcard and # as a multi-level wildcard. The same basic matching rules are present in MQTT 3.1.1. These are MQTT rules, rather than regular-expression or filesystem-glob syntax.
The publisher sends a concrete name such as home/boiler-01/temperature.
The subscriber registers home/+/temperature and receives the subscription acknowledgement.
The broker compares the first level home and the last level temperature exactly; + accepts the intervening level.
If the name matches and delivery is permitted, the broker sends a qualifying publication to the subscriber.
The application decodes the payload and performs any validation, threshold calculation or other processing.
The filter home/+/temperature matches home/boiler-01/temperature and home/room-02/temperature. It does not match home/boiler-01/flow/temperature, because that publication has an additional level. The plus sign does not mean “any characters until something eventually matches”.
The filter home/# includes both home itself and its descendants. The number sign must be the final character and must stand alone or follow a slash. home/#/temperature and home/device# are invalid filters. A plus sign must occupy a whole level, so home/boiler+/temperature is invalid too.

Can a publisher send to a wildcard topic?
No. MQTT wildcard characters belong in subscription filters, not in publication topic names. Publishing once to a concrete name can already reach several matching subscribers. The broker performs that fan-out; the producer does not need to publish to home/# to request it.
The publish subscribe model guide explains why independent matching subscribers receive their own deliveries. It also separates that arrangement from workers sharing one set of jobs. In MQTT 5, $share/group/filter is a special shared-subscription filter format, not a literal name that ordinary publishers should use for the application message.
Which edge cases change topic matching?
Topics are case-sensitive. Leading, trailing and repeated slashes are significant, because they change the levels or introduce empty ones. It is useful to choose a consistent convention, but a naming recommendation is not the same thing as a protocol prohibition.
Filter and publication | Result and reason |
|---|---|
home/+ against home/ | Matches: there is an empty final level for + to match. |
home/+ against home | Does not match: there is no second level. |
home/# against home | Matches: # includes the parent topic. |
home/router/status against Home/router/status | Does not match: Home and home differ. |
home/router/status against /home/router/status | Does not match: the leading slash adds an initial empty level. |
# against $SYS/broker/uptime | Does not match: a leading wildcard does not select names beginning with $. |
A name consisting only of / is valid MQTT syntax. It is still usually a poor application naming choice because its meaning is unclear. Spaces are permitted by the topic rules, although avoiding ambiguous whitespace can make configuration and diagnosis easier.
Why does # miss $SYS messages?
MQTT gives names beginning with $ special treatment. A filter starting with # or + must not match them. A permitted subscription to $SYS/# can match $SYS/broker/uptime, whereas # cannot. The actual system topics exposed by a broker are product-specific; do not assume every broker publishes the same statistics.
This exception applies to the leading character of the name. It is not a general rule that a dollar sign anywhere inside a topic disables wildcard matching. Server-defined or reserved namespaces should be used according to the implementation’s documentation, not as an unrestricted application channel.
UTF-8 length and visually similar names
MQTT topic names and filters are UTF-8 encoded strings, limited by the protocol to 65,535 encoded bytes. They cannot contain the null character U+0000, and the UTF-8 must be well formed. A broker or service may impose a smaller practical limit. Do not confuse the protocol ceiling with a recommended topic length.
The broker must not normalise names during subscription matching. A precomposed é and an e followed by a combining accent can look similar while producing different names. In our Python check, home/café/temperature contained 21 characters but required 22 UTF-8 bytes. Count encoded bytes when validating a byte limit.
A normal resolved topic name is non-empty. MQTT 5 can omit its spelling in a later PUBLISH packet when a valid Topic Alias mapping supplies the name. That wire encoding exception does not create a nameless application topic.
What did our local topic experiment verify?
Techie Broadband ran 14 topic-matching cases through an actual disposable MQTT 3.1.1 broker on 26 October 2026. The setup used Python 3.12.14, aMQTT 0.12.1 and Eclipse Paho MQTT Python 2.1.0 over TCP on an automatically selected 127.0.0.1 port. Clients used clean sessions, QoS 1 and subscriptions acknowledged before each test publication.
The network cases covered exact and wildcard matching, an extra topic level, the parent covered by home/#, empty levels, case differences, leading and trailing slashes, the valid / name, spaces and the two Unicode spellings of café. Each positive case received its identifiable payload. Negative cases observed no delivery during a finite 250 ms window.
We separately checked 17 filter/name pairs with Eclipse Paho’s topic matching helper, including three reserved-$ examples. Those three were library comparisons, not publications to a broker’s system namespace. All 33 recorded checks passed: 14 network cases, 17 helper comparisons, a loopback-address check and listener closure after cleanup.
This was a local functional experiment. It did not measure broadband performance or broker capacity, and it did not test authentication, ACL enforcement, persistence, failure recovery or MQTT 5 aliases. Anonymous plaintext access was confined to loopback; the clients and broker were stopped afterwards. A 250 ms absence observation is not a universal delivery deadline.
How should you design a useful topic namespace?
Choose levels from the questions subscribers actually need to ask. For a home lab, home/device-id/measurement can make it easy to select one device or one measurement across devices. For several sites, a site level might belong earlier in the path. The hierarchy should reflect the application’s selection and ownership needs.
Use stable device identifiers where identity must survive an address change; an IP address is not always a durable application identity.
Keep telemetry, state, events and commands distinguishable when they have different handling or permission rules.
Document units, payload schema, timestamps and compatibility expectations alongside the name.
Avoid inserting passwords, access tokens, personal addresses or other unnecessary sensitive data into topic names.
Choose deliberate rules for case, separators and optional levels, then validate producers against them.
The topic home/boiler-01/temperature does not establish whether a number is Celsius, Fahrenheit, current or stale. Put that information in a documented payload contract or a clearly versioned application convention. The spelling temperature is useful to people but has no built-in measurement semantics in MQTT.
Separate a report such as state/boiler-01 from a request such as command/boiler-01/setpoint when their consequences differ. A dashboard may read state while only a controller may issue commands. Retaining a command can also cause an action when a new subscriber joins, so retention needs an explicit decision rather than a copied default.
A matching topic is not an access-control decision
A wildcard broadens selection, not entitlement. Authentication identifies a client, and authorisation determines what it can publish, subscribe to or receive. The Mosquitto Dynamic Security documentation illustrates separate checks for publishing, receiving and subscription operations. The exact policy model depends on the broker and plugin.
Our ACL guide explains the broader idea of matching rules and policy enforcement. Router-style first-match rules should not be assumed to describe every MQTT authorisation plugin. Test the actual producer and consumer identities against the intended topic permissions, including broad wildcard requests.
A narrow-looking topic name is not a secret or a security boundary by itself. Protect transport where appropriate and check logging, monitoring, bridge and administrative access too. Topic names may appear in systems beyond the application that originally published the message.
Does a topic store messages or guarantee delivery?
In MQTT, the name alone does not define a durable history. A retained publication can provide a latest stored value for a matching topic, while session settings and QoS affect other delivery state. Neither a readable name nor a successful match proves that a disconnected subscriber can recover every earlier event.
The message broker guide follows those acceptance, routing, delivery and application-completion boundaries. The MQTT QoS guide explains the protocol exchanges separately. An application that needs an audit trail must choose a history-preserving design and verify its retention and recovery behaviour.
System or feature | What the name selects |
|---|---|
MQTT topic name and filter | A publication label and matching subscription expression; persistence is a separate decision. |
Kafka topic | Records organised into partitions, with retention and consumer positions in the Kafka model. |
NATS subject | A named routing channel using dot-separated tokens and its own wildcard rules. |
RabbitMQ topic exchange | A routing-key pattern selects bound destinations; the exchange name is not the message’s MQTT topic. |
For example, NATS uses * for one token and > for one or more trailing tokens. MQTT’s # also includes the parent with zero further levels. Copying an MQTT filter into a different system without checking its semantics can therefore change the selected messages, even if the design looks similar.
How much topic-name overhead can MQTT 5 aliases remove?
A topic name travels as part of a PUBLISH packet unless the protocol and connection state allow another encoding. Our example home/boiler-01/temperature is 26 UTF-8 bytes. Its ordinary topic field uses two length bytes plus the name, giving 28 bytes before the packet’s other fields.
MQTT 5 Topic Alias can bind a small integer to a full name for one network connection. Once an allowed mapping exists, a later publication can use an empty topic-name field and the alias property. The receiver resolves that representation back to the established name before processing the message.
Illustrative encoding | Topic field and alias-property bytes |
|---|---|
Full 26-byte name, without alias | 2 length bytes + 26 name bytes = 28 bytes. |
Established alias, empty name field | 2 length bytes + 1 property identifier + 2 alias-value bytes = 5 bytes. |
Difference for these fields | 28 − 5 = 23 bytes per qualifying later publication. |
This is a field-level arithmetic model, not a packet capture or a measured 23-byte saving for every network transmission. It excludes initial mapping, changes to property-length and Remaining-Length encodings, the other packet fields, payload, acknowledgements, TCP and TLS. Small names or a short-lived connection may offer less benefit once setup is included.
Alias zero is invalid. The sender must respect the maximum advertised by the receiver; an absent or zero maximum means no aliases are accepted in that direction. The mappings used in opposite directions are independent, and they expire when that network connection ends. A reconnecting client must establish the required mapping again, even if another form of MQTT session state survives.
How do you change topic names without losing consumers?
Treat a topic rename as an interface change. A subscriber to the old exact name will not automatically follow a producer to the new one. An added level can also break a + filter while leaving a broad # filter apparently healthy, which can hide the migration gap.
Inventory the producers, consumers, bridges, retained values and permission rules that reference the old namespace.
Specify the new names, payload compatibility, ownership and cutover conditions.
Introduce compatible subscriptions or a controlled translation path, with stable event identities where duplicate delivery is possible.
Verify representative messages at each required consumer, including exact, wildcard and restricted identities.
Switch producers deliberately and monitor old and new paths during the agreed transition.
Retire obsolete routes, permissions and retained state only after dependent consumers have been checked.
Publishing to both paths during a transition can create duplicate business effects if a consumer receives both. A bridge can also create a loop if the translated message returns to its source. Test those consequences explicitly; a successful new subscription is only one part of a safe change.
How should you diagnose a topic that receives nothing?
First compare the exact name and filter as data, not as similar-looking labels. Check case, every slash, empty levels, whitespace and UTF-8 spelling. Then establish whether the client is connected to the intended broker and whether the subscription was accepted under the identity actually in use.
Check the publication name and registered filter side by side, including the $ namespace exception.
Inspect subscription acknowledgement results and the broker’s relevant authorisation decisions.
Confirm that the publication happened while the subscription was active, or that an applicable recovery mechanism exists.
Separate broker receipt and client callback delivery from payload decoding and successful application work.
Check MQTT 5 options such as No Local, retained-message handling or shared subscriptions if those features are configured.
A local broker can keep a home-lab exchange working during a broadband outage if its dependencies remain local. A cloud broker or bridge still depends on the remote path. A malformed filter and a failed internet connection need different repairs, so trace the boundary before changing the network.
A useful topic design makes selection predictable, permissions auditable and change manageable. It gives a message a clear place in the application contract while leaving payload meaning, storage, recovery and successful processing explicit.
Frequently asked questions
What is a topic in MQTT?
A topic name labels a published application message. Subscribers register topic filters, and the broker compares those filters with the name to select qualifying deliveries. The topic is separate from the payload and the broker’s network address.
What is the difference between a topic name and a topic filter?
A publisher uses a concrete topic name, such as home/router/status. A subscriber uses a filter that may be exact or include MQTT wildcards, such as home/+/status. Wildcards are not permitted in publication topic names.
Does home/# include home itself?
Yes. MQTT’s multi-level wildcard includes the parent and any number of child levels. By contrast, home/+ needs a second level, although that level can be empty in the name home/.
Why does subscribing to # not show $SYS topics?
MQTT excludes names beginning with $ from filters that begin with # or +. An authorised subscription to the relevant explicit system namespace, such as $SYS/#, is needed. The system topics available depend on the broker.
Does a topic automatically keep a message history?
No. In MQTT, the topic name does not create a complete event log. Retained latest values, session delivery state and application history are separate mechanisms with their own settings and limits.
Does an MQTT 5 Topic Alias survive reconnecting?
No. A Topic Alias mapping belongs to one network connection and must not carry over to the next connection. The sender must establish the mapping again and respect the receiving peer’s advertised maximum.

