I'm learning the TCP and UDP protocols and I have a question about UDP.

I used C to develop a UDP server and a UDP client in my LAN and it works as expected. The server and the client could communicate each other. However, I don't know if UDP could still work as expected ifthere are many clients behind a same NAT.

As my understanding, NAT can maintain all of the status of TCPs, and each client has its own connection status. So when the NAT receives a TCP packet from the server, it knows to which client it should send the TCP packet.

But I don't know what would happen for UDP since UDP is stateless... In other words, when NAT receives a UDP packet, can it know to which client it should send the UDP packet?

  • Both TCP and UDP use port numbers, so I see no problem for NAT to maintain a mapping for both of these protocols. NAT is not concerened with how the protocol behaves.
    – manish ma
    Commented Apr 23, 2023 at 11:29
  • FYI, the Client/Server concept is an application layer [above the transport layer is off-topic here] concept. Neither TCP nor UDP know anything about clients or servers. TCP creates connections between two TCP peers (not clients or servers), and either peer can send and receive or shut down the connection; neither side has any control over the other. UDP, being stateless, simply sends datagrams into the void, and it does not care that the datagram is even received, so it knows nothing of clients or servers.
    – Ron Maupin
    Commented Apr 23, 2023 at 15:24
  • 1
    I believe you are referring to the NAPT variant of NAT (see RFC 3022, Traditional IP Network Address Translator (Traditional NAT)). NAT maintains a translation table for each protocol. Unfortunately, NAPT only supports TCP, UDP, and ICMP, and that prevents the use of other existing transport protocols and stifles innovation of future protocols. That is the reason for IPv6 that restores the IP end-to-end paradigm that is broken by NAPT. This answer explains the problems with NAPT.
    – Ron Maupin
    Commented Apr 23, 2023 at 15:35

1 Answer 1


Does UDP work with NAT?

The correct question would be Can NAT work with UDP? Yes, most NAT routers support UDP.

Since UDP uses port numbers in the same way that TCP does, mapping a translation to a tracked NAT session is straightforward. A complication is the fact that UDP is stateless - there's no connection building and breakup. Source NAT needs to be stateful, so a reply can find its way back to the original source that made the request. A NAT router has to rely solely on an arbitrary timeout or session aging to track a 'UDP session' that doesn't really exist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.