See this answer, and understand that you need both an address and mask to determine the network, then the broadcast address is the last address in the network.
Mask the address with the mask (logical AND
) to get the network, and you set all the host bits to 1
to get the broadcast address. You need to convert the address and mask to binary, do your calculations, the convert it back to decimal. Not everything will line up nicely with the decimal points in a text representation of an IPv4 address, and not doing it in binary will cause you problems.
The network is any address with the same networks bits. Any combinations of host bits with the same network bits are in the same network.