How to Calculate Number of Host in a Subnet? – GeeksforGeeks
In computer networks, an IP address is a unique address that identifies a device on the internet or a local network. Using IP address we can find information about the Class of IP address and number of computers connected in that network (range of IP address in that network), network IP address, broadcast address.
Mục Lục
Steps to find the number of computers connected in the given IP address
1) Identify the class of the IP address
To find the number of computers connected in the network first we need to identify the class of the IP address, there are 5 classes of IP addresses they are A, B, C, D, E.
Each IP address of ipv4 consists of 32bits, it is divided into 4 octets, 1 octet = 8 bits, look at the first octet to find the class of the given IP address. The range of each class is given in the following table.
ClassesrangeA0 to 127B128 to 191C192 to 223D224 to 239E240 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
ClassesDefault maskA255.0.0.0B255.255.0.0C255.255.255.0D–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.
ClassesNumber of networks possibleNumber of hosts possible in 1 networkNumber of usable hosts in 1 networkA126224224 – 2B163846553665534C221256254Dno networks no hosts–Eno networksno hosts–
[Note: Class D is reserved for Multicasting, group email/ broadcast, possible IP address in class D are 228
Class E is reserved for experimental and research / military purposes, possible IP addresses in class E is 228]
In simple words, the Number of hosts in any network can be calculated with the formula = 2x– 2, where x is the number of host ID bits in the IP address.
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
IP address = 9.1.5.31, Network address= 9.0.0.0
So, Network ID bits= 8 (first octet), Host ID bits= 24 (Last three octets)
The network IP address of the given IP address is 9.0.0.0
The number of hosts in each network is 224– 2
The broadcast IP address is 9.255.255.255
Example 2: Find the Class, network IP address, number of hosts (computers), and broadcast address of 201.20.30.40
Answer: Finding the Class to which the given IP address belongs to
The first octet has a value of 201 which is in the range of 192 to 223 so the given IP address belongs to Class C.
Finding the Network IP address
The default mask for class C as given in the table is 255.255.255.0
Perform the AND operation to get the network IP address
201.20.30.40 => 11001001.00010100.00011110.00101000
255.255.255.0 => 11111111.11111111.11111111.00000000
11001001.00010100.00011110.00000000 => 201.20.30.0
IP address = 201.20.30.40, Network address= 201.20.30.0
So, Network ID bits= 24 (first three octets), Host ID bits= 8 (Last octet)
The network IP address of the given IP address is 201.20.30.0
The number of hosts in each network is 28– 2= 254
The broadcast IP address is 201.20.30.255
My Personal Notes
arrow_drop_up