0
0
Computer Networksknowledge~10 mins

NAT (Network Address Translation) in Computer Networks - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - NAT (Network Address Translation)
Device sends packet with private IP
Packet reaches NAT router
Router replaces private IP with public IP
Packet sent to internet with public IP
Response from internet arrives at router
Router replaces public IP with private IP
Packet delivered to correct device inside network
NAT changes private IP addresses to a public IP when sending data out, and reverses this for incoming data, allowing multiple devices to share one public IP.
Execution Sample
Computer Networks
Device IP: 192.168.1.2
Router public IP: 203.0.113.5
Send packet to internet
Router replaces 192.168.1.2 with 203.0.113.5
Internet replies to 203.0.113.5
Router replaces 203.0.113.5 with 192.168.1.2
Packet delivered to device
Shows how a device's private IP is translated to a public IP by the router and back again for incoming packets.
Analysis Table
StepPacket Source IPPacket Destination IPRouter ActionResulting Packet IPs
1192.168.1.2198.51.100.10None (packet sent from device)Src: 192.168.1.2, Dst: 198.51.100.10
2192.168.1.2198.51.100.10Replace Src IP with public IP 203.0.113.5Src: 203.0.113.5, Dst: 198.51.100.10
3203.0.113.5198.51.100.10Packet sent to internetSrc: 203.0.113.5, Dst: 198.51.100.10
4198.51.100.10203.0.113.5Packet arrives at router from internetSrc: 198.51.100.10, Dst: 203.0.113.5
5198.51.100.10203.0.113.5Replace Dst IP with private IP 192.168.1.2Src: 198.51.100.10, Dst: 192.168.1.2
6198.51.100.10192.168.1.2Packet delivered to deviceSrc: 198.51.100.10, Dst: 192.168.1.2
7---End of translation cycle
💡 Packet delivered to device; NAT translation complete
State Tracker
VariableStartAfter Step 2After Step 5Final
Source IP192.168.1.2203.0.113.5198.51.100.10 (response source)198.51.100.10
Destination IP198.51.100.10198.51.100.10192.168.1.2192.168.1.2
Key Insights - 3 Insights
Why does the router change the source IP address before sending the packet to the internet?
Because private IPs like 192.168.x.x are not valid on the internet, the router replaces it with its public IP (203.0.113.5) so the packet can be routed properly, as shown in step 2 of the execution_table.
How does the router know which private IP to replace the public IP with when a response comes back?
The router keeps a translation table mapping the public IP and port to the private IP and port. When the response arrives (step 4), it uses this table to replace the destination IP back to the correct private IP (step 5).
What happens if two devices try to send packets at the same time using NAT?
The router assigns different port numbers to each connection along with the public IP, allowing it to track multiple devices simultaneously. This is part of how NAT manages multiple translations.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What is the source IP after the router action?
A198.51.100.10
B203.0.113.5
C192.168.1.2
DUnknown
💡 Hint
Check the 'Resulting Packet IPs' column at step 2 in the execution_table.
At which step does the router replace the destination IP back to the private IP?
AStep 5
BStep 3
CStep 1
DStep 6
💡 Hint
Look for the router action that mentions replacing the destination IP in the execution_table.
If the device IP changed to 192.168.1.3, how would the source IP in the packet after step 2 change?
AIt would change to 192.168.1.3
BIt would change to a new public IP
CIt would stay 203.0.113.5
DIt would become 198.51.100.10
💡 Hint
Remember the router replaces the private IP with its own public IP, which does not depend on the device's private IP.
Concept Snapshot
NAT translates private IP addresses to a public IP for internet communication.
Router replaces source IP of outgoing packets with its public IP.
Incoming packets have destination IP replaced back to private IP.
Allows multiple devices to share one public IP.
Uses a translation table to track connections.
Full Transcript
Network Address Translation (NAT) works by changing the private IP address of a device inside a local network to a public IP address when sending data to the internet. When a device sends a packet, it has a private IP like 192.168.1.2. The NAT router replaces this private IP with its own public IP, for example 203.0.113.5, so the packet can travel on the internet. When the response comes back to the router's public IP, the router changes the destination IP back to the device's private IP and delivers the packet inside the network. This process allows many devices to share a single public IP address. The router keeps track of these translations in a table to know which private IP corresponds to each public IP and port combination. This explanation is shown step-by-step in the execution table and variable tracker, helping beginners visualize how NAT works.