NAT Traversal: How Calls and Games Punch Through Routers
See how two devices behind home routers find a direct path using STUN, hole punching and ICE, and when a relay has to take over.
Key takeaways
- A router normally lets in only packets that match a conversation started from inside.
- A STUN server tells a device the public address and port its packets appear to come from.
- Hole punching has both sides send outward so each router creates a mapping the other can use.
- When direct paths fail, a TURN relay forwards the traffic at the cost of delay and server capacity.
- ICE gathers all the candidate paths, tests them and picks one that works.
NAT traversal is the set of techniques that lets two devices, each hidden behind its own router, exchange data with one another. Typically both first talk to a server on the public internet, learn how they appear from outside, then try sending to each other at the same time. If the routers allow it, traffic flows directly. If not, a relay carries it.
Video calls, voice chat, many games, file sharing between friends and mesh VPNs all rely on some version of this. It explains why some calls feel crisp and others laggy on the same connection.
The problem
Network address translation rewrites your private address into your router's public one and remembers the mapping. Replies fit the mapping and get through. A stranger's first packet doesn't, so it is dropped. Firewalls behave similarly.
When you load a website this is fine, because the server has a public address and you make the first move. In a call between two homes, neither side has an address the other can reach, and neither router expects the other.
Learning your outside appearance: STUN
STUN (Session Traversal Utilities for NAT, RFC 8489) is a small protocol. Your device sends a request to a STUN server, and the server replies with the source address and port it saw. That is the public side of your router's mapping, something your device otherwise has no way of knowing.
STUN servers do little work, since they carry none of the call itself. The usual port is 3478.
Punching the hole
Now each side needs the other's details. A signaling server, run by the calling or game service, passes them along over ordinary connections both devices made outward.
Each router sees its own device sending to the other's public address, so it records a mapping. When the other side's packet arrives from that address, it looks like a reply and is let in. The early packets that arrive too soon are simply lost, and retries fill the gap.
UDP is favored for this. It has no handshake to coordinate and suits live media, as explained in TCP vs. UDP. TCP versions exist but succeed less reliably.
Why some routers resist
Routers differ in how they build mappings, and the behavior matters. RFC 4787 sets out the vocabulary for UDP.
- With endpoint-independent mapping, your device gets the same public port no matter whom it sends to. The port STUN reported is the one a peer can use.
- With endpoint-dependent mapping, often called symmetric NAT, a new destination gets a new public port. What STUN saw doesn't apply to the peer.
Routers also differ in filtering: some accept packets from anyone once a mapping exists, others only from addresses the inside device has already contacted.
Two forgiving routers connect easily. One strict and one forgiving often still manage. Two endpoint-dependent ones usually fail to connect directly. Game consoles summarize this with labels such as open, moderate or strict, though names vary; NAT types on consoles translates them.
The fallback: TURN relays
TURN (Traversal Using Relays around NAT, RFC 8656) allocates an address on a relay server. Both sides can reach it with outbound connections, and it forwards data between them.
It works in nearly every case, including restrictive office networks, especially when offered over TCP or TLS. The costs are real: the path is longer, which adds delay, and the operator pays for all the traffic passing through. Services therefore use relays only when they must, or deliberately when they want to hide users' addresses from one another.
A relay need not be able to read what it carries. In WebRTC, media is encrypted between the endpoints, and a TURN server just moves the encrypted packets. Group calls often pass through a media server instead, which is a separate design with its own encryption properties.
ICE ties it together
ICE (Interactive Connectivity Establishment, RFC 8445) is the procedure that uses these tools in order. Each device collects candidates, which are possible addresses where it might be reached.
If both devices sit on the same network, the local candidates win and traffic never leaves the building. If your network changes mid-call, such as moving from Wi-Fi to mobile data, the process can run again.
IPv6 and other shortcuts
With IPv6, devices usually have globally unique addresses, so there is no translation to defeat. A firewall still blocks unsolicited packets, which the same simultaneous sending can get past. ICE includes IPv6 candidates and often finds the most direct route that way.
Routers that support UPnP or related port mapping protocols let an application simply ask for an opening. It is effective, with security trade-offs, and does nothing against a provider's carrier-grade NAT.
Privacy side of direct connections
A direct path means the person on the other end can learn your public IP address. For a call with a friend that is rarely a concern. In public game lobbies or calls with strangers it can be, since an address hints at your rough location and can be targeted with floods. Many apps offer a setting to relay calls through their servers, trading a little delay for privacy. See what your IP address reveals.
When calls or games struggle
Work through the likely causes:
- Check the obvious. Run a speed and latency test, and try a wired connection.
- Look for double NAT. Two routers in series make direct connections harder. Put one in bridge or access point mode.
- Check for provider NAT. Your router's internet address will give it away.
- Consider the network you're on. Hotels, schools and offices often block UDP. A service that falls back to TLS relays will connect but may feel slower. Ask the network's administrator, and respect their policy.
- Disable "SIP ALG" or similar helpers if a voice service's support team recommends it, since they sometimes rewrite packets badly.
- Try a forward only if documented. Some games publish required ports. Add just those, to one device, and remove them if they don't help.
Keeping the path open
A hole through a router is temporary. The mapping lives only while the router's timer keeps being refreshed, and UDP timers can be short. Applications therefore send small packets at regular intervals during quiet moments, such as when everyone is muted or a game is paused.
ICE also keeps confirming that the other side still wants to receive. If the checks stop getting answers, the application knows the path has died and can try to restart. That is what is happening during the brief "reconnecting" notice in a call.
Several things can end a mapping early: a router reboot, a change of public address, a switch between networks, a laptop going to sleep, or a router with a very full connection table. If calls reliably drop after a fixed interval, suspect an idle or maximum lifetime on some device in the path, often a firewall on a business network.
Mesh VPNs and remote access
Tools that connect your own devices across the internet use the same recipe. A coordination service introduces the devices and distributes keys. The devices attempt hole punching, and fall back to the provider's relays when that fails. The data is encrypted between your devices in well-designed products.
This is why such tools often work behind carrier-grade NAT without any port forwarding. Check the product's documentation on three points: who can add devices to your network, whether relays can read traffic, and what the coordination service records. Protect the account that controls it with strong sign-in methods, since whoever controls it may be able to join your private network.
What traversal is not
These methods help two parties who both want to talk. Each side actively sends toward the other, after exchanging details through a service they both chose. They don't let an outsider reach a device that isn't participating.
Still, the technique shows that a router's translation is a poor boundary on its own. Any software you run inside your network can establish outward paths that carry traffic back. Control over what you install, separate networks for devices you don't trust and a properly configured firewall matter more than the translation itself.
Organizations that need to restrict peer connections do it with explicit policy: filtering outbound UDP, allowing only approved services and their relays, and telling staff why. The trade-off is call quality, since forcing media over TCP through a relay or proxy adds delay and stalls when packets are lost. A sensible policy usually allows the media ports for the meeting tools the organization has chosen.
Notes for developers
If you build a real-time feature, don't assume direct connections will work for everyone. Provide a TURN service, issue short-lived credentials so strangers can't use your relay, and offer it over UDP, TCP and TLS. Measure how often sessions end up relayed, because that figure drives your costs and your users' experience, and it depends heavily on the networks your audience uses. Test from a mobile network and from a restrictive corporate network, not just from two laptops on your desk, which will nearly always find each other locally and hide every problem described here.