banner
破影岚歌

破影岚歌的博客

bilibili
twitter
github

About IP addresses and subnet masks, and how to perform subnetting.

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 shield 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: Starting with 0, the network number occupies the first byte, and the host number occupies the remaining three bytes, suitable for large networks.
  • Class B addresses: Starting with 10, the network number occupies the first two bytes, and the host number occupies the remaining two bytes, suitable for medium-sized networks.
  • Class C addresses: Starting with 110, the network number occupies the first three bytes, and the host number occupies the last byte, suitable for small networks.
  • Class D addresses: Starting with 1110, used for multicast.
  • Class E addresses: Starting 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. This is also the reason 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 mask#

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 mask#

The subnet mask has two main functions:

  1. Distinguishing network address and host address: The subnet mask performs a bitwise logical "AND" operation with the IP address to separate the network address and host address in the IP address. This helps determine whether an IP address belongs to the local network or a remote network²6.
  2. Subnetting: The subnet mask can divide a large IP network into multiple 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 a subnet mask 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 bits using binary digit "1" and the right side representing the host bits 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 data packets and forward them to the correct destination³8. This is crucial for internet data transmission, ensuring that data can be 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:

  1. Determining the number of subnets: Determine how many subnets need to be created based on actual requirements.
  2. Calculating the subnet mask: Calculate the new subnet mask based on the number of subnets. The subnet mask determines which parts of the IP address are used for the network address and host address.
  3. Assigning subnet addresses: Assign a network address to each subnet.
  4. Calculating the range of available host addresses: Each subnet has a range from the network address to the broadcast address, within which addresses 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 as subnet bits (because 2^2=4). The subnet mask becomes 255.255.255.192 (or /26), because 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 of the first subnet is 192.168.1.0, the network address of the second subnet is 192.168.1.64, the network address of the third subnet is 192.168.1.128, and the network address of 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.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.