Subnet Math
100%

Subnetting · Lesson 3

Subnet Math

Learn how to calculate IPv4 network, broadcast, range, and address counts from a prefix.

Subnet math applies a prefix length to the 32 bits of an IPv4 address. Binary reasoning prevents mistakes at prefix boundaries that do not align with decimal octets.

Finding the Network Address

Use address 192.168.1.165/24:

address  11000000.10101000.00000001.10100101
mask     11111111.11111111.11111111.00000000
network  11000000.10101000.00000001.00000000

A bitwise AND keeps address bits where the mask is one and clears host bits. The result is 192.168.1.0/24.

Which operation finds an IPv4 network address from an address and mask?

Counting Addresses

For prefix /p, the host portion contains 32 - p bits. The total address count is:

2^(32 - p)

A /24 therefore contains 2^8 = 256 addresses. In a traditional broadcast subnet, the all-zero host value is the network address and the all-one value is the directed broadcast, leaving 254 ordinary unicast host addresses.

How many total addresses are in an IPv4 /24?

Finding a Block Boundary

For /26, the mask is 255.255.255.192. The final-octet block size is 256 - 192 = 64, so subnet boundaries are 0, 64, 128, and 192. Address 192.168.1.165/26 lies in:

network:   192.168.1.128
broadcast: 192.168.1.191
range:     192.168.1.129 through 192.168.1.190

What is the network address for 192.168.1.165/26?

Accounting for Prefix Exceptions

The shortcut 2^host_bits - 2 is not universal. IPv4 /31 prefixes are defined for point-to-point links where both addresses can be endpoints and no directed broadcast is needed. A /32 identifies one host route or interface address. Network technology and protocol use determine which addresses are assignable.

Why should you not subtract two addresses from every IPv4 prefix?

Verifying Calculations

Use an independent tool or library to check manual work, then compare with the real interface and route configuration. A mathematically valid prefix can still conflict with another subnet or violate an allocation plan.

What does a correct subnet calculation fail to prove?

Lesson complete

You finished Subnet Math

You can now calculate IPv4 subnet boundaries and recognize common exceptions.

  • Find a network address with bitwise AND.

  • Count total addresses from the number of host bits.

  • Use block sizes to locate network and broadcast boundaries.

  • Handle /31 and /32 according to their intended use.

  • Verify mathematical results against the actual address plan.

Keep your learning progress

Create a free account to save this lesson and continue learning on any device.

Create a free account
Next Lesson
Back to Subnetting