Discover how Edgegap works

Discover how Edgegap works

NAT Traversal

NAT traversal is the set of techniques that let two players behind home routers connect directly to each other. Network address translation hides private addresses behind one public one, which breaks inbound connections by default. Techniques such as hole punching, helped by a STUN server, work around it; when they fail, traffic usually falls back to a relay.

Also called

NAT punch-through, NAT punchthrough, hole punching

By

By

By

Philip Coté

Philip Coté

Philip Coté

,

CTO

CTO

CTO

Published

Published

Published

What Is NAT, and When Does a Game Need NAT Traversal?

Network address translation (NAT) lets many devices share one public internet address. A home router, and often the internet provider too, rewrites the address and port on each outgoing packet and keeps a table, so replies find their way back to the right device. Those entries are temporary. Michal Buras of Highwire Games compared the public port to a flat number in a shared building: “Every time you order a pizza, you are given a unique flat number, and the number changes over time” (Live Service Game Summit, 2024). Traffic that matches no entry in that table is usually dropped. That is why a player’s machine is easy to reach out from, and hard to reach into.

So whether a game needs NAT traversal depends on which machine has to accept a connection:

  • Every player connects out: to a hosted server or a relay with a public address. Each router sees an outgoing connection and lets the replies in, so this usually needs no traversal. The server side of that setup is covered in port mapping.

  • A player’s machine accepts connections: a listen server host, a peer-to-peer mesh, or any host-client session. Other players have to reach a device behind someone else’s router, and that is where NAT traversal comes in.

  • Two browsers connect to each other: a web page can’t open a listening socket the way a native game can, so browser-to-browser play uses WebRTC, which runs a traversal procedure called ICE (RFC 8445) and can fall back to a relay if the game provides one.

So the network design decides how much traversal a game needs, before any technique is chosen. The answer gets harder as more players join from mobile networks (Part 3).

Article's key insights

Short answer: A relay gets packets through NAT and hides player IP addresses, but it doesn’t make a peer-to-peer game secure. The host’s machine still owns the match: it can alter results, plays with zero latency and ends the session by leaving. The game logic also ships in every player’s build, where anyone can decompile and modify it, and lobby data can still leak, as Michal Buras showed at Live Service Game Summit 2024.

  • Relays solve connectivity: they get packets through NAT and firewalls and hide player IP addresses, but they run no game logic.

  • The host still owns the match: behind a relay, one player's machine keeps authority, a zero-latency advantage and the power to end the session by leaving.

  • Safer than raw P2P, not safe: a relay blocks IP-based attacks between players, but it can't stop a host from altering the match.

  • Free relays come with someone else's routing: a 2026 Steam Networking regression pushed players in several regions onto distant relays for about three months.

  • Dedicated servers come in relay-sized versions: a relay-style or multi-room server keeps authority off player machines at a cost close to a relay's.

How Does NAT Traversal Work?

Player-hosted games usually gather several routes and use the best one that works, roughly in this order of preference:

  1. Ask the router: protocols such as UPnP, NAT-PMP and PCP let the game ask a NAT to open a port for it (the FAQ below covers when to rely on them).

  2. Punch through: both players learn their public address from a STUN server, swap it through a rendezvous service such as the lobby or matchmaker, and send at about the same time. The peer-to-peer page outlines the steps and why they fail for some players.

  3. Relay: when no direct path opens, both players connect out to a server that forwards their traffic. It connects nearly every pair, and the route then runs through that server, which is where its location matters.

Diagram comparing two NATs drawn as buildings. On the left, Player A keeps flat 51000 for every call, so Player B’s call back to 51000 reaches A. On the right, A gets a new flat, 51007, for the call to B, so B’s call back to 51000 finds nobody and a relay is needed.

How often does punching work? In a large measurement campaign on the IPFS peer-to-peer network (over 4.4 million attempts from more than 85,000 networks, December 2022 to January 2023), about 70% of hole punches that reached the punching stage succeeded, and 97.6% of the successes came on the first attempt. With that protocol’s timing, TCP and QUIC succeeded at about the same rate (Trautwein et al., arXiv preprint, October 2025). It isn’t a game network, and the authors note their volunteers may be more technical than typical users, so it is a rough baseline rather than a forecast for a game.

What Do NAT Types Mean for a Multiplayer Game?

Consoles summarize their connection test as a label: Open, Moderate or Strict on Xbox, Type 1 to 3 on PlayStation, Type A, B, C, D or F on Nintendo Switch. The labels describe outcomes. The behaviour behind them is described by two properties in RFC 4787 (January 2007):

  • Mapping: whether the NAT keeps the same public port for a socket wherever it sends (endpoint-independent mapping), or opens a new public port for each destination (address-dependent or address-and-port-dependent mapping). The older term “symmetric NAT” covers these, most strictly the address-and-port-dependent kind.

  • Filtering: which outside senders may reach that public port: anyone, only addresses the player has already sent to, or only those exact addresses and ports.

Mapping matters most for punching, because the address a player learned from a STUN server only works for the other player if the NAT reuses it for that destination too:

NAT behaviour (RFC 4787)

Hole punching

Rough console equivalent

Endpoint-independent mapping and filtering

Usually works

Open, Type A

Endpoint-independent mapping, address-dependent filtering

Usually works when both sides send

Moderate, Type B

Address-dependent or address-and-port-dependent mapping (“symmetric”)

Often fails, especially when both players have one

Strict, Type C or D

Platforms don’t publish an exact mapping, so treat the last column as approximate. RFC 4787, a best current practice, says a NAT must use endpoint-independent mapping, but not every router or provider network does. Pairs matter too: as Nintendo puts it, “both your NAT type and the NAT type any player you are attempting to connect with can affect the connection process” (Nintendo Support). Two players behind strict NATs often can’t connect directly and need a relay.

Mobile networks are the hardest case: carriers usually put phones behind their own NAT, shared with many other subscribers. A 2014 to 2016 study found carrier-grade NAT in over 92% of cellular networks, against 13% to 18% of other networks, and 40% of the cellular NATs it could test were symmetric (Richter et al., IMC 2016). In a 2022 test on three German carriers, all three used symmetric NAT, and even improved port-prediction methods connected a phone on one of them to a phone on another only 14% to 17.5% of the time (Keller et al., IEEE ICCE 2022). The studies are dated and regional, but they point the same way: two mobile players often can’t connect directly, which is why cross-platform games with mobile players tend to plan for a relay or a hosted server from the start.

Why Do Connections Drop After NAT Traversal?

A traversed path lasts only as long as the mappings at both ends. A NAT forgets a UDP mapping after a stretch with no traffic: RFC 4787 says the timer must not expire in less than two minutes for most ports and recommends five minutes or more, though some networks use shorter timers: the 2016 study above measured a median of 65 seconds on cellular carrier-grade NATs and 35 seconds on the others it tested. Three cases tend to break a working path:

  • Quiet periods: lobbies, loading screens and menus can send nothing for minutes. Many games send a small keepalive packet at an interval well inside the shortest timeout they expect.

  • Network changes: a phone moving from Wi-Fi to mobile data gets a new public address, and the old path no longer leads anywhere.

  • Host changes: after host migration, every player connects to a new host, which can mean a new traversal and, for some pairs, a relay.

A game can treat a lost path as something to recover from (traverse again, or fall back to a relay) rather than as a disconnect.

IPv6 removes address translation but not the need for traversal. Home gateways commonly forward inbound traffic only when it matches a flow started from inside, or an explicit exception (RFC 6092, January 2011), so two players on IPv6 can still need to punch through.

A word from our sponsor (ourselves!)

Most lag comes from distance, not from code. Edgegap's Edge Cloud is a distributed network with up to 615+ locations available on demand, so each match runs at the best available location for its players. Independent replays of live studio traffic measured a 58% drop in average round-trip time compared with public cloud.

Should Players Connect Directly or Through a Relay?

Each route trades something:

  • Latency: a direct path can be shorter, but not always. In the IPFS study above, where relays were volunteer nodes rather than servers placed for latency, half the peers saw their round-trip time fall to 70% of the relayed value or less after a punch, and about 10% saw it rise. A relay placed near both players narrows that gap, and one placed far away widens it.

  • Privacy: a direct connection shows each player the other’s IP address; a relay shows them only the relay’s.

  • Reliability: punching alone leaves some pairs unable to play together, more often when both are on mobile networks. Relaying connects them, so the relay’s location and capacity decide the experience.

Free platform relays, such as Steam’s and Epic Online Services’, can be fine for games played among friends. What they cost is control: the platform picks the route, the game takes on that platform’s SDK and accounts, and you can’t add code.

A relay you run keeps the player-hosted model and puts the route under your control. An extensible relay, such as LightNet for Unity netcodes, runs on a dedicated server you deploy on Edgegap, in the locations you choose. Every player connects out to it, so players need no hole punching or port forwarding, and no player sees another’s IP address. The game can stay on that relay, or add server logic over time until it becomes a multi-room game server.

Matches on hosted dedicated servers usually need no traversal on the player side: on Edgegap, each deployment gets a URL and public IP, with an external port for each internal one, and every player connects out to it (Edgegap docs).

Frequently Asked Questions

Why does a Nintendo Switch say “NAT traversal process has failed”?

What is the difference between NAT traversal and port forwarding?

Should a game rely on UPnP for NAT traversal?

Get your Game Online Easily & in Minutes

Start Integrating Now!

Get your Game Online Easily
& in Minutes