IP Addresses and Subnet Masks: How to Calculate Network Range?

Imagine that you have just moved into a new community and want to know which block your house belongs to and which neighbors are in the same area as you. The relationship between IP address and subnet mask is like that between block and house, which determines which devices can communicate directly and which devices need to communicate through a "gateway".

1. Basic concepts of IP address and subnet mask
1. What is an IP address
An IP address (Internet Protocol Address) is a unique identifier for a network device, just like the address of each house. Currently, the common IP versions are IPv4 and IPv6. We mainly discuss IPv4 here.


An IPv4 address consists of four groups of numbers between 0-255, for example:

Each part is 8 bits, and the entire IP address is 32 bits, which is used to uniquely identify the device in the network.

2. What is a subnet mask?
The subnet mask is used to divide the network part and the host part of the IP address. Its format is similar to that of an IP address, for example:
In binary, it distinguishes the network address from the host address, where:

255 represents the network portion (cannot be changed).

0 represents the host portion (can be assigned to a device).
2. Method for calculating network range
Determine network address: Network address is the result of bitwise AND of IP address and subnet mask. As follows:
Determine the available IP address range
The first IP address (network address): unavailable, representing the network itself, 192.168.1.0.
The last IP address (broadcast address): used to transmit data to all devices in the network, 192.168.1.255.
Available IP address range: network address + 1 to broadcast address - 1, 192.168.1.1 - 192.168.1.254.
3. Advanced calculation of subnet division
If the subnet mask is not the standard /24, but /26, how do we calculate it?
Question: 192.168.1.10/26 (subnet mask: 255.255.255.192), belongs to which subnet?

Calculation steps:

(1) The binary number corresponding to 255.255.255.192 is 11111111.11111111.11111111.11000000. It can be seen that the last 6 bits are used for the host, that is, 2^6 = 64 addresses.

(2) Network address increment = 256 - 192 = 64.

(3) Possible subnet divisions:


192.168.1.0 - 192.168.1.63
192.168.1.64 - 192.168.1.127
192.168.1.128 - 192.168.1.191
192.168.1.192 - 192.168.1.255
(4) If the IP address is 192.168.1.10, it belongs to the 192.168.1.0/26 subnet.

Network address: 192.168.1.0
Broadcast address: 192.168.1.63
Available IP address range: 192.168.1.1 - 192.168.1.62