STUN and TURN servers explained: how WebRTC calls find a path
WebRTC browsers cannot see each other behind NAT. STUN discovers your public address, TURN relays media when direct paths fail, and ICE picks the best route. What each costs and when you need your own.
Every WebRTC call starts with the same problem: the two browsers usually sit behind different routers and cannot see each other's real network address. STUN and TURN are the two standard tools that solve it. This guide explains what each one does, when you need your own, and what they cost - the infrastructure question behind our video-calling build-vs-buy guide.
The problem: NAT
Most devices sit behind network address translation (NAT): the device knows its private address, but the outside world sees the router's public address and port. Two browsers that want to exchange media peer-to-peer first have to discover address-port pairs where the other side can actually reach them. The framework that coordinates this discovery is ICE (Interactive Connectivity Establishment, RFC 8445): each side gathers candidate addresses - its host address, a server-reflexive address learned through STUN, and a relayed address on a TURN server - then runs connectivity checks, in priority order, to find the best working path. Per MDN's WebRTC connectivity documentation, the candidates are exchanged through your signaling channel alongside the SDP offer and answer.
STUN: discovering your public address
STUN (Session Traversal Utilities for NAT, RFC 8489) answers one question: "what public address and port do I appear on?" The browser sends a small request to a STUN server, which replies with the address it observed. That answer becomes a server-reflexive ICE candidate. STUN servers do almost nothing - a few tiny UDP packets per call - so running one is cheap, and public STUN servers exist (Google operates well-known ones used by many demos). When both sides sit behind ordinary NATs, STUN plus ICE is often enough for a direct peer-to-peer connection.
TURN: relaying when direct fails
Some networks block direct connections outright: symmetric NATs, strict corporate firewalls, some carrier networks. In those cases the only path is through a relay. TURN (Traversal Using Relays around NAT, RFC 8656) provides that relay: both browsers send their media to the TURN server, which forwards it on. Because every relayed call consumes the server's bandwidth in both directions for the whole call, TURN is the expensive part of WebRTC infrastructure - and why there is no meaningful "free public TURN". Plenty of calls never need a relay, but without a TURN server the ones that do simply fail - so production calling needs one.
Your options in practice
- Public STUN, no TURN: fine for demos and prototypes; a slice of real users will fail to connect.
- Self-hosted STUN + TURN: the open-source coturn server is the standard choice; you pay for the VM and, above all, its bandwidth. Sizing follows your relayed-call minutes.
- Managed TURN or full video API: providers sell relay capacity as a service, metered by traffic or participant-minutes; the full video APIs covered in our build-vs-buy guide bundle signaling and SFU infrastructure on top.
FAQ
Do I need STUN and TURN for every call?
STUN, almost always - it is how browsers learn their public candidates. TURN is only the fallback: ICE tries direct candidates first and uses the relay only when nothing direct works. But the share of calls that need TURN is never zero, so a production service without one has a built-in failure rate.
Are public STUN servers free to use?
Yes, discovery traffic is tiny and public servers are common. They are best-effort shared infrastructure, though: for a production app, running your own STUN alongside your TURN server costs little and removes a dependency you do not control.
Can I use someone else's TURN server?
Not practically. Relaying media is real, continuous bandwidth cost, so open TURN relays are not a thing; credentials exist precisely to meter that cost. Either operate your own (coturn is the usual open-source option) or buy relay capacity from a provider.
Can a TURN server listen to my calls?
TURN itself provides no content confidentiality: RFC 8656 leaves that to the application protocol. WebRTC supplies it - RFC 8827 requires every media channel to use SRTP with DTLS-SRTP keying and forbids unencrypted RTP - so the relay forwards encrypted media without the keys. What the relay does see is transport metadata: the peer addresses it relays for, when allocations happen, and how much data flows.
Sources
- MDN Web Docs, WebRTC connectivity (signaling, SDP, ICE candidates): https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Connectivity
- MDN Web Docs, WebRTC API: https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API
- RFC 8445, Interactive Connectivity Establishment (ICE): https://www.rfc-editor.org/rfc/rfc8445
- RFC 8489, Session Traversal Utilities for NAT (STUN): https://www.rfc-editor.org/rfc/rfc8489
- RFC 8656, Traversal Using Relays around NAT (TURN): https://www.rfc-editor.org/rfc/rfc8656
- RFC 8827, WebRTC Security Architecture (media encryption requirements): https://www.rfc-editor.org/rfc/rfc8827
- coturn, open-source TURN/STUN server: https://github.com/coturn/coturn
Drafted with AI assistance from these sources.