As mentioned above, the first few bits of an IP address classify the address as
- Class A,
- Class B, or
- Class C.
This information is sufficient to decide what portion of the address refers to the host and which to the network.
However, this division is a convention and is not programmed into the TCP/IP networking software.
The netmask is a number telling the TCP/IP software which portion of the address is host and which is network.
The netmask itself is a 32-bit number with a one bit set in each position of the network address and a zero bit set in each position of the host address.
It is usually written in dotted decimal form, like an IP address.
If an address is Class A, B, or C, the netmask is completely standard.
For example, a Class A address has eight bits of network address, so the first eight bits of the netmask are 1; it has 24 bits of host, so the next 24 bits are 0. Converted to dotted decimal, this yields 255.0.0.0. The other cases are illustrated in the table below.
A netmask, also known as a subnet mask, plays a critical role in IP addressing, particularly in identifying the network and host portions of an IP address. Both IPv4 and IPv6 use netmasks, but they are more commonly associated with IPv4.
Structure of a Netmask
A netmask is a 32-bit number for IPv4 that masks an IP address and divides the IP address into network address and host address. A netmask is made up of two parts:
- Network bits: The left-most bits in the netmask are set to '1'. Each '1' corresponds to a bit of the IP address that belongs to the network address.
- Host bits: The remaining bits on the right are set to '0'. Each '0' corresponds to a bit of the IP address that can be used for host addresses within the network.
The number of '1' bits corresponds to the prefix length or network prefix, which is often represented in slash notation (also known as CIDR notation) appended to an IP address. For example, in the IP address 192.0.2.0/24, the '/24' indicates that the first 24 bits are network bits, leaving the remaining 8 bits for host addresses.
Use of a Netmask
Netmasks are used for subnetting, a practice that involves dividing a network into smaller logical subnetworks or subnets. The main uses of a netmask are:
- Identify Network and Host Portions: Netmasks differentiate the network portion of an IP address from the host portion. This differentiation is crucial for routing traffic correctly across networks and to specific hosts.
- IP Address Classification: A netmask can be used to classify IP addresses into classes (A, B, C, D, and E), although this classification is less relevant with the widespread use of CIDR (Classless Inter-Domain Routing), which allows for more flexible and efficient allocation of IP addresses.
- Subnetting: By changing the netmask, a network administrator can divide a network into smaller subnets. This process is useful for limiting network traffic, improving network performance, and enhancing control and security.
- Supernetting: A netmask can also be used for supernetting or aggregating several networks into a larger one, a technique often used in routing to reduce the size of routing tables.
A netmask is a fundamental component of IP networking, essential for identifying the network and host portions of an IP address, and for performing subnetting and supernetting.
More sophisticated netmasks are possible if subnetting is being used, but further discussion of the subject is beyond the scope of this course.
The netmask is an important tool for subdividing IP networks and ensuring efficient and correct routing of IP packets.