DEV Community

Aditya Madhavi
Aditya Madhavi

Posted on

From Youtube.com to Your Screen: How Routers Route Web Traffic

Your router acts as a local network’s traffic manager. It is responsible for sending data coming from the internet to the correct device in your home. Let's break down exactly how that happens.

1. The Request

When you search for youtube.com, your device sends a request out to the internet.

Because the internet communicates via IP addresses rather than domain names, this request is first resolved (via DNS) into an IP address.

2. NAT: Network Address Translation

Your router is aware of every device's Local IP address. However, the outside internet only sees one Public IP address for your entire house.

To manage this, the router uses NAT (Network Address Translation). It converts the local address of your device into its single public address before sending it out.

The NAT Table

To keep track of everything, the router maintains a NAT table. This table acts as a log containing:

  • The Requester Device (e.g., your laptop)
  • The Port used
  • The Response Destination

3. Receiving the Data

When the server (like YouTube) sends information back, it arrives at the router’s public IP address.

The router then:

  1. Consults the NAT table.
  2. Finds the original requester device by matching the IP and port.
  3. Forwards the data packets directly to your device.

In short: NAT keeps multiple devices reachable on the internet while presenting only a single public address to the outside world.

What do you think?

I wrote this because I remember being fascinated by how my router knew exactly which phone was requesting which video!

How do you explain networking basics to beginners? Do you have a favorite analogy for NAT? Let's discuss in the comments!

Top comments (0)