← Glossary

What Is STUN in WebRTC?

STUN is the protocol a WebRTC endpoint uses to learn the public address and port that a NAT has assigned to it, by asking a STUN server what address its request appeared to come from. The answer becomes a server-reflexive candidate for connection attempts; STUN does not relay media and is not the signaling channel.

Updated:

STUN, Session Traversal Utilities for NAT, is the protocol a WebRTC endpoint uses to discover how it appears from the outside of its network. A device behind a home router may know its local address without knowing the external mapping a remote peer would see. It sends a small request to a STUN server, and the server replies with the source address and port it observed. That reply gives the device an address it can offer to a peer as a possible way to reach it. The current specification is RFC 8489, which replaced RFC 5389 and states plainly that STUN is not a NAT traversal solution by itself but a tool used within larger mechanisms, chiefly ICE. Address discovery is its best-known role in WebRTC. A standalone STUN discovery server does not relay the call or introduce its participants. STUN messages also serve other ICE functions, including connectivity checks between peers.

STUN Requests and Address Discovery

The core exchange is the Binding request. The client sends it from the local address and port it intends to use for media. On its way out, the NAT rewrites the private source address to a public one and creates a mapping so that replies can find their way back. The STUN server reads the source of the packet as it arrived, which reflects the mapping on that path when NAT is involved, and returns it in the response inside an attribute called XOR-MAPPED-ADDRESS. RFC 8489 refers to this discovered address as the reflexive transport address, and the exclusive-or encoding exists so that NATs which rewrite addresses inside packet payloads do not corrupt the answer.

STUN runs over UDP, TCP and their encrypted forms TLS and DTLS, with 3478 as the default port for unencrypted use. Requests carry a transaction identifier so responses can be matched, and the protocol includes integrity and authentication attributes for uses that need them. A WebRTC application names one or more STUN servers in its peer connection configuration, and the browser gathers candidates according to its ICE implementation and privacy policy. It need not expose every interface. STUN can report an address even without NAT; a directly addressed endpoint may receive the same address it already knew.

Server-Reflexive ICE Candidates

WebRTC does not use STUN results directly; it feeds them into Interactive Connectivity Establishment, defined in RFC 8445. ICE gathers candidates, meaning possible transport addresses at which an endpoint might be reached, and classifies them by how they were obtained. A host candidate is a local interface address. A server-reflexive candidate is, an address learned from an external server's observation, commonly the NAT mapping created for that connection. A relayed candidate is an address on a relay server that will forward traffic. Peer-reflexive candidates appear later, discovered during connectivity checks when a NAT mapping is observed that no earlier step predicted.

Candidate typeHow it is obtainedWhat it represents
HostRead from local interfacesPrivate or directly reachable address
Server-reflexiveSTUN Binding request to a STUN serverPublic mapping created by the NAT
Peer-reflexiveObserved during connectivity checksA NAT mapping toward the specific peer
RelayedAllocation on a TURN serverAddress on a relay that forwards traffic

Each endpoint sends its candidate list to the other through the application's signaling channel. The two sides then pair local and remote candidates and run connectivity checks, which are themselves STUN Binding requests sent directly between the peers rather than to a server. A pair succeeds when a check and its response both get through, and ICE selects a working pair for media. A server-reflexive candidate succeeds when the NAT on each side permits inbound traffic to the discovered mapping, which depends on the NAT's behaviour and not only on STUN having reported an address.

STUN vs TURN and Signaling

Three components are routinely conflated, and separating them clarifies what STUN is responsible for.

A standalone STUN discovery service supplies an address observation, without carrying audio or video payloads. TURN adds an allocated relay address and forwards traffic through a server. That uses relay bandwidth, and may change latency, but its main purpose is to provide a usable path when direct paths fail or are not desired.

Relay use is not limited to a last resort. A WebRTC application can require relay-only candidates for a privacy or network-policy reason. Conversely, configuring only a STUN server does not create a relay fallback. If no suitable direct path works and no TURN service is available, the connection can fail.

STUN also remains relevant after initial discovery. ICE connectivity checks use it between endpoints, and WebRTC consent-freshness checks use STUN messages to confirm continued consent to receive traffic. Such control messages are different from routing the media through a discovery server.

Signaling is the third piece and is outside both protocols. The peers must exchange session descriptions, candidate lists and control messages before any direct path exists, and RFC 8445 is explicit that ICE is not intended for NAT traversal of the signaling protocol, which is assumed to be provided by another mechanism such as a server the application already talks to. WebRTC leaves this to the developer; a WebSocket connection to the application's own server is a common choice. A typical deployment combines application signaling with STUN discovery and TURN capacity. A connection on an already reachable path may not need an external discovery server, and a relay-only policy intentionally skips direct media paths.

What STUN Reveals and Why It Matters

The address reported reflects the request's actual network path. It can contribute to a candidate exposed to page code or the remote peer, subject to browser policy. This is the origin of the privacy concern often called a WebRTC leak: a browser routing HTTP traffic through a proxy may still send STUN requests directly, so the server-reflexive candidate shows the real network's address rather than the proxy's. Whether this happens depends on how the browser and the proxy handle UDP and on browser policies that may restrict candidate exposure. The behaviour is a consequence of STUN doing exactly what it is designed to do, discover the path's external address, applied in a context where the user expected a different path to be used. The leak itself, and the mitigations for it, are a separate topic from the protocol.

Limits of STUN

STUN cannot guarantee connectivity. Some NATs allocate a different public mapping for every destination, so the address a STUN server observes is not the one a peer would need, and the server-reflexive candidate fails its checks. Firewalls may block UDP entirely or restrict inbound traffic regardless of mappings. A suitably configured TURN path can help in these cases, but it must itself be reachable through the network's restrictions. STUN also says nothing about who the peer is or whether the media is encrypted; those are handled by WebRTC's own security mechanisms and the application's authentication. An unreachable STUN service can leave discovery incomplete or delayed. Applications should distinguish that failure from failed peer checks or an unavailable relay; these are different stages of establishing connectivity.

Frequently asked questions

Does a STUN server relay a video call?

A standalone STUN discovery server does not relay media. TURN provides relayed candidates and forwards traffic when selected, either because direct paths fail or because the application requires a relay. STUN control messages can still be used for checks after the call connects, without turning the discovery server into a media relay.

Is STUN enough for every NAT?

No. An address learned from one server may not work toward another destination, and firewalls can prevent a candidate pair from succeeding. ICE tests reachability instead of trusting discovery alone. TURN can provide another path if configured and reachable, but no combination guarantees access through every network policy.

Can the observed address differ from a web request's IP?

Yes. STUN reports the external address of whatever network path the request actually took. If HTTP traffic goes through a proxy but STUN requests go directly, the server-reflexive candidate shows the direct path's address. This is the mechanism behind the privacy issue known as a WebRTC leak.

What is a server-reflexive candidate?

An ICE candidate whose address and port are the mapping a NAT allocated for the endpoint, discovered by sending a STUN Binding request to a server outside the NAT. It is offered to the peer alongside host and relayed candidates and succeeds only if the NAT accepts the peer's inbound traffic.

Is STUN the signaling channel in WebRTC?

No. Signaling, the exchange of session descriptions and candidates between peers, is provided by the application through its own server, often over a WebSocket. STUN is used by each endpoint independently to discover addresses, and its results are then sent to the peer via that separate signaling path.