I realized that all of my devices have the same public IP address (I had knowledge about the concept of public and private IP addresses, but I thought this was unique in both cases), so what I do not understand very well is how the router will know which device corresponds a response entering my LAN?

Here's an example, but it doesn't tell me how the router handle this:

enter image description here

I think I read somewhere that it was using ports, but what if, for example, my brother and I are doing SSH, from what I understand, the router would receive answers to the same IP address (because the public IP address is shared), and to the same port (22 for SSH), then how does the router know to which device to give the corresponding answers?

1 Answer 1


Don't confuse the well-know ports used in the destination with the source port your PC uses. Most of the time, your PC will use a random, ephemeral port when initiating communication. For instance, when you browse a web page, your PC will use port 80 (well-know port for HTTP) as the destination port, but it will choose its own port (e.g. 53277) for the source port.

A router using NAT will maintain a NAT table. When you initiate a connection from inside the NAT (private address) the NAT table will have an entry with the source IP address, source port (this is usually a random, ephemeral port), destination IP address, destination IP port, and the random port number your router chooses to use to replace the source port.

When traffic comes back to the public IP address and the random port the NAT assigned, the NAT will reverse the process, replacing the public destination address and port with the ones from the NAT table to send back to your inside host.


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.