# Subnetting and Subnet Masks Explained

What is Subnetting ?-Subnetting is the process of diving a network into small networks and is a common task on IPV4 networks.

Before we discuss how to implement it it is useful to understand why and when we need to do it and to do that we are first going to work through a simple analogy to illustrate the problem subnetting solves

### Subnetting Analogy

As an analogy imagine a school and we need to split it into class rooms.

But why split it into class rooms? The answer is to stop classes interfering with one another.

Now each classroom has a desk with a computer and we have been tasked with creating a labeling system for the computers.

Now say we have 30 classrooms each with a maximum of 30 students and computers.

If we assign numbers to our classrooms and computers then we could have for example:

computer 11, classroom 24

We need two digits for the classroom which would allow for a maximum of 100 classrooms (0-99).

We need two digits for the computer which would allow for a maximum of 100 computers (0-99).

If we also say that classroom numbers 0 and 99 and computer numbers 0 and 99 were reserved and not allowed to be assigned then we now have a maximum of 98 classrooms and 98 computers which is enough for own requirements.

So lets create our label we could use the following scheme:

• computer 11, classroom 24
• 24-11
• 11-24
• 2411
• etc

There are many possible permutations we just need to pick one and tell every one about out labeling scheme.

Lets assume we go for 2411 where 24 is the classroom and 11 is the computer.

So now when we see the following 0223 we now know that this refers to classroom 2 and computer 23.

This we do easily in our heads once we know the labelling scheme.

We could even make it easier for ourselves by creating a paper mask that we put over the label that would reveal the classroom.

Just like in our classroom example an IP address is split into two components a network component and a node component.

So the address 10.0.2.1 is split into Network plus Node.

So is the network number  10, or 10.2 or 10.0.2 ?

In early IPv4 networks address classes were used to identify the number of bytes allocated to the network component.

The main classes were class A,B,C. With the allocation as follows:

Class A    network,node,node,node
Class B    network,network,node,node
Class C    network,network,network,node

To determine the class you needed to examine the most significant byte (far left).

• 0-127 Class A
• 128-191 Class B
• 192-ccc Class C

### IP Subnetting- Problems with Large Networks

All modern networks use the Ethernet data link protocol.

Ethernet uses a shared media and is negatively effected when a large number of nodes are connected to the same media.

This is just the same as having too many kids in the same classroom.

You can equate a network and node address to our classroom and desk number

What would happen if you had a classroom with 100’s of desks i.e. hundreds of pupils?

So even though a Class A address can accommodate thousands of nodes it it totally impractical to put this many nodes on a single network.

The solution to the problem was to split the network into small networks called sub networks or subnets.

Take for example a class A address which uses 1 byte for the network ID and 3 bytes for the Node ID. Written

Net.Node.Node.Node

It is important to understand that the network part of the address is only used for routing IP packets on the public internet.

Once the packet enters the private network then the Node address is used and the public Network address is not used.

Now a network administrator can interpret the node address any way they want, and so it is possible to split the node address into subnet and Node. So we could have

Net.Subnet.Node.Node or Net.Subnet.Subnet.Node.

The technique used to create subnets is to use a Mask.

The mask effectively hides the Node component and leaves the network and sub network components.

If the IP address was printed on paper we could hide the last byte by placing a paper mask over the number with three holes.

Note: if your binary is a little rusty see the binary numbers tutorial

To do this on a computer we use a number which we then logically AND with with IP address.

Here is the logic table for AND

1 and 1 =1
1 and 0 =0
0 and 1 =0
0 and 0 =0

So our mask to hide the last byte is 255.255.255.0   As 0 and Anything is always 0

The best way to see this is to write the numbers out in binary

000001011.00000001.00000001.00010101 = 11.1.1.21
11111111.11111111.11111111.00000000 =255.255.255.0

and then do a logical AND

the Network address is 11.1.1.0 which corresponds to network 11 subnet 1.1

Th example above used a class A IP address we can do the same with a class B address.

Subnetting on a byte boundary is the easiest to do and understand but we can also subnet on non byte boundaries.

#### Worked Examples

1- You have been allocated a class A network address of 29.0.0.0. You need to create at least 20 networks and each network will support a maximum of 160 hosts. Would the following two subnet masks Work?

255.255.0.0 and or 255.255.255.0

Yes both would work.

Mask 255.255.0.0 has 8 bits for the subnet and 16 bits for the host

8 bits would accommodate 28=256 subnets

16 bits would accommodate 216= over 64000 hosts

Mask 255.255.255.0 has 16 bits for the subnet and 8 bits of the host.

Have possible 28 -2 hosts =254 which is enough.

2. – You have been allocated a class B network address of 135.1.0.0 and and need to create 4 subnets each with around 200 hosts what is the easiest mask to use to satisfy the criteria?

Easiest is to sub net on a byte boundary which would mean a subnet mask of 255.255.255.0

This would allocate 8 bits for the subnet and 8 bits for the host.

We need to accommodate around 200 hosts which requires 8 bits which we have.

We need 4 subnets which requires 4 bits and we have 8 bits. So we have more than enough.

### Classless Inter-Domain Routing (CIDR)

Classless Inter-Domain Routing was introduced in 1993 to replace the classful network design.

It also introduced a new method of denoting network masks.

Example:
A class C network would have a subnet mask of 255.255.255.0 which means that 24 bits are used for the network.

In CIDR notation this is designated by a /24 following the IP address. So:

IP address 192.168.1.168 subnet mask 255.255.255.0 is written as:  192.168.1.168/24 in CIDR notation.

#### Table: CIDR and Subnet Examples

Address Class No of Network Bits No of Host Bits Subnet mask CIDR notation
A 8 24 255.0.0.0 /8
A 9 23 255.128.0.0 /9
A 12 20 255.240.0.0 /12
A 14 18 255.252.0.0 /14
B 16 16 255.255.0.0 /16
B 17 15 255.255.128.0 /17
B 20 12 255.255.240.0 /20
B 22 10 255.255.252.0 /22
C 24 8 255.255.255.0 /24
C 25 7 255.255.255.128 /25
C 28 4 255.255.255.240 /28
C 30 2 255.255.255.252 /30

### Worked Examples

Decimal 192 =11000000 binary which means that 2 bits of this octet are used for the subnet. Now add the 24 bits 255.255.255 and we have 26 bits. So we write:

222.1.1.20/26

2. Write is the IP address 135.1.1.25 mask 255.255. 248.0 in CIDR notation

Decimal 248 =11111000 binary which means that 5 bits of this octet are used for the subnet. Now add the 16 bits 255.255. and we have 21 bits. So we write:

135..1.1.25/21

### Simple Subnetting Exercise Questions

The best way to learn to do subnetting is to try some examples. We will look a some common subnetting problems that arise when creating networks.

1 –  You have been allocated a class C network address of 201.1.1.0 how may hosts can you have?

2- You have been allocated a class A network address of 21.0.0.0. You need create at least 10 networks and each network will support a maximum of 100 hosts. Would the following two subnet masks Work.

255.255.0.0 and or 255.255.255.0

3 – You have been allocated a Class B network address of 129.1.0.0. You have subnetted it using the subnet mask 255.255.255.0 How many networks can you Have and how many hosts can you place on each network?

A1– 256-2= 254  – Why? host addresses of all 0’s and all 1’s are not allowed.

A2- Yes you only need 8 bits for 100 hosts and both subnet masks would give you that.

A subnet mask of 255.255.255.0 would give you lots of networks (2 16) and 254 hosts.

A subnet of 255.255.0.0 would give you lots of hosts (approx 216) and 256 networks.

A3 – the network has 8 bits and so does the node component. This means that you have have 28 =256 networks and 256 -2 = 254 hosts

So far we have been subnetting on a byte boundary using class A and B addresses.

Now we are going to look at how we subnet on a non-byte boundary using a Class C Address.

Exercise- You have been allocated a class C network address of  195.1.1.0.

You need to create 5 sub networks each network has a maximum of 10 hosts.

Now our current subnet mask is 255.255.255.0

We can only use the first 8 bits for out subnets as these 8 bits have been allocated as host addresses.

So for 10 hosts we need 4 bits (16-2 =14 hosts)

for 5 subnets we need 3 bits (8 networks possible)

11100000=224 (Note: 3 bits for sub networks)

11110000=240 (Note: 4 bits for sub networks)

So Subnet masks of 255.255.255.224 and 255.255.255.240 would both work.

In CIDR notation we have 195.1.1.0/27 and 195.1.1.0/28

### Subnet Table and Calculator

Below is a simple subnet table that makes it easier for calculating subnets.

There are also many online subnet calculators available like this one

### Subnet Worked Examples

Subnetting Worked Examples and Exercises

### Subnet Quizes

Test you knowledge using these online quizes

Related Tutorials and Resources:

Save

1. Thanks, very useful article!
One question though… With these exercises above the answer of A-1 starts with… 255-2= 254

Is it me, or does this sound weird? 😉

1. steve says:

No it is me.it should be 256-2. I’ll change it

2. henry says:

“We need 4 subnets which requires 4 bits and we have 8 bits. So we have more than enough.”
Isn’t 4 subnets requires 2 bits?

1. steve says:

4 subnets require 3 bits as 2 are always unused the all0 and all 1 s so with 4 bits
00 =unused
01=ok
10=ok
11=unused
rgds
steve

3. Labeeb Tahir says:

Sir if we want to make 4 subnets of class c ipv4 and one of it should have 75 host bit the limit is of 62 host per subnet , then what should we have to do to find its subnetmask?? Please anyone respond

1. steve says:

It Looks like a VLSM question which I don’t cover on the site because I never did VLSM in real life as there wasn’t the need when I was doing it.

Rgds
Steve

2. Alok Kapil says:

Hi Labeeb, In that case, you would need to take 2 IPs which further can be devided in to 4 (/25) subnets. For ex:
1. 192.168.0. 0/25 (0.1 to 0.126)
2. 192.168.0.128./25 (0.129 to 0.254)
3. 192.168.1.0/25 (1.1 to 1.126)
4. 192.168.1.128/25 (1.129 to 1.254)

4. Very well defined Steve thanx for such a great tutorial.

5. Guillaume says:

Hi Steve,
Thanks for your this explanation. Very useful.
Just a question.
Can we not apply the mask 255.0.0.0 to IP 29.0.0.0 ?

1. steve says:

Yes This is the default subnet mask for a class A address
rgds
steve

1. woow, thank you so much STEVE for your help!

6. Alex says:

Thank you for this awesome explanation. I watched numerous YouTube tutorials, read a few books, but your explanation is so straightforward and easy to understand it immediately clicked! 100x times thanks!

7. asim says:

Under heading “IP Subnetting- Problems with Large Networks”
it says on 6th line that :
“So even though a Class A address can accommodate thousands of nodes, it is totally impractical to put this many nodes on a single network.”

why is it impractical?

1. steve says:

It is because the data link protocol is Ethernet and this was designed to use coax cable which is a shared media. UTP still uses the shared media design. in this configuration as you add more nodes the collision rate increases and the speed decreases until eventually it stops.
There appears to be a 1024 node limit but most ethernet networks aremuch smaller see here

8. Idris says:

Made easy and simple to understand thank you so much.

9. harmony says:

10. Chandra kanth Poola says:

very precise and easy to understand

11. Tharindi says:

12. ollie b says:

wow, just wow, i have spent 3 days in classes trying to understand all this stuff and this page has just explained everything to me in about an hour! God bless you Steve!

13. Mohamud Ali says:

I thank you a lot Steve with this great effort. You made it easy for us.
Many thanks.
Mohamud

14. Stephen says:

real that’s wonderful calculations about /on submitting

15. Graham says:

Thank you for posting. This was very well written and easy to understand.

16. WilliB says:

Yeah nicely done. Much appreciated. Managed to grasp CIDR – even after a couple pilsner. 😉 Now I’m a cider fan too.

17. Guillermo says:

Really helped me to understand the concept of subnet masks and how they work. Thank you!

18. John says:

Great analogy Steven, really made the whole concept much clearer to me, thanks.

19. Hien says:

Very great analogy, thank you

20. It really sound well,of the subnet mask,the explanation give me a better understand, so much appreciate

21. “Well in early IPv4 networks address classes were used to identify the number of bytes allocated to the network component.” Please note that a comma is needed here and depending on where you will place it the provided information will be entirely different.

On the other hand, great explanation, I’m one step forward in understanding netmask

1. steve says:

Tks for the feedback I’ll correct the text
rgds
steve

22. Soumik says:

In the process of simplifying, you over complicated the whole process.
Content is really good. but explanation is over complicated

1. Deb says:

Lol gosh thought it was just me lost and confused

23. 4-bit subnetter says:

Thank you for the tutorial with examples

24. Mike says:

For decades I roamed the earth with the horrible awareness that I don’t grasp subnet masks and CIDR notations … 20 mins on this page and now it all seems so clear. Thanks!

25. Ine says:

Hi Steve
Thank you for this explanation, it is good as always. It was one part that I didn’t quite understand though. How do i know how many networks and hosts I can place on each network?

1. steve says:

Hi
If you take a class c network as an example the starting subnet mask is 255.255.255.0
The lower 8 bits you can use for subnetting.
if you use 4 bits for the sub network and 4 for hosts you get a subnet mask of
255.255.255.240
128+64+32+16=240
the network uses the high order bits
anyway 4 are for the network. With 4 bits you can have 16 values 0000 to 1111
now 0000 and 1111 are normally not allowed for network or host addresses therefore you can have 14 subnets and 14 hosts.
Hope that makes sense
You might also want to look at the worked examples
http://www.steves-internet-guide.com/subnetting-worked-examples/

1. Jake says:

Do you have to subtract 2 addresses from the network addresses as well as the host addresses? In the main post, A3 for the exercise questions, it says that you have 256 networks and 254 hosts. You’re only subtracting the all 1 and all 0 addresses from the hosts. What am I missing?

1. steve says:

Yes That is correct. It wasn’t previously possible to use the all1’s or all0s for subnets or hosts with classfull addressing. That situation changed with classless addressing. However use of all1s and all 0s is discouraged. See this very good cisco discussion on the subject

If you are worried about exam questions then you might find they state if all 1s and all 0s can be used.
Personally I would avoid all 1’s and all 0s
rgds
steve

26. Vivek says:

I thought I could never understand networking concepts. Your article is making me think, if things are explained in a way as you have done, I can and everyone can understand anything. Thanks Steve!!

27. DT says:

Thank you, the clearest explanation of masks and sub-netting I’ve found.

28. oliver says:

your blog is very helpful steve,u made me understand subnetting within 30 minutes yet i have been readin gjunks for almost 8 years without gasping anything