What is a subnet mask
Host addresses with binary numbers that are all "0" and "1" cannot be used, so the IP addresses that can be used are as follows.
Class A ・・・ 2 24 - 2 = 16,777,214
Class B ・・・ 2 16 - 2 = 65,534
Class C ・・・2 8 - 2 = 254
Using the entire Class C IP address and allocating it to 254 devices may not be a problem, but it is not very desirable in terms of broadcast issues and bandwidth sharing within the segment.
Furthermore, with 65,534 Class B terminals and 16,777,214 Class A terminals, it seems that there are not many such large-scale networks in the world, and if there are so many terminals in one segment, congestion will occur. will occur.
So what if you don't use all the addresses in the class, just some and not the rest?
Suppose in class A, only 100 were used. The rest, 16,777,114, are wasted.
Suppose in class B, only 100 were used. The rest, 6,5434, are wasted.
Let's say in class C you used only 100. The rest, 154, are wasted.
This not only wastes valuable IP addresses, but also leads to exhaustion of IP addresses in no time.
To solve this problem, there is something called a subnet mask.
A subnet mask allows you to divide a single network address into multiple networks. These divided networks are called subnets.
By dividing a single network address into appropriate sizes and allocating them, network efficiency and operability can be improved.
default subnet mask
A subnet mask is used to indicate the dividing position between the network address part and the host address part on the IP address.
Then, how to indicate the position of the partition between the network address part and the host address part, create a subnet mask according to the following rules.
Network part ・・・ 1
Host part ・・・ 0
A subnet mask consists of 32 bits, just like an IP address.
For example, the default subnet mask for a Class C IP address, "192.168.123.45" would be:
The default Class C network address is the 24 bits of the upper 3 octets.
Set its 24 bits to '1'.
The default host address for class C is the last 8 bits of the octet.
Set those 8 bits to '0'.
So the default subnet mask for '192.168.123.45' would be '255.255.255.0'.
By the way, the default subnet mask for each class is as follows.
- Class A ・・・ 255.0.0.0
- Class B ・・・ 255.255.0.0
- Class C ・・・ 255.255.255.0
A subnet mask is a sequence of '1's and '0's.
It will not be like "10101010". Followed by a '1' followed by a '0'.
However, it is not very efficient if the subnet mask can only use the default subnet mask. This is because it is more efficient and easier to operate by allocating network addresses of an appropriate size to the network.
Subnetting will be explained using class B network addresses.
Class B has a network address in the first 16 bits and a host address in the remaining 16 bits. Taking a class B address as an example, the first 16 bits are the network address, the remaining 16 bits are the host address, and the boundary between the 16th and 17th bits is the boundary between the network address and the host address.
There are 65,534 class B host addresses.
Class B ・・・ 2 16 -2 = 65,534
When the host address does not need even 16 bits, the boundary between the network address and the host address is shifted to the host address side, and the network address part is extended.
These divided networks are called subnets.
If you shift 8 bits to the host address side, it will look like the figure below.
For example, the network address "220.127.116.11" is a large Class B network address with a default subnet mask of "255.255.0.0" and a host count of 65,534.
By changing from "255.255.0.0" to "255.255.255.0",
Eight bits are reserved for the number of bits in the subnet address part.
There are 256 different 8-bit combinations from 0 to 255.
2 8 = 256 types
To make it easier to understand, let's represent the divided subnets in the diagram below.
By borrowing 8 bits from the host address and extending the network address, it is divided into 256 subnet divisions.
18.104.22.168/24 (0th subnet)
22.214.171.124/24 (1st subnet)
126.96.36.199/24 (2nd subnet)
188.8.131.52/24 (255th subnet)
One subnet has 256 (2 8 ) host addresses. * 254 can be allocated to the terminal.
Subnetting in this way makes it possible to create subnets that match the scale of the network.
The notation "/24" will be explained later in "Subnet mask (CIDR notation)".
Subnet mask/CIDR notation
The method of writing a subnet mask using forward slashes (/) is called CIDR notation. Write the number of 1s in the subnet mask to the right of "/" and add it to the right of the IP address.
Example of how to write)
Subnet mask "255.0.0.0" → "/8"
subnet mask "255.255.0.0" → "/16"
subnet mask "255.255.255.0" → "/24"
subnet mask "255.255.255.240" → "/28"
subnet mask "255.255.255.252" → "/30"
We will explain CIDR notation using the class C IP address, "192.168.123.45/24".
"/24" means the subnet mask.
"24" represents the number of consecutive "1"s from the left. So "/24" is equivalent to "255.255.255.0".
What are the advantages of using CIDR notation?
Since there is a default subnet, why not show the subnet mask?
You might think that.
However, more and more people now use subnetted network addresses rather than the default subnet mask. In other words, the information of the subnet mask is required along with the IP address.
By using CIDR notation, you can express IP address and subnet mask information in a simplified form.