@priyanka gautam-piya please see below example
we are calculating broadcast address of an entire IPv4 subnet.
RULE :
"The broadcast address for an IPv4 host can be obtained by performing a bitwise OR operation between the bit complement of the subnet mask and the host's IP address.
In other words, take the host's IP address, and set to '1' any bit positions which hold a '0' in the subnet mask."
Means take the subnet mask and set all 0's into 1 . now convert it and add with corresponding IP address value.
Example:
Host ip address 172.16.0.0, which has the subnet mask 255.240.0.0
240 = 128+64+32+16 means 1111 0000 now turn all 0 into 1 it becomes 1111 1111
last four 1 is 1+2+4+8 = 15
172.16.0.0, so add 16 + 15 = 31 in 3rd octet .
in 2nd octet flip all 0 into 1 it become 255
and in 1st octet flip all 0 into 1 it become 255
so the broadcast address becomes 172.31.255.255
So finally for ip address 172.16.0.0 subnet mask 255.240.0.0 and the broadcast address is 172.31.255.255
Reference
https://en.wikipedia.org/wiki/Broadcast_address