Subnets and netmasks are both important practical issues in internet routing, and it can sometimes be confusing to understand how they fit together and what they are supposed to do.

The best way to start is to explain what question subnets and netmasks answer. They basically answer the question: Do I just throw this packet of bytes on the wire (typically an Ethernet cable these days) and hope that the destination computer is going to pick it up, or, do I ask the special machine, called the gateway, that knows how to send it to the outside world, to take care of it?

Another way to put it: Let's say we want to connect to another machine. Then I have to ask how to get pieces of information to the machine - this is called routing. Typically on Ethernet, there are two ways to get the information to another machine. If it's on the same piece of wire, and this is what a subnet really is, then we just connect to it directly, if it's not, we go through a gateway.

The question is then: How do I decide whether something's on the same piece of ethernet as me or not?

Answer: If the ip address looks similar to mine, then it must be on the same subnet. Otherwise, go through the gateway.

Question: But what does "similar" mean?

Answer: This is where the subnet mask comes in. Say the netmask is This is decimal for the binary 11111111111111111111111100000000. If the IP addresses match (ie. are equal) on all the bits where the mask is one, it is assumed to be on the same subnet. basically means: The first three numbers of the IP address have to be the same.

Example: wants to talk to The subnet mask is, so since the first three numbers of the IP address match, it just connects directly through ethernet to (in fact it uses ARP to work out how to do this).

But say wants to talk to Then it says "oh, that IP address is not on the same subnet, I'll have to go through the gateway." Let's say the gateway is Then sends the packet to expecting that will pass it on to

Of course the gateway has to be on the same subnet as the machine that's sending the packets.

Log in or register to write something here or to contact authors.