Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I want to get to some external network, lets say from my class C network connected PC, which of these two scenarios will actually happen?

  1. My PC's OS (NIC) knows I want to access address out of my internal network, and sends packets to the default gateway directly.


  2. My PC handles that request like any other, sending it to my switch, which doesent know the destination address, so it resends them to all connected devices. Since of of them is router, he than resends the packets outside.

Or I am completely mistaken?

share|improve this question
1 is a good description of what happens at the IP level. 2 is a pretty good description of what happens at the Ethernet level, except the switch probably does know the router's hardware address and so doesn't have to send them to all connected devices. The packet your PC sends has an IP destination address of and an Ethernet hardware destination address of your router's Ethernet hardware address. – David Schwartz Aug 2 '12 at 21:14
up vote 4 down vote accepted

Both, in a way. On an IP level, your computer knows that it's going to an external address, and sends it directly to the router because it knows that the router is acting as a gateway for anything not on the local subnetwork (which it determines by using the subnet mask).

However, switches and hubs operate one level below IP, the ethernet level (specifically, the Data link layer, with IEEE 802 ethernet for wired ethernet and WiFi devices). It doesn't know what an IP address is, or what they mean. However, it does understand something called a MAC address. When your computer sends out a packet, it also includes the MAC address of the next device on the network which should be handling that packet. In this case, the router.

When a hub receives a packet, it does exactly what you described - it duplicates the packet and sends it out over all lines in hope of getting it to its destination. Any devices that receive the packet but are not the recipient simply discard it.

A switch, on the other hand, is a bit smarter. It actually keeps a table of MAC addresses and associates them with each port, based on incoming traffic. That way, when it has to send a packet to a specific MAC address, it knows which port it needs to send out on. This helps to reduce network congestion.

share|improve this answer

Assuming that the netmask on the nic is, the request would be sent to the default gateway. If the netmask were set such that the required network was in range, the PC would handle the request.

share|improve this answer

Your PC uses its subnet mask to determine if the destination IPv4 address is off-subnet. If it is, then your PC plans to address the Ethernet-layer headers to the Ethernet (MAC) address of your router. If it doesn't know the MAC address of your router, it uses ARP to find out.

So at the Ethernet layer, the packet is addressed to your router, but at the IP layer, the packet is still addressed to the original destination IP address.

share|improve this answer

The operating system IP stack works out where to send it as follows.

First you need to understand some basic addressing. This won't be very thorough but hopefully good enough for you to make some sense of it.

For IPv4 you have a network address and a host address. So for an address of with subnet mask you have the first 3 bytes used to address the network. i.e. the 255.255.255 part. The 0 bit at the end represents the host part of the address. Actually you can also have subnet masks of But, to keep it simple I'll just say that these numbers are used to determine how the 4 bytes or octets that make up the address are split between network and hosts.

In the case of a subnet mask, the 0 part at the end means we can have 255 hosts.

Now for the routing part.

If we're sending a packet to then the IP stack will know it's a local address and just send it directly addressed to because the first 3 octets match my local network. However, if I was to send a packet to then it would be sent to whatever is defined as the default route in my operating system. The default route is a router that will handle the "I want to send a packet to for me". So anything that isn't local that doesn't begin with 192.168.1 will be sent to the default router. How the router knows how to reach is what routing protocols are all about. But you simply asked how the packets get "off network" so I hope this answer explains it well enough for you.

share|improve this answer

2) is easily answered:
Your PC does not send its packets to a switch since it does not know it is there.

Your PC (or rather, your network stack) has a routing table. Based on the information in that table it can:

  • Loop information back to itself (own IP, or local host)
  • Address it to a NIC on a local network (known via its own IP and own subnet)
  • Know it is not local and send it via the someone who hopefully knowns where it has to go (aka the default gateway).

I am trying to come up with a much longer and detailed answer, and in a week or so I will probably post something about networking on my homepage. Meanwhile I like to direct you to a very long and extensive answer on this sites sister site: serverfault how-does-subnetting-work ?

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .