An IP address consists of two addresses: the network address and the host address. A subnet mask separates the network address from the host address in the IP address.
We use an IP address always with the subnet mask. A subnet mask defines the boundary between the network address and the host address in the IP address. A network address is the group address. We use it to create a group of IP addresses. A group of IP addresses is known as an IP subnet. A host address is an individual address. In an IP subnet, all addresses have the same network address and different host addresses.
The following image shows four IP subnets having six host addresses.
We use IP addresses in decimal. From 8 binary bits, the maximum number we can make in decimal is 256. IP addresses start from 0. Hence, the maximum number in decimal will be 255 (256 -1).
We use the subnet mask to separate network and host bits in an IP address. For 32 IP bits, we use 32 subnet mask bits. Subnet mask bits and IP address bits have one-to-one relations. The first subnet mask bit relates with the first IP bit, the second subnet mask bit with the second IP bit, and so on til the last bit.
A subnet mask bit shows the type of the related IP bit. If its value is 1, the IP bit will be a network bit. If its value is 0, the IP bit will be a host bit.
There are five IP classes . These are A, B, C, D, and E. Only classes A, B, and C are available for network addressing. We cannot use classes D and E for network addressing. Network services use class D for multicast addressing. Class E is reserved for research.
Class | First address (binary notation) | Last address (binary notation) | First address (decimal notation) | Last address (decimal notation) |
A | 00000000 | 01111111 | 0 | 127 |
B | 10000000 | 10111111 | 128 | 191 |
C | 11000000 | 11011111 | 192 | 223 |
D | 11100000 | 11101111 | 224 | 239 |
E | 11110000 | 11111111 | 240 | 255 |
Default subnet mask
IP addresses in classes D and E have all network bits. They do not have host bits. Since they do not have host bits and a subnet mask is used to differentiate host bits from network bits, they do not need a subnet mask.
Only IP addresses in classes A, B, and C have host bits and need a subnet mask. These classes have a default subnet mask.
The following table lists default subnet masks.
Class | Default subnet mask |
A | 255.0.0.0 |
B | 255.255.0.0 |
C | 255.255.255.0 |
D | Not applicable |
E | Not applicable |
Because of the default subnet masks, the first 8, 16, and 24 bits in classes A, B, and C are always network bits.
Slash notation
Slash notation is a shorter way to write subnet masks. In this notation, instead of writing the full subnet mask, we use only the number of bits having the value 1 after the slash with the IP address.
For example, the default subnet mask of class A is 255.0.0.0. In binary, it is 11111111.00000000.00000000.00000000. It has 8 network bits having the value of 1. In slash notation, we will write this subnet mask as /8.
The default subnet mask of class B has 16 network bits. In slash notation, it will be /16. The default subnet mask of class C has 24 network bits. In slash notation, we will write it as /24.
Class | Default subnet mask | Slash notation |
A | 255.0.0.0 | /8 |
B | 255.255.0.0 | /16 |
C | 255.255.255.0 | /24 |
The following table lists some examples of IP addresses and their subnet mask in all three notations.
In Slash notation | In binary notation | In decimal notation |
10.10.10.10/8 | 00001010.00001010.00001010.00001010 11111111.00000000.00000000.00000000 | 10.10.10.10 255.0.0.0 |
172.168.1.1/16 | 10101100.10101000.00000001.00000001 11111111.11111111.00000000.00000000 | 172.168.1.1 255.255.0. |
192.168.1.1/24 | 11000000.10101000.00000001.00000001 11111111.11111111.11111111.00000000 | 192.168.1.1 255.255.255.0 |
192.168.1.1/28 | 11000000.10101000.00000001.00000001 11111111.11111111.11111111.11110000 | 192.168.1.1 255.255.255.240 |
Bits in the subnet mask
Bits in the subnet mask always follow a pattern. They are written from left to right. Network bits are always written before the host bits. We cannot write a host bit between network bits.
Subnetting
Subnetting is a process of breaking an IP subnet into many small subnets. To break an IP subnet, we convert the host bits into network bits. We start the conversion process from the leftmost host bit.
When converting bits, we cannot skip any host bit. For example, if we want to break a subnet into two subnets, we will convert the leftmost host bit into a network bit. If we want to break it into four subnets, we will convert the two leftmost host bits into network bits.
This tutorial is the third chapter of the tutorial series. Other chapters of this series are the following.
Chapter 01 Introduction to Subnetting
Chapter 02 Network Address Basic Concepts Explained with Examples
Chapter 04 Convert Decimal IP address in Binary and Binary in Decimal
Chapter 05 Basic Subnetting in Computer Networks Explained
Chapter 06 Subnetting Tutorial - Subnetting Explained with Examples
Chapter 07 Subnetting Tricks Subnetting Made Easy with Examples
Chapter 08 FLSM Subnetting and VLSM Subnetting
Chapter 09 VLSM Subnetting Explained with Examples
Chapter 10 VLSM Subnetting Examples and Calculation Explained
Chapter 11 Route Summarization Advantages and Disadvantages
Chapter 12 Supernetting Tutorial: - Supernetting Explained with Examples
Key points:-
- A subnet mask is a 32 bits binary address.
- IP addresses use subnet masks to separate network bits and host bits.
- Subnet mask bits and IP address bits have a one-to-one association.
- The first subnet mask bit relates to the first IP bit, the second subnet mask bit relates to the second IP bit, and so on til the last bit.
- If the subnet mask bit's value is 1, the related IP bit belongs to the network address.
- If the subnet mask bit's value is 0, the related IP bit belongs to the network address.
- Subnet mask bits are written from left to right.
- In a subnet, network bits are always written before the host bits.
- Subnetting is a process of breaking a subnet into many subnets.
- In subnetting, we convert host bits into network bits.
- Subnetting always starts from the leftmost host bit and goes to the rightmost bit without skipping any bit.