next up previous contents index
Next: Broadcast Address Up: Network Addresses, Masks, and Previous: Calculating the Network Mask   Contents   Index

How to use the Netmask

Once you can figure out what the Netmask of a network is you are probably wondering how to use it. All IP addresses get translated from their four groups into one large number before they are sent across the Internet. Once they are in this format the Linux Operating System looks at the number to figure out where to send the network packet. If your computer is 1.2.3.4 and you are trying to send a packet to 1.2.3.5 and your network mask is 255.255.255.0 or a /24 network then you would first translate the addresses into a group of bits. 1.2.3.4 would become 00000001.00000010.00000011.00000100 and 1.2.3.5 would become 00000001.00000010.00000011.00000101. If you line them up better you can see which parts are the same. Lets mark a 1 below each bit that is the same until we get a different bit. When we get a different bit we will fill in the rest with 0s:

1.2.3.4 00000001.00000010.00000011.00000100
1.2.3.5 00000001.00000010.00000011.00000101
same bits 11111111.11111111.11111111.11111110


We have 31 bits that are the same. In order to be in the same network we need to have at least 24 bits the same. That means that this address is in the same network and can be sent to another computer locally without being sent to a gateway. What if the same address 1.2.3.4 was sending a packet to 1.2.34.56? What would the table look like then?

1.2.3.4 00000001.00000010.00000011.00000100
1.2.34.56 00000001.00000010.00100010.00111000
same bits 11111111.11111111.11000000.00000000


In this example we only have 18 bits that are the same. We needed 24 bits to be the same in order to be in the same network, so we will send the packet to the gateway. Pretty easy? Well, it takes a little bit of time for some people to understand this concept.


next up previous contents index
Next: Broadcast Address Up: Network Addresses, Masks, and Previous: Calculating the Network Mask   Contents   Index
Joseph Colton 2002-09-24