Subnetting Class A, B and C networks: step-by-step calculation with examples and CIDR
🌐 This is an automatic translation of a topic from Underc0de, the largest Spanish-speaking hacking and IT community. Read the original (Spanish) and reply →
Expermicid ·
Update (2026-11-01, Underc0de staff): we added this summary at the top to make it easier to look things up. Below the line you'll find the complete original tutorial, with its images and credits.
Updated: 2026-11 · Review: Underc0de staff. This is a maintenance edit of Expermicid's original tutorial (2013). We added a text version of the tables and calculations below each image, fixed exponents that had been lost in formatting, and left the original source in visible text at the end of the post.
What is subnetting? Subnetting is the technique of dividing an IP network into smaller networks, called subnets, by taking bits from the host portion of the mask and using them as network bits. Each subnet has its own network address, its host range and its broadcast address. It is used to organize the network, separate traffic by function and reduce broadcast.
Quick summary: subnetting Class A, B and C networks with CIDR
1. What is the network mask? An IPv4 address has 32 bits. The mask indicates which bits identify the network (bits set to 1) and which identify the host within that network (bits set to 0). Example: 255.255.255.0 = 11111111.11111111.11111111.00000000, meaning the first 24 bits are network and the last 8 are host.
2. CIDR notation Instead of writing the full mask, you put a slash and the number of bits set to 1: 192.168.1.0/24 is the same as 192.168.1.0 with mask 255.255.255.0. The default class masks are /8 (A), /16 (B) and /24 (C). Since 1993, the Internet assigns addresses with CIDR, that is, classless (RFC 4632). Classes are still used as a starting point for learning and in certification exercises. All the examples below use private ranges (RFC 1918): 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.
3. Basic formulas
[*]Number of subnets: 2^n, where n = bits taken from the host portion. [*]Usable hosts per subnet: 2^h - 2, where h = bits left at 0. The network and broadcast addresses are subtracted. [*]Increment between subnets: 256 - mask value in the octet where the bits were taken. [*]Exceptions: /31 is used on point-to-point links and has 2 usable addresses (RFC 3021). /32 identifies a single host. [/list]
4. Worked example: Class A Network 10.0.0.0/8; at least 100 subnets are needed.
[*]2^7 = 128 (greater than or equal to 100), so 7 bits are taken: /8 + 7 = /15, mask 255.254.0.0 [*]Hosts per subnet: 2^17 - 2 = 131070 [*]Increment: 256 - 254 = 2 in the second octet: 10.0.0.0/15, 10.2.0.0/15, 10.4.0.0/15 ... 10.254.0.0/15 [*]First subnet: network 10.0.0.0, hosts from 10.0.0.1 to 10.1.255.254, broadcast 10.1.255.255 [/list]
5. Worked example: Class B Network 172.16.0.0/16; each subnet must support at least 500 hosts.
[*]2^9 - 2 = 510 (greater than or equal to 500), so 9 host bits remain: 32 - 9 = /23, mask 255.255.254.0 [*]Subnets: 2^(23 - 16) = 2^7 = 128 [*]Increment: 256 - 254 = 2 in the third octet: 172.16.0.0/23, 172.16.2.0/23, 172.16.4.0/23 ... [*]First subnet: network 172.16.0.0, hosts from 172.16.0.1 to 172.16.1.254, broadcast 172.16.1.255 [/list]
6. Worked example: Class C Network 192.168.10.0/24; 6 subnets are needed.
[*]2^3 = 8 (greater than or equal to 6), so 3 bits are taken: /24 + 3 = /27, mask 255.255.255.224 [*]Hosts per subnet: 2^5 - 2 = 30 [*]Increment: 256 - 224 = 32 in the fourth octet: .0, .32, .64, .96, .128, .160, .192 and .224 [*]First subnet: network 192.168.10.0, hosts from .1 to .30, broadcast .31. Second: network .32, hosts from .33 to .62, broadcast .63 [/list]
7. Basic VLSM (variable length subnet masks) With VLSM, each subnet uses the right-sized mask for its number of hosts instead of sharing a single mask. To keep ranges from overlapping, they are assigned from the largest subnet to the smallest. Example with 192.168.50.0/24: LAN A with 100 hosts, LAN B with 50, LAN C with 20 and two point-to-point links. Código: text
Segment Hosts Prefix Network Usable hosts Broadcast
LAN A 100 /25 192.168.50.0 .1 to .126 .127
LAN B 50 /26 192.168.50.128 .129 to .190 .191
LAN C 20 /27 192.168.50.192 .193 to .222 .223
Link 1 2 /30 192.168.50.224 .225 to .226 .227
Link 2 2 /30 192.168.50.228 .229 to .230 .231
Free for growth: 192.168.50.232/29 and 192.168.50.240/28
Note: with VLSM and CIDR, a network that has already been subnetted can be divided again (for example, a /26 into two /27s). That is exactly what is done in this example.
Note about the original tutorial: the exponents that had been lost in formatting are now fixed in the text (2026-11). In the Class C example, where it said "26 - 2 = 62", it now says 2^6 - 2 = 62. In the first clarification, "2N -2" and "2N" now read 2^N - 2 and 2^N.
The purpose of subnetting is to divide a physical IP network into logical subnets (smaller networks) so that each of them works, in terms of sending and receiving packets, as an individual network, even though they all belong to the same physical network and the same domain. Subnetting allows better administration, traffic control and security by segmenting the network by function. It also improves network performance by reducing broadcast traffic on our network. As a disadvantage, its implementation wastes many addresses, especially on serial links.
Class A, B, C, D and E IP Addresses
IP addresses are made up of 32 bits divided into 4 octets of 8 bits each. In turn, a bit or a sequence of bits determines the Class that IP address belongs to. Each class of network address determines a default mask, an IP range, a number of networks and hosts per network.
As text (added 2026-11; standard IPv4 class data): Código: text
Class First bits First octet Default mask Prefix Networks Hosts per network
A 0 1 - 126 (*) 255.0.0.0 /8 2^7 = 128 (126 usable) 2^24 - 2 = 16777214
B 10 128 - 191 255.255.0.0 /16 2^14 = 16384 2^16 - 2 = 65534
C 110 192 - 223 255.255.255.0 /24 2^21 = 2097152 2^8 - 2 = 254
D 1110 224 - 239 (not applicable) - Multicast -
E 1111 240 - 255 (not applicable) - Experimental (reserved) -
(*) 0 is reserved and 127 is used for loopback (127.0.0.1).
Each Class has a default network mask: Class A 255.0.0.0, Class B 255.255.0.0 and Class C 255.255.255.0. Addressing that uses the default network mask is called "classful addressing".
Class Decimal mask Binary mask Prefix
A 255.0.0.0 11111111.00000000.00000000.00000000 /8
B 255.255.0.0 11111111.11111111.00000000.00000000 /16
C 255.255.255.0 11111111.11111111.11111111.00000000 /24
Subnetting is always done starting from a Class A, B or C network address, and it is adapted according to the requirements of subnets and hosts per subnet. Keep in mind that you cannot subnet a classless network address since it has already gone through that process; I point this out because it's a very common mistake. Addressing that uses the adapted (subnetted) network mask is called "classless addressing". Consequently, the Class of an IP address is defined by its network mask and not by its IP address. If an address has its default mask it belongs to Class A, B or C; otherwise it has no Class, even if its IP makes it look like it does.
Network Mask
The network mask is divided into 2 parts:
Network Portion: If the mask is the default one, a classful address, the number of "1" bits in the network portion indicates the network address, that is, the part of the IP address that will be common to all hosts on that network. If it's an adapted mask, things are more complex. The part of the network mask whose octets are all "1" bits indicates the network address and will be the part of the IP address common to all hosts on that network; the remaining "1" bits are the ones that will be modified in the IP address to generate the different subnets, and they will be common only to the hosts belonging to that subnet (explained like this it seems cumbersome, so I leave you examples below). In both cases, classful or not, it determines the prefix you usually see after an IP address (e.g.: /8, /16, /24, /18, etc.) since that number is the sum of the "1" bits in the network portion.
Host Portion: The number of "0" bits in the host portion of the mask indicates which part of the network address is used to assign host addresses, that is, the part of the IP address that will vary as addresses are assigned to hosts.
Examples:
If we have the Class C IP address 192.168.1.0/24 and convert it to binary, the first 3 octets, which match the "1" bits of the network mask (burgundy background), are the network address, which will be common to all hosts assigned in the last octet (gray background). By the same criterion, if we have a Class B address, the first 2 octets are the network address common to all hosts assigned in the last 2 octets, and if we have a Class A address, the 1st octet is the network address common to all hosts assigned in the last 3 octets.
If instead of a classful address we have one that's already subnetted, for example 132.18.0.0/22, things get more complex. In this case the first 2 octets of the IP address, since the first 2 octets of the network mask are all "1" bits (burgundy background), are the network address and will be common to all subnets and hosts. Since the 3rd octet is split in 2, one part in the network portion and the other in the host portion, the part of the IP address corresponding to the network portion (black background), which has "1" bits in the network mask, will change as subnets are assigned and will only be common to the hosts that are part of that subnet. The 2 "0" bits of the 3rd octet in the host portion (gray background) and the entire last octet of the IP address will be used to assign host addresses.
Since it would be almost impossible to work with 32-bit addresses, we need to convert them to decimal numbers. In the conversion process, each bit of an interval (8 bits) of an IP address, if it is "1", has a value of "2" raised to the position that bit occupies in the octet, and then the results are added up. Explained like this it seems a bit cumbersome, but with the table and examples it will be clearer.
The combination of 8 bits allows a total of 256 possible combinations, covering the entire decimal range from 0 (00000000) to 255 (11111111). Some examples.
Calculating the Number of Subnets and Hosts per Subnet
Number of Subnets equals: 2^N, where "N" is the number of bits "borrowed" from the Host portion.
Number of Hosts per Subnet equals: 2^(M) -2, where "M" is the number of bits available in the host portion and "-2" is because every subnet must have its own network address and its own broadcast address.
CitarClarification: Originally the formula to get the number of subnets was 2^N - 2, where "N" is the number of bits "borrowed" from the host portion and "-2" because the first subnet (subnet zero) and the last subnet (subnet broadcast) were not usable since they contained the network and broadcast address respectively. All the tutorials floating around the Internet use that formula. Nowadays the formula 2^N is used and taught to get the number of subnets, which allows both subnet zero and the broadcast subnet to be assigned. (Exponents fixed in 2026-11: previously it read "2N -2" and "2N" because the formatting had been lost.)
Well, that's the basic theory. Once we understand this we can start subnetting. As advice, I tell you to learn and absorb the dynamics of this process since it's fundamental.
Manual Subnetting of a Class A Network
Given the Class A IP address 10.0.0.0/8 for a network, we are asked to obtain 7 subnets through subnetting. This is a typical example we may be asked, although we'll rarely run into it in real life.
2^1 = 2 (less than 7)
2^2 = 4 (less than 7)
2^3 = 8 (greater than or equal to 7) -> N = 3 bits
Once the calculation is done, it tells us we must borrow 3 bits from the host portion to make 7 or more subnets, and that the total number of usable subnets will be 8, meaning 1 will be left for future use.
Taking the default Class A mask, we add to the network part the 3 bits we borrowed from the host portion, replacing them with "1", and so we get 255.224.0.0, which is the subnet mask we'll use for all our subnets and hosts.
To get the subnets we work only with the network IP address, in this case 10.0.0.0. For this we'll modify the same octet of bits (the second) that we modified earlier in the network mask, but this time in the IP address.
Network 10.0.0.0 00001010.000 | 00000.00000000.00000000
Mask 11111111.111 | 00000.00000000.00000000 (255.224.0.0)
^^^ the 3 bits that change in each subnet
There are several ways to get the range; the one I find simplest is to subtract the adapted network mask number from 256. In this case it would be: 256-224=32, so 32 will be the range between each subnet.
Subnet Network address First host Last host Broadcast
1 10.0.0.0 10.0.0.1 10.31.255.254 10.31.255.255
2 10.32.0.0 10.32.0.1 10.63.255.254 10.63.255.255
3 10.64.0.0 10.64.0.1 10.95.255.254 10.95.255.255
4 10.96.0.0 10.96.0.1 10.127.255.254 10.127.255.255
5 10.128.0.0 10.128.0.1 10.159.255.254 10.159.255.255
6 10.160.0.0 10.160.0.1 10.191.255.254 10.191.255.255
7 10.192.0.0 10.192.0.1 10.223.255.254 10.223.255.255
8 10.224.0.0 10.224.0.1 10.255.255.254 10.255.255.255
Mask for all: 255.224.0.0 (/11). Increment: 32 in the second octet.
If we want to calculate how many hosts we'll get per subnet, we must apply the formula 2^M - 2, where M is the number of "0" bits available in the host portion of the network IP address and - 2 is because every subnet must have its own network address and its own broadcast address.
2^4 = 16 (less than 50)
2^5 = 32 (less than 50)
2^6 = 64 (greater than or equal to 50) -> N = 6 bits
The calculation tells us we must borrow 6 bits from the host portion to make 50 or more subnets, and that the total number of usable subnets will be 64, meaning 14 will be left for future use. So we add the 6 borrowed bits to the default Class B mask, replacing them with "1", and we get the adapted mask 255.255.252.0.
Once we adapt the network mask to our needs, it isn't touched again and will be the same for all subnets and hosts that make up this network. From here on we'll only work with the network IP address. In this case with the host portion (gray background).
Network 132.18.0.0/22 10000100.00010010.000000 | 00.00000000
net + subnet (22 bits) | host: M = 2 + 8 = 10 bits at 0
Besides a number of subnets, which we already reached by adapting the mask in the first step, the exercise asked for a specific number of 1000 hosts per subnet. To check whether it's possible to get them with the new mask (it isn't always possible), we use the formula 2^M - 2, where M is the number of "0" bits available in the host portion and - 2 is because the first and last IP addresses of the subnet are not usable, being the subnet address and broadcast respectively.
2^10 - 2 = 1022 hosts per subnet.
The 10 "0" bits of the host portion (gray background) are the ones we'll modify later as we assign hosts to the subnets.
Get the Subnet Range (3)
To get the subnets we work with the network portion of the network IP address, more specifically with the part of the network portion that we modified in the network mask, but this time in the IP address. Remember that 6 bits were previously added to the network mask in the third octet, so you'll have to modify those same bits but in the network IP address (black background).
Network 132.18.0.0/22 10000100.00010010 | 000000 | 00.00000000
common network | subnet | host
(the 6 "subnet" bits change in each subnet)
The 6 "0" bits of the network portion (black background) are the ones we'll modify later as we assign the subnets.
There are several ways to get the range; the one I find simplest is to subtract the adapted subnet mask number from 256. In this case it would be: 256-252=4, so 4 will be the range between each subnet. In the chart I only put the first 10 subnets and the last 5 because it would be too long, but the dynamics are the same.
2^1 = 2 (less than 4)
2^2 = 4 (greater than or equal to 4) -> N = 2 bits
As we see in the chart, to make 4 subnets we must borrow 2 bits from the host portion. We add the 2 borrowed bits, replacing them with "1", to the default Class C mask and get the adapted mask 255.255.255.192.
We now have our adapted network mask, which will be common to all subnets and hosts that make up the network. Now we need to get the hosts. For this we'll work with the network IP address, specifically with the host portion (gray background).
Network 192.168.1.0/26 11000000.10101000.00000001.00 | 000000
net + subnet (26 bits) | host: M = 6 bits at 0
The exercise asked for a minimum of 50 hosts per subnet. For this we use the formula 2^M - 2, where M is the number of "0" bits available in the host portion and - 2 because the first and last IP addresses of the subnet are not used, being the subnet address and broadcast respectively.
2^6 - 2 = 62 hosts per subnet. (Fixed 2026-11: it previously said "26 - 2" because the exponent had been lost.)
The 6 "0" bits of the host portion (gray background) are the ones we'll use as we assign hosts to the subnets.
Get the Subnet Range (3)
To get the subnet range we use the network portion of the IP address that was modified when adapting the network mask. 2 bits were added to the network mask in the fourth octet, so you'll have to modify those same bits but in the IP address (black background).
Network 192.168.1.0/26 11000000.10101000.00000001 | 00 | 000000
common network | subnet | host
(the 2 "subnet" bits change in each subnet)
The 2 "0" bits of the network portion (black background) are the ones we'll modify later as we assign the subnets.
The simplest way to get the range is to subtract the adapted subnet mask number from 256. In this case it would be: 256-192=64, so 64 will be the range between each subnet.
Subnet Network address First host Last host Broadcast
1 192.168.1.0 192.168.1.1 192.168.1.62 192.168.1.63
2 192.168.1.64 192.168.1.65 192.168.1.126 192.168.1.127
3 192.168.1.128 192.168.1.129 192.168.1.190 192.168.1.191
4 192.168.1.192 192.168.1.193 192.168.1.254 192.168.1.255
Mask for all: 255.255.255.192 (/26). Increment: 64 in the fourth octet. 62 hosts per subnet.
And that's all, I hope you find it useful.
I studied all this in my degree. In this case the tutorial was taken from Los enlaces son solo para miembros. Registrate o iniciá sesión but next time I'll make one of my own :)