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

I understand that the subnet mask when combined with an IP is used to define the range of IPs that the router is responsible for routing. e.g. a router with subnet, will route to through its LAN port, all other will be forwarded to its WAN/gateway. (sanity check please)

What is the subnet mask (as shown on ipconfig /all) for a client computer used for? Does the subnet mask of the client have to be same as its gateway?

share|improve this question
up vote 3 down vote accepted

It's for precisely the same reason. The client computer needs to know which destinations it should try to reach directly and which it should try to reach through a router.

For IP addresses inside the subnet, the client computer uses ARP to locate the Ethernet hardware address of the destination machine's interface in the subnet. For IP addresses outside the subnet, Ethernet traffic is sent to the router's Ethernet hardware address in the subnet.

While a typical SoHo "WiFi router" has layer 2 (bridging, switching) and layer 3 (routing, NAT) functions combined, the client computer still acts precisely the same as it would if the switching and routing functions on the network were entirely separate like they typically used to be.

share|improve this answer
+1 for explaining what the subnet mask is used for, not just what it is. – prateek61 Apr 13 '13 at 10:54

To answer your first question yes the subnet mask is used to quickly determine where to route traffic (either local or to forward on).

All computers on the same subnet need to have the same subnet mask. This allows them to construct packets with the subnet mask specified.

Better explanation here:

Every IP address is divided into a network ID portion and a client ID portion. On the internet, routers look at the 3 binary digits on the left of the destination IP address to determine an IP address's "class." (An IP address is 32 binary digits.) The router then uses the class to determine how many binary digits make up the network portion of the IP address: 8 for class A's, 16 for class B's, and 24 for class C's. It uses a database in the router (called the routing table) to decide where to send it next.

Once a packet is passed by an Internet router to its destination network, it is either on the LAN segment of the destination computer, or the LAN has been subdivided by the LAN administrators. If its on the destination computer's LAN segment, the destination computer uses it and it goes no further. If a network administrator has divided the LAN, and the destination computer is not on the current LAN segment, the corporate routers (not Internet routers) must now determine how to forward the packet to the correct LAN segment. These corporate routers are what sub-divide the LAN.

The "network" portion of the IP address doesn't help the corporate router, because every IP address in the subdivided LAN has the same network ID. This is what the subnet mask is for. Here's a key point: A subnet mask is used both when a LAN is subdivided, and when it is not subdivided (a single LAN segment).

share|improve this answer

The subnet mask is used to "group together" network interfaces [more or less = computers ] which can speak directly to each other.

A gateway CAN NOT be the same as a subnet, but a gateway (with a few technical exceptions) needs to be in the same subnet as the machines connected to it.

A subnet mask represents a number of bits, which make up a range. Using some (for a computer at least) simple binary maths, it can easily work out if another address is in the same subnet/physical network. Subnets are (generally) a group of numbers which are a power of 2.

By way of example - Take the common subnet Each "." represents a part of the IP addreess. So if a computer has an IP address of, and a netmask of, it means that any machine which has an IP address of 192.168.1.X is locally attached and does not need to go through a router.

It is possible, and indeed on non-home connections very common to have different subnets, for example, many point-to-point connections will have a subnet of, which provides 4 IP addresses, of which only 2 are actually usable for machines - 1 for each end of the link. Similarly, because IP space is at a premium, a block of 256 IP's [called a class C] can be divided up on subnet boundaries, for example into 16 sets of 16 IP's, with a netmask of, and then given to different networks.

It is not quite correct to say that all IP addresses not in a subnet will be routed out the [default] gateway - in fact, a network does not even need to have a default gateway, and will still work with limited functionality.

There are 2 parts to understanding this -

  1. If an address is not in the same subnet as the originating PC (as defined by the netmask), a "next hop" can be specified. Thus if I want to see different parts of a network/the internet through different computers I can specify different "next hops" for various IP addresses. In addition, instead of specifying IP addresses, I can specify ranges of IP addresses using netmasks.

  2. A default route is nothing more then a slightly special case of a network with a "next hop" of the router - the special case being the netmask, which means all addresses. (Where an IP address is matched by multiple routes, the one with the smallest netmask (ie largest number for the netmask) that matches the route is used.

share|improve this answer

You must log in to answer this question.

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