What is an IP address (this article mainly explains IPv4)#
An IP address (Internet Protocol Address) is a unified address format used to assign a logical address to each network and host on the Internet, in order to mask the differences in physical addresses. An IP address is similar to a phone number or home address, ensuring that information can be accurately sent to the correct destination.
IPv4 address is one of the widely used versions of IP addresses. It consists of a 32-bit binary number, usually divided into four 8-bit binary numbers (i.e., four bytes). For readability, IPv4 addresses are usually represented in dotted decimal notation, where each 8-bit binary number is converted to a decimal number and separated by dots (.), such as a.b.c.d
, where a, b, c, and d are decimal integers between 0 and 255.
IPv4 addresses can be divided into the following classes:
- Class A addresses: Start with 0, with the network number occupying the first byte and the host number occupying the remaining three bytes, suitable for large networks.
- Class B addresses: Start with 10, with the network number occupying the first two bytes and the host number occupying the remaining two bytes, suitable for medium-sized networks.
- Class C addresses: Start with 110, with the network number occupying the first three bytes and the host number occupying the last byte, suitable for small networks.
- Class D addresses: Start with 1110, used for multicast.
- Class E addresses: Start with 1111, reserved addresses used for experimentation and research.
IPv4 addresses also include special addresses, such as the loopback address (127.0.0.1) used for local communication testing, and the broadcast address (e.g., 255.255.255.255) used to send packets to all hosts on the local network.
Due to the limited IPv4 address space, the problem of address exhaustion has arisen, which is why IPv6 addresses have been proposed. IPv6 addresses have a larger address space to meet the needs of more devices in the future.
What is a subnet mask#
Introduction to subnet masks#
A subnet mask is a 32-bit address used to divide the network address and host address in an IP address. It is used in conjunction with an IP address to separate the network portion and host portion of an IP address¹1.
Functions of subnet masks#
The main functions of subnet masks are as follows:
- Distinguish network addresses and host addresses: Subnet masks use bitwise logical "AND" operations with IP addresses to separate the network address and host address in an IP address. This helps determine whether an IP address belongs to the local network or a remote network²6.
- Subnetting: Subnet masks can divide a large IP network into smaller subnets. This reduces IP address waste, improves network application efficiency, and facilitates network management¹1.
For example, a common subnet mask is 255.255.255.0
, which is equivalent to 11111111.11111111.11111111.00000000
in binary. This means that the first three bytes of the IP address are the network address, and the last byte is the host address. If two computers have the same network address after applying the same subnet mask, they are in the same subnet¹1.
The configuration of subnet masks must follow certain rules, where 1s and 0s must be continuous and cannot be mixed. The length of a subnet mask is also 32 bits, with the left side representing the network portion using binary digit "1" and the right side representing the host portion using binary digit "0"¹1.
In practical applications, subnet masks are not only used within local area networks but also by routers to determine the correct routing path for data packets. Through subnet masks, routers can determine the next hop address of a data packet and forward it to the correct destination³8. This is crucial for internet data transmission to ensure that data is accurately sent to the correct destination.
How to perform subnetting#
Subnetting is the process of dividing a larger network into multiple smaller, independent subnetworks. This improves network management efficiency and security, as well as allows for more rational allocation and utilization of IP address resources. Subnetting typically involves the following steps:
- Determining the number of subnets: Determine how many subnets need to be created based on actual requirements.
- Calculating the subnet mask: Calculate the new subnet mask based on the number of subnets. The subnet mask determines which parts of an IP address are used for the network address and host address.
- Assigning subnet addresses: Assign a network address to each subnet.
- Calculating the range of available host addresses: Each subnet has a range of addresses from the network address to the broadcast address, which can be assigned to devices within that subnet.
For example, if we have a Class C network address 192.168.1.0 with a default subnet mask of 255.255.255.0 (or /24), and we want to divide it into 4 subnets, each supporting at least 30 hosts. We can follow these steps:
- Step 1: Determine the number of subnets. We need 4 subnets.
- Step 2: Calculate the subnet mask. Since we need 4 subnets, we need to borrow at least 2 bits for subnetting (because 2^2=4). The subnet mask becomes 255.255.255.192 (or /26), as we add the borrowed 2 bits to the original 24 bits, resulting in a total of 26 bits.
- Step 3: Assign subnet addresses. The network address for the first subnet is 192.168.1.0, the network address for the second subnet is 192.168.1.64, the network address for the third subnet is 192.168.1.128, and the network address for the fourth subnet is 192.168.1.192.
- Step 4: Calculate the range of available host addresses. Each subnet can have 2^(32-26)-2=62 available addresses (subtracting 2 because the network address and broadcast address cannot be used for hosts).
This is just a simple example, and actual subnetting can be more complex, taking into account the actual network requirements and IP address usage¹1²2³3.