MQTT port numbers: 1883, 8883 and MQTT over WebSockets

Catalin NegruPublished 5 min read

Part of the MQTT guide

The default MQTT port is TCP 1883 for unencrypted connections and TCP 8883 for MQTT over TLS. Both are registered with IANA and named in the MQTT 3.1.1 and 5.0 standards. MQTT over WebSockets has no registered port of its own; it runs on whatever port the broker’s HTTP listener uses, usually 443 when TLS is on.

This page is part of the MQTT guide. What TLS adds on port 8883 is covered in MQTT security.

MQTT port reference

PortTransportIANA service nameUse
1883MQTT over TCPmqttUnencrypted. Test benches and isolated networks only
8883MQTT over TLS over TCPsecure-mqttThe normal choice for anything that crosses a network you do not control
80 or a broker-chosen portMQTT over WebSocketnoneUnencrypted WebSocket, for browsers on a trusted network
443 or a broker-chosen portMQTT over WebSocket over TLSnoneBrowser clients, and networks that allow outbound HTTPS only

The numbers are defaults. A broker can listen on any port, and many run several listeners at once: one for devices with client certificates, one for WebSocket clients, one bound to localhost for administration. The client has to be told which port and which transport; nothing in MQTT negotiates it.

Brokers ship with their own conventions for the WebSocket listeners, and the numbers differ from product to product, so read the broker’s configuration instead of guessing.

Which side needs the port open

MQTT connections are always opened by the client. The broker listens; clients dial out. That fixes the firewall rules:

  • At the broker: allow inbound TCP on the listener port from the networks where clients live.
  • At the device or plant: allow outbound TCP to the broker’s address on that port. No inbound rule, no port forward and no public address are needed on the device side.

Once the connection is up, messages flow both ways over it, so a device behind NAT receives commands on the same connection it opened. This is the main reason MQTT is used to get data out of plant networks.

Subscriptions do not need a second port or a second connection either. Publishing and subscribing share one TCP connection per client.

Port 1883: plain TCP

On port 1883 the MQTT packets are written directly to the TCP stream. Everything is readable by anyone on the path: topic names, payloads, and the user name and password in the CONNECT packet. Use it on a bench, between containers on one host, or on a control network that is already isolated. Do not expose it to the internet. Unauthenticated brokers on public addresses are found by scanners within hours, and a subscription to # reads everything they carry.

Port 8883: MQTT over TLS

On port 8883 the client completes a TLS handshake first and then speaks ordinary MQTT inside the encrypted channel. The MQTT packets are identical to those on 1883; a capture shows TLS records instead.

The client needs the right trust material before the handshake will succeed:

  • a CA certificate to verify the broker’s certificate,
  • the broker’s hostname as it appears in that certificate, since connecting by IP address often fails name verification,
  • a client certificate and private key, if the broker requires mutual TLS,
  • a clock that is roughly correct, because certificate validity is checked against it. A device that boots with its clock at 1970 will reject every certificate until it gets the time.

Client libraries usually express the choice in a URL scheme, mqtt:// for plain TCP and mqtts:// for TLS, with ws:// and wss:// for the WebSocket forms. These schemes are a library convention, not part of the standard.

MQTT over WebSockets

Browsers cannot open raw TCP sockets, so the standard defines how to carry MQTT inside a WebSocket connection. The client requests the WebSocket subprotocol mqtt, MQTT packets travel in binary frames, and a packet may be split across frames or share a frame with others. The broker’s WebSocket listener usually answers on a URL path as well as a port, and the path has to match.

Besides browsers, WebSockets over TLS on 443 help on networks whose egress policy allows HTTPS and nothing else. The cost is a few bytes of framing per message and an HTTP upgrade at connect time.

Keep alive, NAT and idle timeouts

A firewall or NAT device forgets an idle TCP connection after a timeout, often a few minutes on cellular networks, and then drops the packets silently. Neither end learns about it until it tries to send. MQTT’s keep alive prevents this: the client sends a PINGREQ whenever it has been silent for the keep alive period, and the broker closes a connection that has been quiet for one and a half times that period. Set the keep alive shorter than the shortest idle timeout on the path. Sixty seconds is a common starting point; on a metered link, measure the timeout before going shorter.

Troubleshooting a connection

SymptomLikely cause
Connection refusedNo listener on that port, or a firewall rejecting it
Connection times outA firewall dropping outbound traffic to the port, or the wrong address
TCP connects, then closes immediatelyA TLS client talking to 1883, or a plain client talking to 8883
TLS handshake failsMissing or wrong CA certificate, hostname mismatch, wrong clock, or no client certificate where one is required
CONNACK arrives with a refusalThe port is right; the problem is the credentials or the client identifier
Connects, then drops every few minutesIdle timeout shorter than the keep alive, or two clients sharing one client identifier
WebSocket returns HTTP 404Wrong URL path on the WebSocket listener

Two quick checks separate network problems from MQTT problems. openssl s_client -connect broker.example.com:8883 shows whether the port is reachable and which certificate the broker presents. An MQTT command line client pointed at the same host with the same certificates shows whether the broker accepts the CONNECT. If the first works and the second does not, the network is fine.

Ports used by ControlCom

Devices publish to the ControlCom Connect broker over TLS on port 8883. The device or application needs outbound access to that port; nothing has to be reachable from outside. For a sender that can only use outbound HTTPS, the platform’s HTTP API accepts the same JSON payload shape.

The ControlCom Edge Server, which runs on site, publishes its own ports for local clients. Its port reference lists 8883 for MQTT with Sparkplug B over mutual TLS, and 3041 for the web interface and for Sparkplug B over secure WebSockets with token-based authentication. The MQTT Explorer tool in the web interface connects on that same port at the path /mqtt.

The MQTT documentation  gives the connection details for a device, the Edge Server getting started guide  has the full port table, and the page for controls engineers covers what else a site network needs. For what happens after the port is open, continue with MQTT QoS.

One outbound rule for TCP 8883 is the network change a site needs before a device can publish to ControlCom Connect.