Rules for using subnet mask
IPv4 addressing
IPv4地址格式:a.b.c.d/x
IP地址 = 网络地址 + 主机地址
The highest bit of x of an address in the form of abcd/x constitutes the network part of the IP address.
/x indicates that the leftmost x bit in the 32 bits defines the subnet address.
Example:
192.168.101.1/24
二进制:11000000.10101000.01100101.00000001
网络地址:192.168.101.0
广播地址:192.168.101.255
主机地址:0.0.0.1
子网掩码:255.255.255.0(24位)
Subnet mask
(1) The role of the subnet mask: calculate the network address of an IP address.
An IP address and its subnet mask are ANDed, and the result is the network address. which is:
网络地址 = IP地址 & 子网掩码
//And operation (&): 1&1=1, 1&0=0, 0&1=0, 0&0=0.
If and only if the network numbers of the two IP addresses are the same, they can be pinged.
(2) Representation of subnet mask:
example:
IP地址:192.168.101.1/24
子网掩码的位数:24位
子网掩码(十进制):255.255.255.0
子网掩码(十六进制):0xffffff00
子网掩码(二进制):11111111.11111111.11111111.00000000
Five types of IP addresses
The network number of any number is replaced by the symbol -, and the host number is replaced by the symbol x:
Address category | Address format | IP address range | Subnet mask | Can accommodate the number of hosts | Special purpose address |
---|---|---|---|---|---|
A | 0-------.xxxxxxxx.xxxxxxxx.xxxxxxxx | 1~127 | 255.0.0.0 | 232 | 127.xxx (loopback address), 10.xxx/8 (private address) |
B | 10------.--------.xxxxxxxx.xxxxxxxx | 128~191 | 255.255.0.0 | 216 | 172.10.xx/16 (private address) |
C | 110-----.--------.--------.xxxxxxxx | 192~223 | 255.255.255.0 | 28 | 192.168.xx/32 (private address) |
D | Beginning with 1110 | 224~239 | For multicast | ||
E | Beginning with 1111 | 240~255 | For scientific research retention |
Subnetting
Example:
Obtain an IP address 200.23.16.0/20 from the Internet Provider (ISP); use the subnet mask to divide it into 8 subnets.
(1) The binary value of 7 is 111, three digits, and the number of subnet mask digits is 20+3=23.
(2) Divide the subnet.
ISP address block | 200.23.16.0/20 | 11001000 00010111 00010000 00000000 |
---|---|---|
Organization 0 | 200.23.16.0/23 | 11001000 00010111 00010000 00000000 |
Organization 1 | 200.23.18.0/23 | 11001000 00010111 00010010 00000000 |
Organization 2 | 200.23.20.0/23 | 11001000 00010111 00010100 00000000 |
Organization 3 | 200.23.22.0/23 | 11001000 00010111 00010110 00000000 |
Organization 4 | 200.23.24.0/23 | 11001000 00010111 00011000 00000000 |
Organization 5 | 200.23.26.0/23 | 11001000 00010111 00011010 00000000 |
Organization 6 | 200.23.28.0/23 | 11001000 00010111 00011100 00000000 |
Organization 7 | 200.23.30.0/23 | 11001000 00010111 00011110 00000000 |