# How do you calculate the prefix, network, subnet, and host numbers?

Now let’s take a little technical approach;

Each system on the network that communicates must have an IP address. IP addressing is used according to the routing layer (layer 3) of the TCP / IP protocol cluster.

## IPv4 – IP (Internet Protocol) Addresses

IP addresses (in IPv4) are 32-bit numbers. These numbers are divided into four 8-bit segments for ease of writing and display, as well as the ease of network management. I’m going to call each of these parts Octet later in my article.

Each part can be a number between 1 and 255. In order for numbers to be between 1 and 255, it is necessary to set the value 1 to 0. The values ​​of 1 also have mathematical equivalents and sum corresponding to these equivalents. These totals give us IP addresses and Subnet Masks.

If you need to open this logic a little more; We have an IP address that is reserved for four Octet 8 bits and has not yet been assigned value.

1.OCTET2.OCTET3.OCTET4.OCTET
00000000000000000000000000000000

Taking the first octet of this, over 00000000. part;

0 value to 1 by assigning a value of 255 ‘ll go up to the upper limit.

00000000
oneoneoneoneoneoneoneone
128643216842ndone

128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

The sum of these numbers with each other will give the following result, respectively:

128 = 128
+ 64 = 192
+ 32 = 224
+ 16 = 240
+ 8 = 248
+ 4 = 252
+ 2 = 254
+ 1 = 255

• The values ​​of 1 corresponding to the values ​​of 0 will be the parts we will add to the collection, which will give us the numerical equivalent on the corresponding Octet of the corresponding IP address.
• Accordingly, the Binary equivalent of 192.168.20.10 Decimal Ip is as follows.

1.OCTET

1 1 0 0 0 0 0 = 192
128 64 32 16 8 4 2 1

2.OCTET

1 0 1 0 1 0 0 = 168
128 64 32 16 8 4 2 1

3.OCTET

0 0 0 1 0 1 0 0 = 20
128 64 32 16 8 4 2 1

4.OCTET

0 0 0 0 1 0 1 0 = 10
128 64 32 16 8 4 2 1

I have obtained the value I want by summing the 1 value fields. If I set all 0 to 1, then I ‘ll have 255.

My reason for explaining this logic was to explain the logic of the IP addresses by which these values ​​are obtained. I will also use this logic when we move to the subnetting section.

Now, let’s take a look at IP ranges :

Class A IP Range :

1.0.0.0 –
126.255.255.255 IPs with 127 are used for testing purposes. This is called the LOOPBACK IP.
For example; 127.0.0.1 is the local IP address.

Class B IP Range :

128.0.0.0 -191.255.255.255

Class C IP Range :

192.0.0.0 – 223.255.255.255

Class D IP Range :

224.0.0.0 -239.255.255.255 Available for multicast-enabled hosts.

Class E IP Range :

240.0.0.0 -255.255.255.255
Dedicated  IP range.

These IP ranges from 1.0.0.0 to 223.255.255.255 are used in the Internet environment, ie the Public IP range.
These IPs are divided into Public (Internet) and Private (LAN) IP addresses. The reason for the two separate is that the IP addresses do not conflict with each other. To prevent this operation, it is important to use IPs in the private IP range that are set as a standard in the LAN environment.

LAN environment, that can be distributed in the internal network IP Ranges ( Private IP ):

Class A IP Range :

10.0.0.0 – 10.255.255.255

Class B IP Range :

172.16.0.0 -172.31.255.255

Class C IP Range :

192.168.0.0 – 192.168.255.255

The IP limits and ranges outside the Private IP class and ranges mentioned above are the Public IP ranges and Public IP Ranges used in the WAN ( Wide Area Network ) environment, ie the external network.

I have given the IP ranges above that can be deployed in the LAN environment, ie inside. Now, let’s take a look at the Subnet Mask values according to the classes of these ips.

IP addresses; the address of each house is Subnet Mask; these are the structures that determine the neighborhoods of these houses. Every neighborhood child can only talk to those in their neighborhood, which is what is desired when building network structures. So with the subnet mask, we do network partitions, which comes from the concept of subnetting.

Subnet Mask Provisions of IP Classes:

255 .0.0.0

255. 255 .0.0

255.255. 255 .0

These are the default subnet masks of their classes.

Subnet Masks tell us how many houses will be located in a neighborhood when determining the neighborhoods of the houses, ie creating networks. I mean the number of hosts in a network.

Host Number of Subnet Masks, Host Calculation:
As we go through step by step, before building our neighborhoods, let’s take a look at how many houses will be available in our neighborhoods, ie the number of hosts that can be accommodated in the network:

Information: As the value of 255 falls within their class, the number of hosts they hosts increases.

255.0.0.0 Number of Hosts: 16,777,214
11111111.00000000000000000.00000000 / 8254 .0.0.0 Hos Number: 33,554,430
1111111 0.00000000.00000000.00000000 / 7

252 .0.0.0 Number of Hosts: 67,108,862
111111 00.00000000.0000000000000000 / 6

248 .0.0.0 Number of Hosts: 134,217,726
11111 000,000,000,000,000,000,000,000,000 / 5

240 .0.0.0 Number of Hosts: 268,435,454
1111 0000.00000000.00000000.00000000 / 4

224 .0.0.0 Host Total: 536,870,910
111 00000.00000000.00000000.00000000 / 3

192 .0.0.0 Number of Hosts: 1,073,741,822
11 000,000,000,000,000,000,000,000,000,000 / 2

128 .0.0.0 Number of Hosts: 2,147,483,648
1 0000000,0000000000000000000000 / 1

255.255.0.0 Number of Hosts: 65,534
11111111.11111111.00000000000000000 / 16

255. 254 .0.0 Host Number: 131,070
11111111. 1111111 0.00000000.00000000 / 15

255. 252 .0.0 Number of Hosts: 262,142
11111111. 111111 00.00000000.00000000 / 14

255. 248 .0.0 Number of Hosts: 524,286
11111111. 11111 000.00000000.00000000 / 13

255 240 .0.0 Host Count: 1,048,574
11111111. 1111 0000.00000000.00000000 / 12

255. 224 .0.0 Number of Hosts: 2,097,150
11111111. 111 00000.00000000000000 / 11

255 192 .0.0 Host Count: 4,194,302
11111111. 11 000000.00000000.00000000 / 10

255 128 .0.0 Host Count: 8,388,606
11111111. 1 0000000.00000000.00000000 / 9

255.255. 255.0 Host Number: 254
11111111.11111111. 11111111.00000000 / 24

255 255. 254 .0 Host Number: 510
11111111.11111111. 1111111 0.00000000 / 23

255 255. 252 .0 Host Number: 1022
11111111.11111111. 111111 00.00000000 / 22

255 255. 248 .0 Host Number: 2046
11111111.11111111. 11111 000.00000000 / 21

255 255. 240 .0 Host Number: 4094
11111111.11111111. 1111 0000.00000000 / 20

255 255. 224 .0 Host Number: 8190
11111111.11111111. 111 00000.00000000 / 19

255 255. 192 .0 Host Number: 16,382
11111111.11111111. 11 000000.00000000 / 18

255 255. 128 .0 Host Number: 32,766
11111111.11111111. 1 0000000.00000000 / 17

255.255.255. 255Host: 0
11111111.11111111.11111111. 11111111 /32

255 255 255. 254 Number of
Hosts : 0 11111111.11111111.11111111. 1111111 0/31

255 255 255. 252 Host: 2
11111111.11111111.11111111. 111111 00/30

255 255 255. 248 Host: 6
11111111.11111111.11111111. 11111 000/29

255 255 255. 240 Host Count: 14
11111111.11111111.11111111. 1111 0000/28

255 255 255. 224 Host Count: 30
11111111.11111111.11111111. 111 00000/27

255 255 255. 192 Host: 62
11111111.11111111.11111111. 11 000000/26

255 255 255. 128 Host Count: 126
11111111.11111111.11111111. 1 0000000/25

You can see this more clearly in the table below, which is a summary of the host numbers of the subnet masks I have prepared above.

Ex: We can

host 254 hosts in a Class C Subnet Mask (255.255.255.0). If we need a host number of more than 254, eg 500;

255.255.255.0 Subnet Mask ‘s 11111111.11111111.11111111. We need to play with the binary values ​​of 00000000.

11111111.111111111111111111.00000000 We convert the last value from 1 in 3 Octet to 0 in binary values.

So we have 23 bits left.
11111111.11111111.1111111 0 .00000000 = 23 bits.
The remaining 0 values ​​give us the number of hosts we can use. Let’s take a look at how we reach these host number values;

The element in determining the host numbers of subnet masks is that the sum of the 0 values ​​available is found by the formula [2 n -2].

Ex: For

255 .0.0.0
11111111 .000000000000000000000000000

the sum of the 0 values ​​at hand is 24 bits.
2 24 -2 = 16,777,214 Host

The formula [2 n -2] always gives us the total number of hosts .

Other Subnet masks tell us the number of inhabitants that they can host in their neighborhoods, that is, the number of hosts. We will also benefit from this system when performing subnetting.

## CIDR Notation

Subnet Mask in a well / 8 /16 and / 24 must have attracted your attention. These notation formats are called CIDR (Classless Inter-Domain Routing) Notation.

“/” Slashtan subsequent decimal value, Subnet Mask ‘Taki1 values represent. Don’t confuse it with the0 values mentioned above.

A value of 0 gives the total number of HOSTs in that subnet mask.

Values ​​of 1 specify NETWORK addresses.

In addition to the determination of network addresses, it also provides the subnetting structure, ie creating different networks within a network by dividing large networks into subnets.

Ex.

10.10.5.100 / 8

In the display, / 8 indicates the value of 1 in the 8 Subnet Mask. This tells us that only 8 bits are used in the 1st octet in a 4-Octet structure with a 32-bit value.

I have specified the default Subnet Mask of this class A above.
255 .0.0.0

Here, the value of 255 in the first octet comes from the sum of 8 bits, which I showed at the beginning of my article the mathematical calculation of them, but I rewrite them for recall.

255 .0.0.0
11111111 .00000000.00000000.00000000 / 8
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

The remaining 0 values, as I mentioned above, give us the total number of HOSTs.
So in summary before the neighborhood was created. Then the number of people living in that neighborhood appeared.

the sum of the 0 values ​​at hand is 24 bits.
2 24 -2 = 16,777,214 Host

Network: 255.0.0.0
to Host Hosted Count: 16,777,214

Ex.

10.50.15.90 / 5
248 .0.0.0

Here, 248 in the first octet comes from the sum of 5 bits.

248 .0.0.0
11111 000.00000000.00000000.00000000 / 5
128th + 64 + 32 + 16 + 8 + 0 + 0 + 0 = 248

the sum of the 0 values ​​at hand is 27 bits.
2 27 -2 = 134,217,726 Host

Network: 248.0.0.0
Number of Hosts to Host: 134,217,726

IMPORTANT: You do not have to use a Class A Subnet Mask again for a class A ip address . You can also use a B or C class Subnet mask for a class A ip address .

Ex.

10.50.15.90 24/
255 .255.255.0

11111111.11111111.11111111 .00000000 / 24

the sum of the 0 values ​​at hand is 8 bits.
2 8 -2 = 254 Hosts

Network: 255.255.255.0
Number of Hosts to Host: 254

Ex.

10.50.15.90 / 14
255 .252.0.0

11111111.111111 00.00000000.00000000 / 14

the sum of the 0 values ​​at hand is 18 bits.
2 18 -2 = 262,142 Hosts

Network: 255.252.0.0
Number of Hosts to Host: 262,142

## Subnetting – Dividing the Subnet

Practice 1:

We have an IP of 192.168.10.0 /24. The subnet mask for this IP will be 255.255.255.0. While partitioning into sub-networks, in this SubNetMask ( subnet ) only we can play on the field of 0. Accordingly, I want to divide my IP into 15 separate networks.

192.168.10.0 / 24
255.255.255. 0
24 = 11111111.11111111.11111111. 00000000
2 8 -2 = 254 (host)

The formula [2 n ] always gives us the total number of networks in a network and is divided from left to right.
The remaining values ​​of 0 indicate the number of hosts to be hosted on the network, which is calculated by theformula[2 n -2].

Counting from left to right, I will reach 15 networks.

. 1111 0000 (4th Octet)
2 1 = 2
2 2 = 4
2 3 = 8
2 4 = 16 (because I want 15 networks, I cut 4 bits values.)
2 4 -2 = 14 (total for each network) Shoo)

. 1 1 1 1 0 0 0 0
2 n
2 1 2 2 2 3 2 4

.1 1 1 1 0 0 0 0
2 n -2
2 4 2 3 2 2 2 1

255.255.255. 240

11111111.11111111.11111111. 111 1 0000

IMPORTANT NOTE: As networks grow, the range of the last 1 is checked. Accordingly, the networks in this example will grow by 16 each.

Reminder: Bits 128-64-32-16-8-4-2-1 sees the form.

1 1 1 1 0 0 0 0
128 64 32 16 8 4 2 1

NETWORKS:

1. Network:

192.168.10. 0/28
192.168.10. 15th/ 28th
NET ID:192.168.10. 0
IP Range:192.168.10. 1– 192.168.10. 14

192.168. 10.1
192.168. 10.2
192.168. 10.3
192.168. 10.4
192.168. 10.5
192.168. 10.6
192.168. 10.7
192.168. 10.8
192.168. 10.9
192.168. 10.10
192.168. 10.11
192.168. 10.12
192.168. 10.13
192.168. 10:14

## Provisioning | AND process

AND, in other words, checksum, is a proof of which network the corresponding IP address belongs to. It shows which network an IP address belongs to, and thus shows whether we are subnetting correctly.

Practice 1:

192.168. 10.1 – 192.168. 192.168 in the IP range of 10.14 . The first Network of 10.10 / 24 IP is 192.168. 10. Let’s see that 0 belongs to the network ID ;

First of all , I get the binary values ​​of the IP 192.168.10.10 ;

11 000000. 1 0 1 0 1 000.0000 1 0 1 0.0000 1 0 1 0

255 . 255 . 255 . I get the binary values ​​of the 240 subnet mask;

11111111 . 11111111 . 11111111 . 1111 0000

I’m doing this by putting these binary values ​​one by one;

When making checks, the rule will always be as follows;

1 + 1 = 1
0 + 1 = 0
1 + 0 = 0

11 000000. 1 0 1 0 1 000.0000 1 0 1 0.0000 1 0 1 0
11111111 . 11111111 . 11111111 . 1111 0000

__________________________________
11 000000. 1 0 1 0 1 000.0000 1 0 1 0 .00000000

192.168.10. 0

192.168 with this checksum. The 10th IP of Network 1 is 192.168. 10. We’ve proven that by making sure that it belongs to 0 network ID .

2. Network:

192.168.10. 16th / 28th
192.168.10. 31 / 28th
NET ID: 192.168.10. 16
IP Range: 192.168.10. 17 – 192.168.10. 30

3. Network:

192.168.10. 32nd / 28th
192.168.10. 47th / 28th
NET ID: 192.168.10. 32
IP Range: 192.168.10. 33 – 192.168.10. 46

4. Network:

192.168.10. 48 / 28th
192.168.10. 63 /28
NET ID: 192.168.10. 48
IP Range: 192.168.10. 49 – 192.168.10. 62

5. Network:

192.168.10. 64 /28
192.168.10. 79 / 28th
NET ID: 192.168.10. 64
IP Range: 192.168.10. 65 – 192.168.10. 78

15. Network:

192.168.10. 224 /28
192.168.10. 239th / 28th
NET ID: 192.168.10. 224
IP Range: 192.168.10. 225 – 192.168.10. 238

Practice 2:

We have an IP of 192.168.16.0/16. The subnet mask for this IP will be 255.255.0.0. When partitioning subnets, we can manipulate the 0 fields on the 3rd OCTET on this subnet mask. Accordingly, I want to divide my IP into 16 separate networks.

192.168.16.0/16
255. 255.0.0
11111111. 11111111. The host of 00000000.00000000 / 16
2 16 -2 = 65,534

Since I’m going to play on the 0’s field in the 3rd OCTET when dividing it into subnets, I’m starting to separate it from left to right in the 0’s field in the 3OCTET;
.00000000.00000000
2 1 = 2
2 2 = 4
2 3 = 8
2 4 = 16 (exactly the number of networks I want to divide. No garbage network.)

3. Since I have allocated 4 bits on the 0 field in the OCTET, I set the values ​​of 0 to 1. If you remember, 1 was the Network and 0 was the Host.

. 1111 0000 .00000000

255. 255. 240 .0
11111111. 11111111. 1111 0000 .00000000 / 20

Accordingly, the total Host I have:
2 12 -2 = 4094

NOTE: 3. Since we are playing on the 0 fields in the OCTET, our new subnet mask becomes a class C subnet mask.

3. When we look at the range of the last 1 in OCTET, we can see that the networks we subdivided into 16 will grow by 16, which I also mentioned in our first example.

NETWORKS:

Networks to be Distributed:
0,16,32,48,64,80,96,112,128,144,160,176,192,208,224,240

1.Network:

192.168. 0.0 / 20
192.168. 15.255 / 20
NET ID: 192.168. 0.0
IP Range: 192.168. 0.1 to 192.168. 15 254

192.168. 0.1 to 192.168. 0.254
192.168. 1.1 to 192.168. 1,254
192,168. 2.1 to 192.168. 2,254
192,168. 3.1 to 192.168. 3,254 192,168
. 4.1 to 192.168. 4,254
192,168. 5.1 – 192.168. 5,254
192,168. 6.1 to 192.168. 6,254
192,168. 7.1 – 192.168. 7.254
192.168. 8.1 – 192.168. 8,254
192,168. 9.1 – 192.168. 9,254
192,168. 10.1 – 192.168. 10,254
192.168. 11.1 – 192.168. 11.254
192.168. 12.1 – 192.168. 12.254
192.168. 13.1 – 192.168. 13.254
192.168. 14.1 – 192.168. 14.254
192.168. 15.1 – 192.168. 15 254

IMPORTANT INFORMATION: I will be providing this information according to 1.Network. The same rule applies to other remaining networks.

This IP range is 192.168. 0 .1- 192.168. The 15-15 range between 0-15 has caught your attention and may have confused you, often witnessing confusion. The situation here is as follows;

First of all, the Network ID of the 1st Network is 192.168. It’s 0.0. I divided the total of 65,534 hosts I have into 16 separate networks and divided each network equally into 4094 hosts.

Since 4094 hosts will be assigned to each network and I can assign up to 254 hosts on the host side, for example; 192.168. 192.168 on 0.0 network. Starting at 0.1, 192.168. When I gave up to 0.254, I used the first 254 of the 4094 hosts.

254, since 192.168 is the last value I can give for the host. 192.168 after 0.254. 1.1 continuing from IP 192.168. I’m assigning 254 more hosts up to 1,254.

I’m doing 16 more steps like this, and ultimately 192.168. 15.254 ‘to continue and end. So, I’m creating 16 separate IP blocks in 16 separate networks so that each network has a total of 4094 hosts.

In total, Ex. When we calculate the total number of hosts in 1.Network;

254 * 16 = 4064 (Net ID and Broadcast IP not accounted)
+16 = 4080 (Net ID is included, Broadcast IP not accounted)
+16 = 4096 (Net ID and Broadcast) IP account)

We see it in shape. Now let’s continue from Network 2 to the last network;

2.Network:

192.168. 16.0 / 20
192.168. 31.255 / 20
NET ID: 192.168. 16.0
IP Range: 192.168. 16.1 – 192.168. 31 254

192.168. 16.1 – 192.168. 16.254
192.168. 17.1 – 192.168. 17.254
192.168. 18.1 – 192.168. 18.254
192.168. 19.1 – 192.168. 19.254
192.168. 20.1 – 192.168. 20.254
192.168. 21.1 to 192.168. 21.254
192.168. 22.1 – 192.168. 22.254
192.168. 23.1 – 192.168. 23.254
192.168. 24.1 – 192.168. 24.254
192.168. 25.1 to 192.168. 25.254
192.168. 26.1– 192.168. 26.254
192.168. 27.1 – 192.168. 27.254
192.168. 28.1 – 192.168. 28.254
192.168. 29.1 – 192.168. 29.254
192.168. 30.1 – 192.168. 30.254
192.168. 31.1 – 192.168. 31.254

3.Network:

192.168. 32.0 / 20
192.168. 47.255 / 20
NET ID: 192.168. 32.0
IP Range: 192.168. 32.1 – 192.168. 47 254

192.168. 32.1 – 192.168. 32.254
192.168. 33.1 – 192.168. 33.254
192.168. 34.1 – 192.168. 34.254
192.168. 35.1 – 192.168. 35.254
192.168. 36.1 – 192.168. 36.254
192.168. 37.1 – 192.168. 37.254
192.168. 38.1 – 192.168. 38.254
192.168. 39.1 – 192.168. 39.254
192.168. 40.1 – 192.168. 40.254
192.168. 41.1 – 192.168. 41.254
192.168. 42.1– 192.168. 42.254
192.168. 43.1 – 192.168. 43.254
192.168. 44.1 – 192.168. 44.254
192.168. 45.1 – 192.168. 45.254
192.168. 46.1 – 192.168. 46.254
192.168. 47.1 – 192.168. 47.254

4.Network :

192.168. 48.0 / 20
192.168. 63.255 / 20
NET ID: 192.168. 48.0
IP Range: 192.168. 48.1 – 192.168. 63 254

192.168. 48.1 – 192.168. 48.254
192.168. 49.1 – 192.168. 49.254
192.168. 50.1 – 192.168. 50.254
192.168. 51.1 – 192.168. 51.254
192.168. 52.1 – 192.168. 52.254
192.168. 53.1 – 192.168. 53.254
192.168. 54.1 – 192.168. 54.254
192.168. 55.1 – 192.168. 55.254
192.168. 56.1 – 192.168. 56.254
192.168. 57.1 – 192.168. 57.254
192.168. 58.1 – 192.168.58.254
192.168. 59.1 – 192.168. 59.254
192.168. 60.1 – 192.168. 60.254
192.168. 61.1 – 192.168. 61.254
192.168. 62.1 – 192.168. 62.254
192.168. 63.1 – 192.168. 63.254

5.Network :

192.168. 64.0 / 20
192.168.79.255/20
NET ID: 192.168. 64.0
IP Range: 192.168. 64.1 – 192.168. 79.254

6.Network :

192.168. 80.0 / 20
192.168. 95.255 / 20
NET ID: 192.168. 80.0
IP Range: 192.168. 80.1 – 192.168. 95.254

7.Network :

192.168. 96.0 / 20
192.168. 111.255 / 20
NET ID: 192.168. 96.0
IP Range: 192.168. <Strong96.1 – 192.168. 111.254

8.Network :

192.168. 112.0 / 20
192.168. 127.255 / 20
NET ID: 192.168. 112.0
IP Range: 192.168. 112.1 – 192.168. 127.254

9.Network :

192.168. 128.0 / 20
192.168. 143.255 / 20
NET ID: 192.168. 143.0
IP Range: 192.168. 143.1-1 192.168. 143.254

10.Network :

192.168. 144.0 / 20
192.168. 159.255 / 20
NET ID: 192.168. 144.0
IP Range: 192.168. 144.1 – 192.168. 159.254

11.Network :

192.168. 160.0 / 20
192.168. 175.255 / 20
NET ID: 192.168. 160.0
IP RANGE: 192.168. 160.1 – 192.168. 175.254

12.Network :

192.168. 176.0 / 20
192.168. 191.255 / 20
NET ID: 192.168. 176.0
IP Range: 192.168. 176.1 – 192.168. 191.254

13.Network :

192.168. 192.0 / 20
192.168. 207.255 / 20
NET ID: 192.168. 192.0
IP Range: 192.168. 192.1 – 192.168. 207.254

14.Network :

192.168. 208.0 / 20
192.168. 223.255 / 20
NET ID: 192.168. 208.0
IP Range: 192.168. 208.1 – 192.168. 223.254

15.Network :

192.168. 224.0 / 20
192.168. 239.255 / 20
NET ID: 192.168. 224.0
IP Range: 192.168. 224.1 – 192.168. 239.254