Calculate the broadcast address for your IPv4 subnet

One network device sending three lines toward nearby computers
Contents
  1. Use the prefix to find the subnet
  2. Identify which kind of broadcast you mean
  3. Check for exceptions before assigning addresses
  4. Frequently asked questions

An IPv4 broadcast address targets devices on a network segment that receive that type of traffic. For a typical subnet, set every host bit to 1 to find its subnet broadcast. On 192.168.5.128/26, the result is 192.168.5.191. The last number is not always 255.

Use the prefix to find the subnet

Take 192.168.5.140/26. A /26 leaves six bits for hosts, giving blocks of 64 addresses. In the last octet, the blocks start at 0, 64, 128, and 192. The address .140 falls in the block from .128 through .191. The first address is the subnet address. The last is its broadcast address.

IPv4 address and prefixSubnet addressSubnet broadcast
192.168.5.140/24192.168.5.0192.168.5.255
192.168.5.140/26192.168.5.128192.168.5.191
192.168.5.140/27192.168.5.128192.168.5.159

The same IPv4 address gives three different broadcasts in this table. Read the prefix or subnet mask from the actual network configuration before calculating.

Identify which kind of broadcast you mean

An IPv4 subnet-directed broadcast uses a specific network prefix followed by all ones for its host bits. The limited broadcast address, 255.255.255.255, stays on the local link. RFC 2644 specifies that routers disable receipt and forwarding of network-directed broadcasts by default, so do not expect the address of a remote subnet to reach every device there.

An Ethernet broadcast is at a different layer. For example, an ARP request can go to the Ethernet broadcast MAC address to learn a neighbor's hardware address. The subnet examples above calculate IPv4 destination addresses.

Check for exceptions before assigning addresses

For the ordinary /26 example, assign devices within .129 through .190. Leave .128 for the subnet identity and .191 for broadcast. A /31 point-to-point link using RFC 3021 is a special case. Its two addresses serve as endpoints, so the usual rule for an ordinary shared subnet does not apply. The IP address guide explains why an address and its network settings belong together.

Frequently asked questions

Is an address ending in .255 always a broadcast?

Check the prefix. Whether an address has all host bits set depends on the subnet mask, including any bits left for hosts before the last octet.

Is the subnet address the same as the broadcast?

For a typical multi-device subnet, the subnet address has host bits all zero and the broadcast has them all one.

Will every device answer a broadcast ping?

No. Clients and network equipment can ignore or filter that traffic. Use an authorized device inventory when you need a list of connected hosts.

Sources