Network Prefix Calculator

Calculate the network prefix (network address) by performing a bitwise AND operation between an IP address and subnet mask. This is the fundamental operation that routers use to determine which subnet a packet belongs to and how to forward it.

Network Prefix Calculator
Figure 1 — Network Prefix Calculator

What Is a Network Prefix?

The network prefix (also called the network address or network ID) identifies which subnet a host belongs to. It is calculated by performing a bitwise AND between the IP address and the subnet mask. The result zeros out all host bits, leaving only the network portion of the address.

Every device on a network uses this calculation to determine whether a destination IP is on the same local subnet or needs to be forwarded through a gateway. When you ping another device, your operating system first ANDs its own IP with its mask, then ANDs the destination IP with the same mask. If the results match, the traffic stays local. If they differ, it goes to the default gateway.

How the Bitwise AND Operation Works

The AND operation compares two bits and produces a 1 only if both input bits are 1. Otherwise, the result is 0. Applied to an IP address and subnet mask octet by octet:

Bit A (IP)Bit B (Mask)A AND B (Result)
000
010
100
111

The subnet mask has all 1s in the network portion and all 0s in the host portion. When you AND the IP with the mask, the network bits pass through unchanged while the host bits become 0. This gives you the network address — the starting point of that subnet.

Worked Example

Given IP address 172.16.45.200 with subnet mask 255.255.240.0 (/20):

IP Address:    10101100.00010000.00101101.11001000  (172.16.45.200)
Subnet Mask:   11111111.11111111.11110000.00000000  (255.255.240.0)
────────────────────────────────────────────────────
Network Addr:  10101100.00010000.00100000.00000000  (172.16.32.0)

The third octet is where the interesting math happens. The IP has 00101101 (45) and the mask has 11110000 (240). ANDing these: 00101101 AND 11110000 = 00100000 (32). So the network address is 172.16.32.0/20.

Pro Tip: The quickest way to find the network address for non-standard masks is to focus only on the "interesting octet" — the octet where the mask is not 255 or 0. In the example above, only the third octet (45 AND 240) requires actual calculation. The rest are either passed through (AND 255) or zeroed (AND 0).

CIDR Prefix Length Reference

CIDRSubnet MaskInteresting OctetBlock SizeNetworks Start At
/20255.255.240.03rd (240)16.0, .16, .32, .48, ...
/21255.255.248.03rd (248)8.0, .8, .16, .24, ...
/22255.255.252.03rd (252)4.0, .4, .8, .12, ...
/23255.255.254.03rd (254)2.0, .2, .4, .6, ...
/25255.255.255.1284th (128)128.0, .128
/26255.255.255.1924th (192)64.0, .64, .128, .192
/27255.255.255.2244th (224)32.0, .32, .64, .96, ...
/28255.255.255.2404th (240)16.0, .16, .32, .48, ...

Network Prefix in Routing

Routers maintain a routing table that maps network prefixes to next-hop addresses or interfaces. When a packet arrives, the router extracts the destination IP, performs a longest prefix match against its routing table, and forwards the packet to the matching entry with the most specific (longest) prefix.

For example, if a routing table has entries for 10.0.0.0/8 and 10.1.0.0/16, a packet destined for 10.1.5.10 matches both entries, but the router uses the /16 entry because it is more specific. This is the foundation of how the internet routes traffic across thousands of networks.

See our Subnet Calculator for a more comprehensive subnet calculation tool, or the CIDR Converter to translate between CIDR notation and subnet masks.

Finding Network Prefix on Your Device

Windows

ipconfig

# Look for:
#   IPv4 Address: 192.168.1.100
#   Subnet Mask:  255.255.255.0
# Network prefix: 192.168.1.0/24

Linux / Mac

ip addr show
# or
ifconfig | grep -A 1 inet

# Output: inet 192.168.1.100/24
# The /24 directly tells you the prefix length

Pro Tip: On Linux, the ipcalc utility can compute the network prefix for you: ipcalc 172.16.45.200/20 displays the network address, broadcast, host range, and wildcard mask in one command. Install it with sudo apt install ipcalc on Debian/Ubuntu systems.

Common Mistakes with Network Prefixes

  1. Using the wrong subnet mask — if two devices on the same physical network have different masks, they may calculate different network prefixes and fail to communicate directly.
  2. Confusing network address with gateway — the network address (e.g., 192.168.1.0) is not usable by any host. The gateway is typically the first usable address (.1).
  3. Overlapping prefixes — when configuring VLANs, ensure each subnet's prefix does not overlap with another. Use this calculator to verify.
  4. Forgetting the broadcast address — the last address in a subnet is the broadcast address and cannot be assigned to a device.

Video Tutorial

Key Takeaways

  • The network prefix is calculated by ANDing the IP address with the subnet mask
  • Routers use the network prefix to determine where to forward packets
  • Focus on the interesting octet — where the mask is between 1 and 254
  • The block size (256 minus the mask value) tells you subnet boundaries
  • All devices on the same subnet must calculate the same network prefix
  • Longest prefix match is how routers select the best route for each packet

Related Tools & Guides

Frequently Asked Questions

What is the difference between a network address and a network prefix?

They are the same thing. The network address (or network prefix) is the result of performing a bitwise AND between an IP address and its subnet mask. It identifies the subnet, and the CIDR notation (like /24) indicates the prefix length — how many leading bits belong to the network portion.

Can I assign the network address to a device?

No. The network address (all host bits set to 0) is reserved to identify the subnet itself. It cannot be assigned to any device. Similarly, the broadcast address (all host bits set to 1) is reserved for sending messages to all devices on the subnet.

How does a router use the network prefix?

When a router receives a packet, it extracts the destination IP address, compares it against its routing table entries using the longest prefix match algorithm, and forwards the packet to the interface or next-hop address associated with the most specific matching prefix.

What happens if two devices have different subnet masks?

If two devices on the same physical network have mismatched subnet masks, they may calculate different network prefixes from their IP addresses. This causes one or both devices to believe the other is on a different subnet, forcing traffic through the gateway instead of communicating directly, or failing entirely.

What is the longest prefix match?

Longest prefix match is the routing algorithm that selects the most specific route for a destination. If a routing table has 10.0.0.0/8 and 10.1.0.0/16, a packet to 10.1.5.10 matches both, but the /16 route wins because it is more specific (longer prefix). This allows hierarchical routing and summarization.

How do I calculate the network prefix without a calculator?

For masks on octet boundaries (/8, /16, /24), just copy the masked octets and zero the rest. For other masks, find the interesting octet, subtract the mask value from 256 to get the block size, then find the largest multiple of the block size that is less than or equal to the IP octet value. That multiple is the network octet.

About Tommy N.

Tommy is the founder of RouterHax and a network engineer with 10+ years of experience in home and enterprise networking. He specializes in router configuration, WiFi optimization, and network security. When not writing guides, he's testing the latest mesh WiFi systems and helping readers troubleshoot their home networks.

Promotion for FREE Gifts. Moreover, Free Items here. Disable Ad Blocker to get them all.

Once done, hit any button as below