What is Network Address Translation (NAT) with Example

What is Network Address Translation (NAT) with Example


🔹 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

TypeExampleScope
Private IP192.168.0.2Local Network
Public IP203.0.113.10Internet

🔹 How NAT Works – Step by Step

  1. A device in a private network (like 192.168.1.2) wants to access the internet.
  2. It sends the data to the router.
  3. The router replaces the private IP address with its public IP address.
  4. The router sends the data to the internet.
  5. 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

TypeDescription
Static NATOne-to-One mapping between private and public IP. Used when a device needs to be always accessible (e.g., servers).
Dynamic NATMany-to-Many mapping. A pool of public IPs is used, assigned dynamically to internal devices.
PAT (Port Address Translation) or NAT OverloadMany-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:

  1. 192.168.1.10 sends request to www.example.com.
  2. NAT changes source IP:
   From: 192.168.1.10:5678  
   To:   203.0.113.5:54321
  1. The server replies to 203.0.113.5:54321.
  2. 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.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *