What is Subnetting:
Example 1: Class B subnet
Let's use a class B address to illustrate how subnetting works. Let's say you were assigned the class B address 172.16 from the NIC. First determine how many subnets you need, and how many nodes per subnet you need to define. A typical (and easy to use) subnetting scheme for a class B network would be to use an 8 bit subnet mask. Since the 3rd octet is the first "free" octet for Class B, you will start there. So, an 8 bit subnet mask would be 255.255.255.0. This means you have 254* subnets available and 254 addresses for nodes per subnet.
*Why are there only 254 subnets available instead of 256 (0-255)? You should not use subnet 0 or a subnet of all 1s. With an all 1s subnet mask, this is also your broadcast address. You can configure this, but it is neither proper nor recommended to make your subnet the same as your broadcast address. Subnet 0 is also not recommended. Cisco will allow the use of subnet 0 with the IP subnet zero command.
Example 2: Class B
Now let's take this example: you have just assigned an interface the address 172.16.10.50 with a mask of 255.255.255.0. What subnet is it in? First represent the bits in binary (for class B, you start with the 3rd octet since octets 1 and 2 are fixed).
|
SUBNET
|
HOST
|
|
|
00001010
|
00110010
|
(address representation - 10.50)
|
|
11111111
|
00000000
|
(subnet mask representation - 255.0)
|
|
00001010
|
00000000
|
(results of logical "AND" - subnet 10) 10
|
This address is in subnet 10 (172.16.10.0). Valid addresses for subnet 10 would be 172.16.10.1 through 172.16.10.254. Address 172.16.10.255 is the broadcast address for this subnet. According to the standard, any host id consisting of all 1s is reserved for broadcast.
Example 3: Class B
Let's say you have a need for more subnets than 254. (Remember this is the maximum number of subnets in a single octet.) Sticking with our class B address, let's configure an 11 bit subnet. This means we will use all 8 bits from our 3rd octet and the first three bits from the 4th octet. The subnet mask is now 255.255.255.224 (128+64+32=224). Now you need to find out what subnet the following address is in: 172.16.10.170 255.255.255.224. First, denote the address in binary representation (just octets 3 and 4 for a class B address) like this:
|
SUBNET
|
HOST
|
|
|
00001010
|
10101010
|
(address representation 10.170)
|
|
11111111
|
11100000
|
(subnet mask representation 255.224-first 11 bits subnet)
|
|
00001010
|
10100000
|
(results of logical "AND") 10 160
|
So, the address here is in subnet 172.16.10.160. The valid addresses for this subnet are 172.16.10.161 through 172.16.10.190 (.191 is the broadcast address). As soon as you hit 10.192, the bits in the subnet change and you move into subnet 10.192.
Example 4: Class B
Let's take an example where the mask is shorter than one octet. Now we want only a few subnets, but need many hosts per subnet. We'll use a 3 bit subnet mask. Now we have: 172.16.65.170 255.255.224.0 (the mask is now the first 3 bits of the 3rd octet). What subnet is this address in?
|
SUBNET
|
HOST
|
|
|
01000001
|
10101010
|
(address representation 65.170)
|
|
11100000
|
00000000
|
(subnet mask representation 224.0)
|
|
01000000
|
00000000
|
(results of logical "AND" - subnet 64) 64
|
|