# How to obtain maximum number of subnets and hosts from a give IP address

Let’s assume that the given IP address is 172.20.0.0 and the mask is 255.255.255.224

Or simply 172.20.0.0/27 in CIDR notation

Steps to find out the number of hosts:

1. Find out the block and subtract it by 2. Why 2? Because in a given network address, 1 bit is always reserved for network and one for broadcast address.

Let’s find the block, take the last octet of the subnet mask (224) and subtract it from 256; 256-224=32. So 32 is the block or the range for this ip address. And if you subtract 2 from 32, you get 30. And that’s the number of host achievable from this network. Easy!

Now what about the subnet?

1. Let me show another way of finding both the subnets and hosts. Again it is very easy!

For this we need to convert the subnet mask into binary number and distinguish the two (subnet & host):

255.255.255.224

11111111.11111111.11111111.11100000

From this we come to know that all 0s are the bits reserved for host and all 1s are reserved for subnets.

Now we know that this particular ip address belongs to Class B that means, first two octets are reserved for network and remaining two are for subnets and hosts.

nnnnnnnn.nnnnnnnn.ssssssss.ssshhhhh

Therefore, subnet is 2^11= 2048 and host 2^5-2=30

# Obtaining Network ID, Broadcast address and usable IP addresses from a given IP address

Let’s say you have been give an IP address and asked you to find out its Network ID, Broadcast and all usable IP addresses. How can you do it?
Well there are different ways to do it, but I will discuss two ways and I am particularly very interested to discuss the one that is easy and faster!
First Way: let’s assume that the given IP address is 5.88.192.50/29
Step 1: The /29 means 29 bits are turned on, i.e. 11111111.11111111.11111111.11111000 from this we get the subnet 255.255.255.248
Step 2: Now subtract the last octet of subnet mask from 256 to get the block size. 256 – 248 = 8 (block)
Step 3: Now increment the block by block starting from zero until it get more than the last octet of the given IP address (50), i.e. 0,8,16,24,32,40,48,56………
Step 4: Now one can see that the last octet of IP address 50 falls between block size 48 and 56, hence we get that:
Network ID is: 5.88.192.48
Broadcast address is: Last bock size 56 – 1 = 55 (5.88.192.55)
Usable IP range: 6
5.88.192.49
5.88.192.50
5.88.192.51
5.88.192.52
5.88.192.53
5.88.192.54

Second Way: We will consider the same IP address 5.88.192.50/29
Step 1: Get the subnet mask, which is 255.255.255.248
Step 2: Get the block size 256 -248 = 8 (block)
Step 3: Divide the last octet of IP address i.e. 50 by the block size i.e. 8 (50 / 8 = 6.25)
Step 4: Now truncate the decimal portion of the value 6.25 and multiply it by block size 8 (6 * 8 = 48)
Hence 48 is the network ID of the given IP address. 5.88.192.48

Note: This second way is little tricky sometimes. Because one might get a block size greater than the value in the octet to be divided. For example consider this IP address: 10.218.15.163 255.255.240.0  OR /20. The block size of this network is 16 and value in the octet is 15 hence we can’t divide this further. So the solution is one can follow the binary AND operation mentioned below or simply replace the octet and subsequent octet with zero.

Therefore, according to this rule the answer to this question:

Which subnet does host 10.218.15.163 255.255.240.0 belong to?

Subnet: 10.218.0.0

Third Way: We will consider the same IP address 5.88.192.50/29
Using bit wise AND operation and this is what exactly computers get the information.

Here the IP address and the subnet mask is converted into binary numbers and after performing bit wise AND operation, one will get the network address.