How subnetting works

An IPv4 address is 32 bits split into a network part and a host part. The subnet mask (or its CIDR prefix) draws the line: every bit set to 1 belongs to the network, every 0 to the host. From that single split everything else follows — the network address (all host bits 0), the broadcast address (all host bits 1), and the usable host range in between.

usable hosts = 2^(32 − prefix) − 2  ·  the −2 removes the network & broadcast addresses

Worked example

Take 192.168.1.0/24. The /24 mask (255.255.255.0) reserves 24 bits for the network and 8 for hosts:

Network:   192.168.1.0
Broadcast: 192.168.1.255
Usable:    192.168.1.1 to 192.168.1.254   (2^8 − 2 = 254 hosts)
Wildcard:  0.0.0.255

Borrow one more bit (/25) and you get two subnets of 126 hosts each — that borrow-a-bit trick is the whole of VLSM (variable-length subnet masking), where each subnet uses a mask sized to match how many hosts it actually needs.

Related