This flow shows how MQTT wildcard subscriptions use '+' to match one topic level and '#' to match multiple levels, deciding which messages to deliver.
Execution Sample
IOT Protocols
Subscribe to: sensors/+/temperature
Publish to: sensors/livingroom/temperature
Publish to: sensors/kitchen/humidity
Subscribe with '+' wildcard to receive temperature from any room, then publish messages to different topics to see which match.
Process Table
Step
Subscription Topic Filter
Published Topic
Match Condition
Match Result
Message Delivered
1
sensors/+/temperature
sensors/livingroom/temperature
'+' matches 'livingroom' level
Match
Yes
2
sensors/+/temperature
sensors/kitchen/humidity
'temperature' != 'humidity' at last level
No Match
No
3
sensors/#
sensors/kitchen/humidity
'#' matches all remaining levels
Match
Yes
4
sensors/#
devices/kitchen/humidity
First level 'sensors' != 'devices'
No Match
No
5
home/+/temperature
home/livingroom/temperature
'+' matches 'livingroom'
Match
Yes
6
home/+/temperature
home/livingroom/kitchen/temperature
'+' matches only one level, extra levels present
No Match
No
💡 All published topics checked against subscription filters; messages delivered only if match conditions met.
Status Tracker
Variable
Start
After 1
After 2
After 3
After 4
After 5
After 6
Final
Subscription Topic Filter
sensors/+/temperature
sensors/+/temperature
sensors/+/temperature
sensors/#
sensors/#
home/+/temperature
home/+/temperature
home/+/temperature
Published Topic
sensors/livingroom/temperature
sensors/kitchen/humidity
sensors/kitchen/humidity
devices/kitchen/humidity
devices/kitchen/humidity
home/livingroom/temperature
home/livingroom/kitchen/temperature
home/livingroom/kitchen/temperature
Match Result
Match
No Match
Match
No Match
No Match
Match
No Match
No Match
Message Delivered
Yes
No
Yes
No
No
Yes
No
No
Key Moments - 3 Insights
Why does '+' only match one level and not multiple levels?
The '+' wildcard matches exactly one topic level. For example, in row 6 of the execution table, 'home/+/temperature' does not match 'home/livingroom/kitchen/temperature' because '+' matches only 'livingroom', not multiple levels like 'livingroom/kitchen'.
How does '#' differ from '+' in matching topics?
The '#' wildcard matches zero or more levels at the end of the topic. For example, in row 3, 'sensors/#' matches 'sensors/kitchen/humidity' because '#' covers all remaining levels after 'sensors'.
Can '#' be used in the middle of a topic filter?
No, '#' must be the last character in the topic filter. It matches all remaining levels from that point. This is why in the examples, '#' appears only at the end.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at step 2, why is the message not delivered?
ABecause '+' does not match 'kitchen'
BBecause the last level 'humidity' does not match 'temperature'
CBecause '#' wildcard is missing
DBecause the published topic has too many levels
💡 Hint
Check the 'Match Result' and 'Match Condition' columns at step 2 in the execution table.
At which step does the '#' wildcard allow matching multiple topic levels?
AStep 3
BStep 1
CStep 5
DStep 6
💡 Hint
Look for '#' in the 'Subscription Topic Filter' column and see where it matches multiple levels.
If the subscription was 'home/#' instead of 'home/+/temperature', which published topic would match at step 6?
Asensors/livingroom/temperature
Bhome/livingroom/temperature
Chome/livingroom/kitchen/temperature
Ddevices/kitchen/humidity
💡 Hint
Refer to how '#' matches multiple levels in the variable_tracker and execution_table.
Concept Snapshot
MQTT wildcard subscriptions:
- '+' matches exactly one topic level
- '#' matches zero or more levels at the end
- '+' and '#' help subscribe to multiple topics easily
- '#' must be last in filter
- Messages delivered only if topic matches filter
Full Transcript
This lesson shows how MQTT wildcard subscriptions work using '+' and '#'. The '+' wildcard matches exactly one level in the topic path, like a single folder in a file path. The '#' wildcard matches all remaining levels, like a catch-all folder. We traced examples where subscriptions with '+' matched topics with one varying level, and '#' matched multiple levels. We saw why some messages are delivered and others are not, based on these rules. This helps understand how to subscribe to many topics efficiently in IoT messaging.
Practice
(1/5)
1. What does the MQTT wildcard + represent in topic subscriptions?
easy
A. It matches zero or more topic levels.
B. It matches exactly one topic level.
C. It matches the entire topic string.
D. It matches only the last topic level.
Solution
Step 1: Understand the + wildcard meaning
The + wildcard matches exactly one topic level in MQTT subscriptions.
Step 2: Compare with other wildcards
The # wildcard matches zero or more levels, so it is different from +.
Final Answer:
It matches exactly one topic level. -> Option B
Quick Check:
+ = one level [OK]
Hint: Remember: + means one level only [OK]
Common Mistakes:
Confusing + with # wildcard
Thinking + matches multiple levels
Assuming + matches zero levels
2. Which of the following is the correct MQTT subscription syntax to match all topics under home/kitchen including sub-levels?
easy
A. home/kitchen/#
B. home/+/kitchen
C. home/kitchen/+
D. home/#/kitchen
Solution
Step 1: Identify the wildcard for all sub-levels
The # wildcard matches all remaining topic levels, including zero or more sub-levels.
Step 2: Apply to the topic home/kitchen
Using home/kitchen/# subscribes to home/kitchen and any deeper topics like home/kitchen/temperature.
Final Answer:
home/kitchen/# -> Option A
Quick Check:
# matches all sub-levels [OK]
Hint: Use # to catch all subtopics under a path [OK]
Common Mistakes:
Using + instead of # for multiple levels
Placing # in the middle of the topic
Using invalid syntax like # in the middle
3. Given the subscription building/+/temperature, which of these topics will be matched?
medium
A. building/floor1/temperature
B. building/floor1/room1/temperature
C. building/temperature
D. building/floor1/humidity
Solution
Step 1: Understand the + wildcard position
The + wildcard matches exactly one topic level between building and temperature.
Step 2: Check each topic against the pattern
Topic building/floor1/temperature matches because floor1 fills the + wildcard. Others either have too many or too few levels or wrong last level.
Final Answer:
building/floor1/temperature -> Option A
Quick Check:
+ matches one level only [OK]
Hint: + matches exactly one level between slashes [OK]
Common Mistakes:
Matching topics with extra levels
Ignoring the exact position of +
Assuming + matches zero levels
4. You wrote the subscription sensor/#/temperature but it does not work. What is the problem?
medium
A. The subscription is missing a leading slash.
B. The + wildcard should be used instead of # here.
C. The topic levels are case sensitive and must be lowercase.
D. The # wildcard must be at the end of the topic filter.
Solution
Step 1: Recall the rule for # wildcard placement
The # wildcard must be the last character in the topic filter and can only appear once.
Step 2: Analyze the subscription sensor/#/temperature
Here, # is in the middle, which is invalid syntax and causes the subscription to fail.
Final Answer:
The # wildcard must be at the end of the topic filter. -> Option D
Quick Check:
# only at end [OK]
Hint: # must be last in topic filter [OK]
Common Mistakes:
Placing # in the middle of topic
Confusing + and # usage
Ignoring MQTT topic syntax rules
5. You want to subscribe to all topics under office but only one level deep, such as office/room1 and office/room2, but not office/room1/temperature. Which subscription should you use?
hard
A. office/+/+
B. office/#
C. office/+
D. office
Solution
Step 1: Understand the requirement for one level deep
You want to match topics exactly one level below office, like office/room1.
Step 2: Choose the correct wildcard
The + wildcard matches exactly one level, so office/+ matches office/room1 but not office/room1/temperature.
Final Answer:
office/+ -> Option C
Quick Check:
One level deep = use + wildcard [OK]
Hint: Use + for exactly one sub-level [OK]
Common Mistakes:
Using # which matches all levels
Using multiple + wildcards incorrectly
Not including any wildcard
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.