How a netmask works.


Preface

I've been using the internet for several years now. when I set up my first slip connection, I waded through mountains of cryptic information that I barely understood. One of the pieces of information that I really didn't understand at all was how a netmask worked. I just took it on fath that it made sense and used whatever numbers someone gave me. I finally found a reference that (almost) described how a netmask works. Armed with a near description, I sat down with a scientific calculator (I can't convert decimal to binary and back in my head) and figured out what the description meant. Since this has been a hole in my knowlege, and all the references I have seen don't spell it out, I decided to see if I can explain it and add to the pool of knowlege so you won't have to go through my process to discover this.


There are three pieces of information that interact with each other to resolve IP addressing. They are the netmask, the IP address, and the network address. As you may already know, when an IP packet is sent to a foreign address (off of this local network) the network address is all that is used for routing purposes until the packet reaches the target network. At this point the whole IP address is used to determine the specific machine on this network to send the packet to based on local routing tables or dynamic ARP (address resolution protocol, which we will not cover here). In order for a router to know the network address, it uses the IP address and the netmask.

Here's the relationship:

Your network address is your IP address masked (bitwise AND) with your netmask. This may mean nothing to you without the following clarification. Lets use an example.

If your netmask is: 255.255.255.0
and your IP address is: 198.139.158.3
 
your Network address is: 198.139.158.0

If you were in a subnetted environment you might have:

If your netmask is: 255.255.255.224
and your IP address is: 198.139.158.55
 
your Network address is: 198.139.158.32

This still only alludes to the "secret" of the netmask. To shed light on the second example lets take a look at the meaning of the netmask. We are going to convert the decimal notation (4 octets), to binary notation. The 1's in the netmask will imply the value "true", while the 0's will imply the value "false". The true values will be allowed to pass throught the netmask and the false values will not. The netmask acts as a filter.

 

Decimal

Binary

The IP address: 198.139.158.55
11000110 10001011 10011110 00110111
The netmask: 255.255.255.224
11111111 11111111 11111111 11100000
The Network address would be: 198.139.158.32
11000110 10001011 10011110 00100000

In the above chart, you can see in the binary column that whenever the netmask value is 0, the network address also has a value of 0. Whenever the netmask has a value of 1, the corresponding network address takes its value from the IP address. Try looking down from the IP address, to the netmask, then to the network address, digit by digit.

I hope this clarifies it for you.

Produced by:

Steven Lee, steven@main.nc.us