If you are going to set up a network, then you have to know how to distribute them. For this to know network and broadcast addresses is very essential. So to know how to calculate network and broadcast addresses if you have IP address and subnet mask.
Method 1
For Classful Network
For a classful network total bits is 8. So Total bits = T_{b} = 8.
 Subnet mask can be 0, 128, 192, 224, 240, 248, 252, 254 and 255.
 Below table gives you the “Number of bits used for subnetting”(n) to their corresponding subnet mask.
 For subnet mask 255 is default, so it’ll not consider for subnet masking.
 For example:
Let, IP address = 210.1.1.100 and Subnet mask = 255.255.255.224Total bits = T_{b} = 8 Number of bits used for subnetting = n = 3 (as subnet mask = 224 and its corresponding “No. of bits used for Subnetting” is 3 from above table)
From the previous step, you got the “Number of bits used for subnetting”(n) and you know the “T_{b}“, then you can get “Number of bits left for host”(m) = T_{b} – n as total bits is the summation of number of bits used for subnetting and number bits left for host i.e. T_{b} = m+n.
 Number of bits left for host = m = T_{b} – n = 8 – 3 = 5
 Number of subnets = 2^{n} = 2^{3} = 8
Value of last bit used for subnet masking = Δ = 2^{m} = 2^{5} = 32
 The 8 subnets (as calculated in previous step) are shown above.
 Each of them has 32 addresses.
Now you have to find that your IP address is in which subnet, that subnet’s first address is network address and last address is broadcast address.
 Here the taken IP address is 210.1.1.100 . 210.1.1.100 comes in 210.1.1.96 – 210.1.1.127 subnet (see the previous step table). So 210.1.1.96 is network address and 210.1.1.127 is broadcast address for the taken IP address i.e. 210.1.1.100 .
For CIDR
Method 2
 Write the the bitprefix in below format.

 If it’s 27, then write it as 8 + 8 + 8 + 3 .
 If it’s 12, then write it as 8 + 4 + 0 + 0 .
 Default is 32, which is 8 + 8 + 8 + 8.
 Convert the corresponding bit according to the below table and represent in quaddotted decimal format.
Let IP address is 170.1.0.0/26 . Using above table, you can write:
26  =  8  +  8  +  8  +  2  
255  .  255  .  255  .  192 
Now the IP address is 170.1.0.0 and subnet mask in quaddotted decimal format is 255.255.255.192 .
 Subnet mask can be 0, 128, 192, 224, 240, 248, 252, 254 and 255.
 Below table gives you the “Number of bits used for subnetting”(n) to their corresponding subnet mask.
 For subnet mask 255 is default, so it’ll not consider for subnet masking.
 From the previous step, you got IP address = 170.1.0.0 and Subnet mask = 255.255.255.192
Total bits = T_{b} = 8 Number of bits used for subnetting = n = 2 (as subnet mask = 192 and its corresponding “No. of bits used for Subnetting” is 2 from above table)
 Number of bits left for host = m = T_{b} – n = 8 – 2 = 6
 Number of subnets = 2^{n} = 2^{2} = 4
Value of last bit used for subnet masking = Δ = 2^{m} = 2^{6} = 64
Now you can find previously calculated number of subnets by separating subnets each having “Value of last bit used for subnet masking” or Δ addresses.
 The 4 subnets (as calculated in previous step) are
 Each of them has 64 addresses.
 Here the taken IP address is 170.1.0.0 . 170.1.0.0 comes in 170.1.0.0 – 170.1.0.63 subnet (see the previous step table). So 170.1.0.0 is network address and 170.1.0.63 is broadcast address for the taken IP address i.e. 170.1.0.0 .