Making a few assumptions
- You are talking about an Internet gateway router
- You are using RFC1918 addresses on the inside
- You have a single IP assigned to you from your ISP
With all of this being the case, Your gateway router is going to be performing PAT [Port Address Translation]
As a request goes through your gateway from a client it has a few important pieces of information. Source IP, source port, destination IP, destination port, all of which Your router will keep track of all of this in a table [Translation table].
So lets look at an example. In this example your IP that your router has from your ISP is 184.108.40.206
SRC IP = 10.10.10.1 SRC Port = TCP/12345 ==> DST IP 220.127.116.11 DST Port TCP/80
As this travels through the router it will translate the source info.
SRC IP = 18.104.22.168 SRC Port = TCP/54321 ==> DST IP 22.214.171.124 DST Port TCP/80
When 126.96.36.199 responds it will respond like this.
SRC IP 188.8.131.52 SRC Port TCP/80 ==> DST IP = 184.108.40.206 DST Port = TCP/54321
Your router will look at its translation table and discover that TCP/54321 was the source port of a connection that initially came from 10.10.10.1 with an original source port of TCP/12345.
The router will the rewrite the packet/segment and send it back to the inside host.