Skip to main content

Kullanım Kılavuzu

Calculating the number of hosts and subnets based on IP address and mask

IP addresses are used to identify devices on a network. To communicate with other devices on the network, an IP address must be assigned to each network device (including computers, servers, routers, printers, etc.). Such devices on a network are referred to as hosts.

A subnet mask determines the maximum number of hosts that can be supported on a particular network. In addition, subnet masks allow you to divide one network into several subnets.

Introduction to IP addresses

One part of the IP address is the network number (ID), and the other is the host ID. Just as different houses on the same street share the same street name in their address, hosts on a network have a common network number in their address. And just as different houses have their own house numbers, each host on the network has its own unique identification number - the host ID. The network number is used by routers to send packets to the correct networks, while the host ID identifies the specific device on that network to which packets should be delivered.

Structure

An IP address consists of four parts, written as decimal numbers with dots (e.g. 192.168.1.1). Each of these four parts is called an octet. An octet represents eight binary digits (e.g., 11000000 or 192 in decimal form).

Thus, each octet can take values from 00000000 to 11111111 in binary or 0 to 255 in decimal.

The following figure shows an example of an IP address where the first three octets (192.168.1) represent the network number, and the fourth octet (16) represents the host ID.

mask-01-en.png

The number of binary digits in the IP address that go to the network number and the number of digits in the address that go to the host ID can differ depending on the subnet mask.

Private IP addresses

Each host on the Internet must have a unique address. If your networks are isolated from the Internet (for example, linking two branch offices), you can easily use any IP address for the hosts. However, the Internet Assigned Numbers Authority (IANA) has reserved the following three blocks of IP addresses specifically for private networks:

  • 10.0.0.010.255.255.255

  • 172.16.0.0172.31.255.255

  • 192.168.0.0192.168.255.255

IP addresses on these private subnets are sometimes called 'local' addresses.

IP addresses can be obtained through IANA from your ISP, or you can assign them yourself from the private network address range.

Subnet masks

The subnet mask is used to determine which bits are part of the network number and which are part of the host ID (the logical conjunction operation 'AND' is used for this purpose).

The subnet mask includes 32 bits. If a bit in the subnet mask is '1', then the corresponding bit of the IP address is part of the network number. If a bit in the subnet mask is '0', the corresponding bit of the IP address is part of the host ID.

Tablo 4. Example of allocation of network number and host identifier in an IP address

1st octet: (192)

2nd octet: (168)

3rd octet: (1)

4th octet: (2)

IP address (binary)

11000000

10101000

00000001

00000010

Subnet mask (binary)

11111111

11111111

11111111

00000000

Network number

11000000

10101000

00000001

Host ID

00000010



Subnet masks always consist of a series of consecutive 1s, starting with the leftmost bit of the mask, followed by a series of consecutive zeros for a total of 32 bits.

A subnet mask can be defined as the number of bits in the address representing the network number (the number of bits with a value of '1'). For example, an '8-bit mask' is a mask in which 8 bits are ones, and the remaining 24 bits are zeros.

Subnet masks are written in decimal numbers with dots, just like IP addresses. The following examples show the binary and decimal notation of 8-bit, 16-bit, 24-bit, and 29-bit subnet masks.

Tablo 5. Subnet Masks

Binary 1st octet:

Binary 2nd octet:

Binary 3rd octet:

Binary 4th octet:

Decimal

8-bit mask

11111111

00000000

00000000

00000000

255.0.0.0

16-bit mask

11111111

11111111

00000000

00000000

255.255.0.0

24-bit mask

11111111

11111111

11111111

00000000

255.255.255.0

29-bit mask

11111111

11111111

11111111

11111000

255.255.255.248



Network size

The number of bits in the network number determines the maximum number of hosts that can be on such a network. The more bits in the network number, the fewer bits are left for the host ID in the address.

An IP address with a host ID of all zeros represents the IP address of the network itself (e.g., 192.168.1.0 with a 24-bit subnet mask). An IP address with a host ID of all ones represents that network's broadcast address (192.168.1.255 with a 24-bit subnet mask, for example).

Since such two IP addresses cannot be used as identifiers for individual hosts, the maximum possible number of hosts in the network is calculated as follows:

Tablo 6. Maximum possible number of hosts

Subnet mask

Host ID size

Maximum number of hosts

8 bit

255.0.0.0

24 bit

224 – 2

16777214

16 bit

255.255.0.0

16 bit

216 – 2

65534

24 bit

255.255.255.0

8 bit

28 – 2

254

29 bit

255.255.255.248

3 bit

23 – 2

6



Recording format

Since the mask is always a sequence of units to the left complemented by a series of zeros up to 32 bits, it is possible to simply specify the number of units rather than write the value of each octet. This is usually written as a '/' after the address and the number of unit bits in the mask.

For example, a 192.1.1.0 /25 address represents a 192.1.1.0 address with a mask of 255.255.255.128. Some possible subnet masks in both formats are shown in the following table.

Tablo 7. Alternative format for writing the subnet mask

Subnet mask

Alternative recording format

Last octet (binary)

Last octet (decimal)

255.255.255.0

/24

0000 0000

0

255.255.255.128

/25

1000 0000

128

255.255.255.192

/26

1100 0000

192

255.255.255.224

/27

1110 0000

224

255.255.255.240

/28

1111 0000

240

255.255.255.248

/29

1111 1000

248

255.255.255.252

/30

1111 1100

252



Making subnets

Subnets can be used to divide a single network into multiple networks. In the example below, the network administrator creates two subnets to isolate a group of servers from other devices for security purposes.

In this example, the company network has an address of 192.168.1.0. The first three octets of the address (192.168.1) represent the network number, and the remaining octet represents the host ID, allowing a maximum of 28 - 2 = 254 hosts on the network.

The company's network, before it was divided into subnets, is shown in the following diagram.

mask-02-en.png

To split the 192.168.1.0 network into two separate subnets, you can 'borrow' one bit from the host ID. In this case, the subnet mask will become 25-bit (255.255.255.128 or /25).

The 'borrowed' bit of the host ID can be either zero or one, which gives us two subnets: 192.168.1.0 /25 and 192.168.1.128 /25.

The company network, after it has been divided into subnets, is shown in the following figure. It now includes two subnets, A and B.

mask-03-en.png

In a 25-bit subnet, 7 bits are allocated to the host ID, so each subnet can have a maximum of 27 - 2 = 126 hosts (the host ID of all zeros is the subnet itself, and of all ones is the broadcast address for the subnet).

The address 192.168.1.0 with mask 255.255.255.128 is the address of subnet A, and 192.168.1.127 with mask 255.255.255.128 is its broadcast address. Thus, the smallest IP address that can be assigned to a valid host on subnet A is 192.168.1.1, and the largest is 192.168.1.126.

Similarly, the host ID range for subnet B is 192.168.1.129 to 192.168.1.254.

Example: four subnets

The previous example showed the use of a 25-bit subnet mask to divide a 24-bit address into two subnets. Similarly, dividing a 24-bit address into four subnets would require 'borrowing' two bits of the host ID to get four possible combinations (00, 01, 10, and 11). The subnet mask consists of 26 bits (11111111.11111111.11111111.11000000), that is 255.255.255.192.

Each subnet contains 6 bits of host ID, giving a total of 26 - 2 = 62 hosts for each subnet (the host ID of all zeros is the subnet itself, and of all ones is the broadcast address for the subnet).

Tablo 8. Subnet 1

IP address/subnet mask

Network number

Last octet value

IP address (decimal)

192.168.1.

0

IP address (binary)

11000000.10101000.00000001.

00000000

Subnet mask (binary)

11111111.11111111.11111111.

11000000

Subnet address 192.168.1.0

Smallest host ID: 192.168.1.1

Broadcast address 192.168.1.63

Largest host ID: 192.168.1.62



Tablo 9. Subnet 2

IP address/subnet mask

Network number

Last octet value

IP address (decimal)

192.168.1.

64

IP address (binary)

11000000.10101000.00000001.

01000000

Subnet mask (binary)

11111111.11111111.11111111.

11000000

Subnet address 192.168.1.64

Smallest host ID: 192.168.1.65

Broadcast address 192.168.1.127

Largest host ID: 192.168.1.126



Tablo 10. Subnet 3

IP address/subnet mask

Network number

Last octet value

IP address (decimal)

192.168.1.

128

IP address (binary)

11000000.10101000.00000001.

10000000

Subnet mask (binary)

11111111.11111111.11111111.

11000000

Subnet address 192.168.1.128

Smallest host ID: 192.168.1.129

Broadcast address 192.168.1.191

Largest host ID: 192.168.1.190



Tablo 11. Subnet 4

IP address/subnet mask

Network number

Last octet value

IP address (decimal)

192.168.1.

192

IP address (binary)

11000000.10101000.00000001.

11000000

Subnet mask (binary)

11111111.11111111.11111111.

11000000

Subnet address 192.168.1.192

Smallest host ID: 192.168.1.193

Broadcast address 192.168.1.255

Largest host ID: 192.168.1.254



Example: eight subnets

Similarly, a 27-bit mask (000, 001, 010, 011, 100, 101, 110, and 111) is used to create eight subnets.

The values of the last octet of the IP address for each subnet are shown in the following table.

Tablo 12. Eight subnets

Subnet

Subnet address

First address

Last address

Broadcast address

1

0

1

30

31

2

32

33

62

63

3

64

65

94

95

4

96

97

126

127

5

128

129

158

159

6

160

161

190

191

7

192

193

222

223

8

224

225

254

255



Subnetwork planning

The following table summarises the subnet planning for a network with a 24-bit network number.

Tablo 13. Subnetwork planning for a 24-bit numbered network

Number of 'borrowed' bits of the host ID

Subnet mask

Number of subnets

Number of hosts in a subnet

1

255.255.255.128 (/25)

2

126

2

255.255.255.192 (/26)

4

62

3

255.255.255.224 (/27)

8

30

4

255.255.255.240 (/28)

16

14

5

255.255.255.248 (/29)

32

6

6

255.255.255.252 (/30)

64

2

7

255.255.255.254 (/31)

128

1



An example of calculating the number of subnets and hosts in a subnet based on IP address and subnet mask

Here is an example of calculating the number of subnets and hosts for the network 59.124.163.151/27.

/27 is the network prefix or netmask. In binary format 11111111 11111111 11111111 11100000. In decimal format, 255.255.255.224

In the fourth field (last octet) of 11100000, the first 3 bits define the number of subnets; in our example, 23 = 8.

In the fourth field (last octet) 11100000, the last 5 bits define the number of subnet hosts; in our example, 25 = 32.

The IP range of the first subnet is 0~31 (32 hosts), but 0 is a subnet, and 31 is for broadcast. Thus, the maximum number of hosts of this subnet is 30. First subnet: 59.124.163.0. Broadcast address of the first subnet: 59.124.163.31.

IP range of the second subnet is 59.124.163.32 to 59.124.163.63. Second subnet: 59.124.163.32. Broadcast address of the second subnet: 59.124.163.63.

We can calculate the IP range of the eighth subnet from 59.124.163.224 to 59.124.163.255. Eighth subnet: 59.124.163.224. Broadcast address of the eighth subnet: 59.124.163.255.

In our example, the IP address 59.124.163.151 is on the fifth subnet. Fifth subnet: 59.124.163.128/27. The IP range of the fifth subnet is 59.124.163.128 to 59.124.163.159. Broadcast address of the fifth subnet: 59.124.163.159.

Önemli

For convenience in calculating subnet IP addresses and network masks, there are special online IP calculators (e.g. https://ipnet.tools/ip-calculator), as well as free programs/utilities for quick and easy calculation.