Calcylator
Ip Address Subnet

IP address subnetting:
find the network, broadcast and usable range

Subnetting looks like binary puzzle work, but every answer comes from one AND operation and a power of two. Here is the routine, done by hand.

Calcylator Editorial Team

Updated · 4 min read

How an address, a prefix and a mask fit together

An IPv4 address is a 32-bit number, written as four decimal bytes. A subnet splits those 32 bits into a network part at the front and a host part at the end. The prefix length after the slash says how many bits belong to the network, so /24 means the first 24 bits and /27 means the first 27.

The same split can be written as a subnet mask, which is a 32-bit number with ones in the network positions and zeros in the host positions. A /24 prefix is 255.255.255.0 and a /27 prefix is 255.255.255.224. The mask and the prefix describe the identical boundary in two notations.

Everything you want to know about the subnet follows from that boundary: where the network starts, where it ends, and how many devices fit between.

The three formulas you need

Network address =IP address AND subnet mask
AND:
bitwise operation: 1 only where both bits are 1
subnet mask:
255.255.255.x written in binary
Broadcast address =network address OR wildcard mask
wildcard mask:
the inverse of the subnet mask, for example 0.0.0.31 for /27
Usable hosts =2^(32 − prefix) − 2
32 − prefix:
number of host bits
− 2:
one address is the network, one is the broadcast

The first usable address is the network address plus one, and the last is the broadcast address minus one. These formulas apply per subnet, so each subnet loses two addresses to its own network and broadcast roles.

Worked example: 10.20.77.130/27

Only the last octet needs work, because the /27 mask is 255.255.255.224 and the first three octets of the mask are all ones. The last octet of the address is 130, and 224 is the last octet of the mask.

  • Address, last octet

    130 = 10000010

  • Mask, last octet

    224 = 11100000

  • AND

    10000000 = 128

  • Block size

    256 − 224 = 32

  • Broadcast

    128 + 32 − 1 = 159

  • Usable range

    10.20.77.129 to 10.20.77.158

  • Host bits

    32 − 27 = 5, so 2⁵ − 2 = 30 hosts

Network

10.20.77.128/27

Broadcast 10.20.77.159; 30 usable addresses.

This is the faster version: since the block size is 32, the network addresses in this /24 are multiples of 32 (0, 32, 64, 96, 128 and so on). The number 130 lies between 128 and 160, so its network is 128.

Prefix reference for the last octet

Common subnet sizes inside one /24
PrefixSubnet maskBlock sizeUsable hostsSubnets per /24
/24255.255.255.02562541
/25255.255.255.1281281262
/26255.255.255.19264624
/27255.255.255.22432308
/28255.255.255.240161416
/29255.255.255.2488632
/30255.255.255.2524264

A /30 gives two usable hosts and is traditional for point-to-point links, while /31 is used on point-to-point links where the two addresses are both usable, and /32 identifies a single host. These two do not follow the minus-two rule.

Using the numbers to plan a network

Planning starts from the number of devices in each segment. Count current hosts, add growth, and then choose the smallest prefix whose usable count covers it. Forty devices need at least 42 addresses, so a /26 with 62 hosts fits, while a /27 with 30 does not.

Aligning subnets on their block boundaries is essential. A /26 can only start at .0, .64, .128 or .192 within a /24. Trying to start one at .50 is invalid because the network address must be a multiple of the block size.

  • Keep one prefix length per function (users, servers, voice) so that rules are easy to read.
  • Leave unused space between groups so a subnet can grow without renumbering.
  • Reserve private ranges such as 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 for internal use.

Splitting space with different sized subnets

Real networks need segments of different sizes, and fixed-size splitting wastes addresses. Variable-length subnet masking allocates the largest block first and works down. Take 192.168.10.0/24 and three groups: 100 hosts, 50 hosts and 20 hosts.

  • 100 hosts need 7 host bits (126 usable), so a /25: 192.168.10.0/25 covering .0 to .127.
  • 50 hosts need 6 host bits (62 usable), so a /26: 192.168.10.128/26 covering .128 to .191.
  • 20 hosts need 5 host bits (30 usable), so a /27: 192.168.10.192/27 covering .192 to .223.

Addresses .224 to .255 remain free for future use, and none of the blocks overlap. Allocating biggest-first keeps every block aligned to its own size.

A few ranges have special meaning and should not be handed to ordinary hosts. 127.0.0.0/8 is loopback, 169.254.0.0/16 is used for automatic link-local addressing when no DHCP answer arrives, and 100.64.0.0/10 is set aside for carrier-grade NAT. The private blocks 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 are the ones meant for internal networks.

Overlap is the most common design error when networks are joined, for example when two offices both use 192.168.1.0/24. A quick calculation of each range's network and broadcast addresses shows the clash before a VPN is built, which is much cheaper than finding it afterwards.

Common slips and what a subnet figure cannot tell you

A frequent error is taking the broadcast address as usable or the network address as a device address. Another is mixing up the prefix and the mask when typing configuration: /27 and 255.255.255.224 are the same boundary, but 255.255.255.27 is meaningless.

A subnet calculation describes addressing only. It does not prove that two hosts can reach each other, because routing, firewalls, VLAN configuration and gateways all play a part. Treat the output as a design aid and confirm with real connectivity tests.

Common questions

How do you find the network address from an IP and prefix?

Convert the address and mask to binary and AND them, bit by bit. For 10.20.77.130/27 only the last octet matters: 130 AND 224 = 128. The network address is 10.20.77.128. The quick method is to find the multiple of the block size at or below the host value.

How many hosts are in a /27 subnet?

A /27 has 5 host bits, so 2⁵ = 32 addresses, of which 30 are usable once the network and broadcast addresses are removed. It uses the mask 255.255.255.224 and fits eight times into a /24.

What is the difference between a prefix and a subnet mask?

They are two ways of writing the same boundary. The prefix counts the network bits, such as /24, and the mask writes them as ones in dotted decimal, such as 255.255.255.0. Converting between them is a matter of counting ones.

What is the broadcast address of 192.168.12.45/26?

The /26 block size is 64, and 45 falls in the block starting at 0. The broadcast address is 0 + 64 − 1 = 63, so it is 192.168.12.63. The usable range is 192.168.12.1 to 192.168.12.62, giving 62 hosts.

Why do we subtract 2 from the number of addresses?

In a normal IPv4 subnet the first address identifies the network and the last is the broadcast address, so neither can be given to a device. A /30 has four addresses and therefore two hosts. Special cases such as /31 and /32 are treated differently.

Was this guide helpful?

Continue reading

View all blogs