Subnet CN
Subnet CN
Subnet CN
Address?
To calculate a subnet mask from an IP address first, we have to identify the
type of IP address whether it belongs to a class full IP address or a Classless
IP address. In this article, we discuss how to calculate subnet mask for class
full IP address and Classless IP address.
Calculate Subnet Mask For Classful IP Address
As we know there are five classes in class full IP addressing Class A, Class B,
Class C, Class D, and Class E. From these classes two classes that is D and
E are reserved for special purposes remaining three classes that is A, B, and
C are used to provide IP address to the client.
Ranges of The Classes
Class A: 1.0.0.0 to 126.255.255.255
Class B: 128.0.0.0 to 191.255.255.255
Class C: 192.0.0.0 to 223.255.255.255
Default Subnet Mask
Class A: 255.0.0.0
Class B: 255.255.0.0
Class C: 255.255.255.0
To identify the subnet mask of any given IP address first we have to find the
class of the IP address and then the default subnet mask is the subnet mask
of that IP address.
Example 1: Find subnet mask of the 19.35.21.31 IP address.
As we can see this IP address belongs to class A because 19 the first octate
decimal value come in the range of 1 to 126 that is class A so the subnet
mask of this IP address is 255.0.0.0.
Example 2: Find subnet mask of the 217.39.47.9 IP address.
As we can see this IP address belongs to class C because 217 the first octate
decimal value come in the range of 192 to 223 that is class C so the subnet
mask of this IP address is 255.255.255.0.
Calculate Subnet Mask For Classless IP Address
Class less IP addressing is also known as CIDR (Classless Inter-Domain
Routing) notation, represents how many bits are used for the network portion
of the IP address. The representation of the CIDR notation is a.b.c.d/n here n
represent the number of bits used for network portion or NID these first n bit
are 1 in the subnet mask of any IP address.
Example: Calculate the subnet mask of 192.168.1.0/24.
Here n=24 means 24 bits is 1 in the subnet mask so the subnet mask of this
IP address is 11111111.11111111.11111111.00000000 i.e 255.255.255.0.
Calculate a Custom Subnet Mask
If you want to divide your network into smaller subnets, you need to modify
the subnet mask. This is done by borrowing bits from the host portion and
adding them to the network portion.
For instance, if you want to divide a Class C network into two subnets, you
borrow one bit from the host part:
o Default mask: 255.255.255.0 (24 bits, /24)
o Subnet mask: 255.255.255.128 (25 bits, /25)
Calculate Subnet and Host Per Subnet
To calculate how many subnets and hosts per subnet are possible after
subnetting, use the following formulas:
Number of Subnets: 2n, where n is the number of borrowed bits.
Hosts per Subnet: 2h−2 where h is the number of bits left for the host
portion (subtracting 2 for network and broadcast addresses).
Example: Calculate the subnet mask of 192.168.1.0/26.
Subnet Mask: 255.255.255.192 (26 bits for network, 6 bits for host)
Subnets: 22=4 subnets
Hosts per Subnet: 26−2=62 hosts per subnet
Conclusion
Calculating a subnet mask from an IP address involves understanding class
full IP addressing and CIDR notation, binary conversion,
and subnetting principles. For class Full IP addressing there is a
default subnet mask for each class and for CIDR notation n represent the NID
part or number of 1’s in the subnet mask.
A
0 to 127
B
128 to 191
C
192 to 223
D
224 to 239
E
240 to 255
Example: If the IP address given is 64.19.23.0 then the first octet is 64 which
is in the range of 0 to 127, so the given IP address belongs to class A.
2) Finding network IP address
To find the network IP address we need default mask value, Default mask
value is different for each class, the default mask value for each class is given
in the table below
A
255.0.0.0
B
255.255.0.0
C
255.255.255.0
D –
E
–
After finding the default mask value, perform AND operation with the given IP
address to get the network IP address.
Example: If the given IP address is 64.0.0.8 convert this into the binary format
by replacing each octet with respective binary values, then the Binary format
of the given IP address will be 01000000.00000000.00000000.00001000.
Now take the default mask value to which the IP address belongs (from the
above table), convert that default mask value into its binary format, the default
mask of class A is 255.0.0.0 converting to binary format will be
11111111.00000000.00000000. 00000000
Now perform the AND operation between them
01000000.00000000.00000000. 00001000
11111111.00000000.00000000. 00000000
01000000.00000000.00000000.00000000 => 64.0.0.0
Convert the resulting answer to decimal format to get the network IP
address. The network IP address of the given IP address 64.0.0.8 is 64.0.0.0
3) Finding the number of hosts or number of computers connected to that
network
The class it belongs will tell the range of hosts that can connect to that
network, it’s given in the below table.
D no networks no hosts –
E no networks no hosts –
In simple words, the Number of hosts in any network can be calculated with
the formula = 2 – 2, where x is the number of host ID bits in the IP address.
x
Why do we subtract 2?
Because the first and last addresses are not used for any hosts because the
first IP is used to represent the whole network ID while the last IP is used as
the broadcast address.
Example: The given IP address is 192.168.254.1 it belongs to class C, when
we perform AND operation on IP address with a default mask of class C, we
get the network IP address as 192.168.254.0 this is the IP address used to
represent the whole network and the broadcast address will be the last IP
address of this network which is 192.168.254.255
4) Broadcast address
Broadcast addresses are of 2 types limited broadcast and direct broadcast
Limited broadcast: When the host in the same network wants to broadcast
a message to all hosts within its network, In this case, the Broadcast
address will be 255.255.255.255
Direct broadcast: When the host in another network wants to broadcast a
message to all the hosts in the other network, then the broadcast address
will be calculated as above.
Example 1: Find the Class, network IP address, number of hosts
(computers), and broadcast address of 9.1.5.31
Answer: Finding the Class to which the given IP address belongs to
The first octet has a value of 9 which is in the range of 0 to 127 so
the given IP address belongs to Class A.
Finding the Network IP address
The default mask for class A as given in the table is 255.0.0.0
Perform the AND operation to get the network IP address
9.1.5.31 => 00001001.00000001.00000101.00011111
255.0.0.0 => 11111111.00000000.00000000.00000000
00001001.00000000.00000000.00000000 => 9.0.0.0