Monday, June 15, 2009

Understanding Subnet Mask

If you are winxp user, just type "ipconfig" in the command window, you will probably see something like:

Connection-specific DNS Suffix... somedomain.com
IP address...................................... 192.168.5.10
Subnet Mask................................. 255.255.255.0
Default Gateway........................... 192.168.5.100

SubnetMask seems always go with IP address.
Ever wondering what subnet mask is?
If the answer is yes, you may want to read this article.


Part 1 IP Addressing
Computers and devices that are part of an internetworking network such as the Internet each have a logical address. The network address is unique to each device and can either be dynamically or statically configured. An address allows a device to communicate with other devices connected to a network. The most common network addressing scheme is IPv4. An IPv4 address consists of a 32 bit address written into 4 octets (e.g. 192.168.5.10) and a subnet mask (e.g. 255.255.255.0).

Suppose a home network consists of computers named Foo and Bar, connected to a router, and then via a cable modem to the Internet. The home network is configured as a subnet: address 17.76.99.1 is assigned to Foo, address 17.76.99.2 to Bar, and address 17.76.99.100 to the router. The subnet has been configured so that the first three octets of its members' addresses are all the same subnet id, 17.76.99, and this fact is expressed by the subnet mask 255.255.255.0 (binary 11111111 11111111 11111111 00000000) configured in the router.
When Foo sends data to example.com at 208.77.188.166, the router performs a logical AND of the destination example.com address with the subnet mask. It also performs a logical AND of the origin address (17.76.99.1) and recognizes that these two results are different, and therefore sends the data over the Internet, via the subnet's default gateway.
When Foo sends data to Bar, however, it determines that the results of the two AND operations are the same, therefore the destination lies within the subnet and the default gateway is not required. The data is transmitted directly from Foo to Bar within the home network.

For detail about IP address, see the network 101 -- Understanding IP address.

Part 2 Why subnet mask
As Intenet grows, more network IP address number are needed. The InterNIC (who in charge of IP address allocation), however, is not eager to hand out unlimited network addresses because they are quickly running out of them. One way of IP address conservation is to take the address that is assigned to a network and expand the capacity with subnets. Subnetting allows you to increase the number of networks available to you without applying for another IP address number.
On the other hand, putting too many computers in a single network is problematic. Due to heavy transfer of data, the packets become slow resulting in collision and retransmission. As there is no security barrel, critical data can be accessed by any other computer. Again, subnetwoking is needed here.

Part 3 IP Address Classes
The IP address is composed of 32 bits, which consist of two parts: the most significant bits (MSBs) identify a particular network and the remaining bits specify a host on that network. The most significant bits of the network portion actually determine the address class as shown in this table: Address MSB
Class Pattern
Class A 0
Class B 10
Class C 110

A class A address could be diagramed:
Network Host
+------+ +----------------------+
[0xxxxxxx][xxxxxxxxxxxxxxxxxxxxxxxx]
which shows the eight network bits followed by the 24 host bits.

Class A address would have a range of address numbers from 1.0.0.0 through 126.0.0.0 ( 0. x.x.x and 127. x.x.x are reserved). The number of host addresses per network is 16,777,214, which is two less than two raised to the 24th power because both host numbers 0.0.0 and 255.255.255 are reserved.

The first two bits of a Class B address are 1 and 0, the next fourteen bits identify the network and the last sixteen the host, as diagramed:
Network Host
+--------------+ +--------------+
[10xxxxxxxxxxxxxx][xxxxxxxxxxxxxxxx]
Thus, Class B addresses include the network numbers in the range from 128.1.0.0 through 191.254.0.0 for a total of 65,534 host addresses.

The first three bits of a Class C address are 1, 1, and 0, the next 21 bits identify the network and the last eight the host, as diagramed:
Network Host
+----------------------+ +------+
[110xxxxxxxxxxxxxxxxxxxxx][xxxxxxxx]
Thus, Class C addresses include the network numbers in the range 192.0.1.0 through 223.255.254.0 for a total of 254 host addresses per network address.
Finally, we have Class D and Class E addresses. Class D address start at 224.0.0.0 and are used for multicast purposes. Class E addresses start at 240.0.0.0 and are currently used only for experimental purposes.

Part 4 The Subnet Mask
A subnet mask (or number) is used to determine the number of bits used for the subnet and host portions of the address. The network bits are represented by the 1s in the mask and the host bits are represented by the 0s in the mask. The result of a bit-wise logical 'AND' operation between the IP address and the subnet mask is a Network Address or Number or Subnet Address.
Let's look at an example. Here we have a Class B address of 191.70.55.130 and apply the default subnet mask 255.255.0.0.
1011 1111 1000 0110 0011 0111 1000 0010 IP address
1111 1111 1111 1111 0000 0000 0000 0000 Subnet mask
1011 1111 1000 0110 0000 0000 0000 0000 Result

Subnet Mask can take value other than 255.255.0.0, here we employ a mask 255.255.255.0 that divides the host portion into a subnet and host that are each eight bits wide:
1011 1111 1000 0110 0011 0111 1000 0010 IP address
1111 1111 1111 1111 1111 1111 0000 0000 Subnet mask
1011 1111 1000 0110 0011 0111 0000 0000 Result
This division allows 254 (256-2 reserved) subnets, each with 254 hosts.


This division on a byte boundary makes it easy to determine the subnet and host from the dotted-decimal IP address. However, the subnet-host boundary can be at any bit position in the host portion of the IP address. Here, we use a mask 255.255.128.0 that allows more subnets (512-2 reserved), but with the trade-off of fewer hosts (128-2) per subnet:

1011 1111 1000 0110 0011 0111 1000 0010 IP address
1111 1111 1111 1111 1111 1111 1000 0000 Subnet mask
1011 1111 1000 0110 0011 0111 1000 0000 Result

Part 5 Private Subnets

There are three IP network address reserved for private networks.

10.0.0.0 to 10.255.255.255

172.16.0.0 to 172.31.255.255

192.168.0.0 to 192.168.255.255

These can be used by anyone setting up internal IP networks, because routers on the Internet will never forward packets coming from these addresses.

Part 6 Design Example
Suppose you have a Class C IP address of 200.133.175.0, and you want to break the network into 6 subnets of 30 nodes each, which limits us to 180 nodes.
To accomplish this, we need to use a subnet mask 3 bits long.
255.255.255.224 (11111111.11111111.11111111.11100000)
This gives us 6 possible network numbers, 2 of which cannot be used.

Subnet bits, Subnet Address, Node Addresses, Broadcast Address
000, 200.133.175.0, Reserved, None
001, 200.133.175.32, .33 thru .62, 200.133.175.63
010, 200.133.175.64, .65 thru .94, 200.133.175.95
011, 200.133.175.96, .97 thru .126, 200.133.175.127
100, 200.133.175.128, .129 thru .158, 200.133.175.159
101, 200.133.175.160, .161 thru .190, 200.133.175.191
110, 200.133.175.192, .193 thru .222, 200.133.175.223
111, 200.133.175.224, Reserved, None

Part 7 CIDR
To simplify subnet mask notation, CIDR suffix address (e.g. /18) is used, which list only 1s bits that start the mask.
Class A= /8, Class B = /16, Class C =/24
For instance, the following are equivalent:
192.168.0.0 with netmask 255.255.0.0
192.168.0.0/16

For another instance, the following are equivalent:
192.168.0.0 with netmask 255.255.128.0
192.168.0.0/17

[ Socialize This]

1 comment:

  1. MY QUESTION IS WHY CANT WE USE THE HOST

    ADDRESSES 200.133.175.1 THRU 200.133.175.30 ??

    THIS IS THE SITE WHERE THE CISCO EXAMPLE IS...
    http://www.cisco.com/en/US/tech/tk365/technologies_tech_note09186a00800a67f5.shtml#ex2



    AND THIS IS WHERE THE OTHER EXAMPLE IS
    http://www.semsim.com/ccna/tutorial/subnetting/CCNA-Subnetting-Course-Map.pdf

    PLS HELP!!!

    ReplyDelete

Why I stopped publishing blog posts as information provider

Now the AI can generate content. Does that mean the web publishing industry reaches the end? ChatGPT said: ChatGPT Not at all. While AI can ...