🔹 What is Network Address Translation (NAT)?
Network Address Translation (NAT) is a method used in networking to map private IP addresses inside a local network to a public IP address before sending data to the internet. It allows multiple devices on a local network to share a single public IP address.
🔹 Why NAT is Needed?
The main reason for NAT is the shortage of IPv4 addresses. There are not enough IPv4 addresses (like 192.168.0.1
) to assign globally, so we use private IPs inside networks and only one public IP for internet communication.
🔹 Types of IP Addresses
Type | Example | Scope |
---|---|---|
Private IP | 192.168.0.2 | Local Network |
Public IP | 203.0.113.10 | Internet |
🔹 How NAT Works – Step by Step
- A device in a private network (like
192.168.1.2
) wants to access the internet. - It sends the data to the router.
- The router replaces the private IP address with its public IP address.
- The router sends the data to the internet.
- When the response comes back, the router maps the public IP back to the private IP and sends it to the right device.
🔹 Types of NAT
Type | Description |
---|---|
Static NAT | One-to-One mapping between private and public IP. Used when a device needs to be always accessible (e.g., servers). |
Dynamic NAT | Many-to-Many mapping. A pool of public IPs is used, assigned dynamically to internal devices. |
PAT (Port Address Translation) or NAT Overload | Many-to-One mapping. All devices share a single public IP using different ports. This is the most common type of NAT. |
🔹 Example of NAT
Scenario:
- Internal Computer IP:
192.168.1.10
- Router’s Public IP:
203.0.113.5
- Port:
54321
assigned by router for tracking
Steps:
192.168.1.10
sends request towww.example.com
.- NAT changes source IP:
From: 192.168.1.10:5678
To: 203.0.113.5:54321
- The server replies to
203.0.113.5:54321
. - Router looks up mapping and forwards reply back to
192.168.1.10:5678
.
🔹 Diagram of NAT (PAT Style):
+------------+ +-------------+ +--------------------+
| PC A |------>| |------>| |
|192.168.1.10| | NAT Router| | Internet |
+------------+ |203.0.113.5 |<------| (e.g. Web Server) |
+-------------+ +--------------------+
🔹 Advantages of NAT
- Conserves public IP addresses
- Adds security by hiding internal IPs
- Allows multiple devices to access the internet using a single IP
🔹 Disadvantages of NAT
- May interfere with some applications (VoIP, P2P)
- Can add slight delay due to address translation
- Difficult to host internal servers (unless port forwarding is used)
🔹 Real Life Use Case
If you’re using Wi-Fi at home:
- Your laptop, phone, and TV have private IPs like
192.168.0.X
- Your ISP gives your router one public IP
- NAT allows all devices to access the internet using that one IP.