subnetting.net

Subnetting Tutorial

Welcome to the subnetting.net subnetting tutorial. This training session will teach you everything you need to know to pass any exam that requires TCP/IP knowledge. In addition, the methods you will learn here will allow you to not only solve subnetting questions, it will help you increase your speed and master TCP/IP concepts.

For many entry-level to intermediate computer networking exams, the need to quickly solve subnet based questions is apparent. In addition, the mastery of these concepts will give you a major advantage when you sit for the exam. For example, some have estimated that the CCNA exam has around 40% subnetting questions. When you are done with this tutorial, these questions will be no harder than simple addition or subtraction. To put this is real life terms, suppose the CCNA exam has 50 questions and you are given around 20 subnetting questions. When you learn to subnet, you should expect to ace these 20 questions. In other words, you would get 100% on 40% of the exam. This makes the remainder of your study time much more productive.

TCP/IP Subnetting Very Basic

The first thing we need to look at is - What is an IP address? How does it work?

Here is kind of a loose analogy that should make this very clear. Think of an IP address as your postal address. Let's take 191.54.38.15 for example. In our analogy, each set of numbers may represent a geographic area. As we move from the left to the right, the geographic area continuously becomes more and more specific.

191 = Your State
54 = Your Town
38 = Your Apartment building
15 = Your Apartment Number

To have TCP/IP, at some point, you must have a router. It doesn't make much difference if you have a router in your house, or a router in your business. They basically provide the same functionality. To further this analogy, think of a router as a post office. If you were going to send a letter (or in this case email) to another IP address, your router will decide what to do with that message.

If you put the outgoing letter by your mail box, a few things would happen based on the destination postal address (IP Address). If the letter was being mailed to someone in your own building, the router or postal carrier (switch) would know that it does not have to leave the building (your subnet) and would send it directly.

Intra-Subnet = The postal carrier (switch), would know that the destination address is local and would send it directly to the recipient. For example, if you were on IP 191.54.38.15 and you mailed your letter to 191.54.38.16, the letter would never leave your building. The concept of a subnet mask, is what tells the mail carrier which addresses are within a given network. As our analogy stands right now, we don't know how many apartments are in your building. We will get into the subnet masks later, for now let's assume there are 30 apartments in your building and the building next-door also has 30 apartments. To mail a letter within your own apartment building (subnet), a router/post office is not required.

Okay, easy enough. What happens if you want to send it to the building next-door?

Your mail carrier would take the letter to the post office in your town, and the post office would route the letter to the building next-door. This is what is called a "hop". So if your address was 191.54.38.15 and you wanted to send your letter to 191.54.39.15, your local router would simply forward your request to the Post Office that knows how to get to 191.54.39.15.

Now, suppose your letter was addressed to a different town in your state, let's say 191.55.1.10. The process is basically the same, but it will include more "hops". In this scenario, your mail carrier would take the letter to your local post office, it would then be sent to a hub within your state, then the destination town's post office, then finally to the end recipient.

The communication process would look something like this:

  • Your Town Post Office (ISP): I don't know anything about 191.55.x.x, I only know 191.54.x.x. Therefore, I'm going to send it to the "hub" post office (in IP terms this is basically what a default route does).
  • Hub Post Office: This letter is addressed to 191.54.x.x, those addresses are serviced by the post office in the destination town.
  • Destination Town: Ok, this letter is addressed to 191.54.x.x, I know where that is so I'm going to send this letter directly to the end recipient.
Of course, this is only a loose analogy and the IP addresses used to describe the process could have been anything. The takeaway from this first lesson is the router in your home or business, simply does not know where every possible destination IP address is located.

TCP/IP Address Construct

A TCP/IP address is a 32 bit, binary number that has been converted to decimal. Whenever the word binary comes up, many people immediately become concerned. No worries, this is going to be very easy. Here are a few simple definitions to help the process:

Octet = An octet is simply a group of 8 numbers. The IP address 191.168.1.1 has four octets: 191, 168, 1, and 1. I know I said there are 8 numbers and I only showed you four, but keep in mind that IP is in binary, not decimal. Each set of numbers represent 8 binary digits (zeroes or ones).

Bits = A bit is simply a single character. In other words, 32 bits equals 32 zeroes or ones.

Binary = A number system that is based on two characters - 0 & 1.

Okay, now let's convert our decimal IP address of 191.54.38.15 into binary:

Remember that each octet represents eight binary digits - Each placement of those binary digits represents a decimal number. To start, let's look at a simple three digit binary number:

---- ---- ----
4 2 1

Our decimal numbers on the bottom always start with 1 and double for each placement going from right-to-left. To convert to a decimal number, we will add a 1 above every decimal number we want to add together to get to our decimal number and a zero for every number we are not going to add.

Decimal Number 3
0 1 1
---- ---- ----
4 2 1

Now we simply add each decimal number (on the bottom) each time we see a binary 1. Thus, decimal 3 = 011

Decimal 4 = Binary 100
1 0 0
---- ---- ----
4 2 1


Decimal 5 = Binary 101
1 0 1
---- ---- ----
4 2 1


Decimal 191 = Binary 10111111
1 0 1 1 1 1 1 1
---- ---- ---- ---- ---- ---- ---- ----
128 64 32 16 8 4 2 1


Decimal 54 = Binary 00110110
0 0 1 1 0 1 1 0
---- ---- ---- ---- ---- ---- ---- ----
128 64 32 16 8 4 2 1


Decimal 38 = Binary 00100110
0 0 1 0 0 1 1 0
---- ---- ---- ---- ---- ---- ---- ----
128 64 32 16 8 4 2 1


Decimal 15 = Binary 00001111
0 0 0 0 1 1 1 1
---- ---- ---- ---- ---- ---- ---- ----
128 64 32 16 8 4 2 1


191 54 38 15
10111111 00110110 00100110 00001111

191.54.38.15 = 10111111.00110110.00100110.00001111

Subnet Mask

A subnet mask is used to determine where the network ends and the hosts begin. We get this information by converting the decimal numbers within the subnet mask to binary. The 1's in our binary subnet mask represents the network portion of our IP address, and the 0's represent the hosts. Here's an example:

IP Address: 192.168.1.0

Subnet Mask: 255.255.255.0

The first thing we do is convert our first octet to binary:

1 1 1 1 1 1 1 1
---- ---- ---- ---- ---- ---- ---- ----
128 64 32 16 8 4 2 1

When we add up all the decimal numbers underneath our binary 1's, we get 255 (128+64+32+16+8+4+2+1). In this example, the next two octets are also all 1's. And as you probably have guessed the fourth and final octet in our example is all 0's or all hosts.

So in binary, 255.255.255.0 is equal to:

11111111.11111111.11111111.00000000

Wherever our 1's stop and our zeros begin is called our network boundary:

11111111.11111111.11111111.|00000000

In this example, the first three octets are our network and the last one represents our hosts:

Subnet = 192.168.1.0

Hosts* = 192.168.1.1 - 192.168.1.254 (E.g. 192.168.1.1, 192.168.1.2, 192.168.1.3, etc...)

*The number of hosts on any network is determined by taking 2 to the power of the number of binary zero's. In this example, 8 0's = 2^8 = 256. However, we have to remove the first and last address from the pool of usable addresses. We will discuss this later, for now suffice it to say that the actual formula to determine how many hosts is (2^n)-2, where n = the number of binary zero's.

In our example n=8, so we have 2^8-2=256-2=254. We have a single network with 254 usable IP addresses for hosts (PC's, printers, etc...).

Now, let's take a look at what happens if we change our subnet mask:

IP Address: 192.168.1.0

Subnet Mask: 255.255.0.0

Just like the previous example, the first thing we need to do is to determine our network boundary by converting our decimal subnet mask to binary:

11111111.11111111.|00000000.00000000

Subnet = 192.168.0.0

Hosts = 192.168.0.1-192.168.255.254
Note that we can't use 192.168.0.0 as a host because it is the network address and 192.168.255.255 also can't be used because it is reserved for the broadcast address. However, all addresses in between the network address and the broadcast address can be assigned to hosts. Although it may look strange, addresses such as 192.168.0.255, 192.168.1.0, and 192.168.255.0 are all valid host addresses in the 192.168.0.0/16 network.

So now we can use the same formula to determine the number of assignable hosts - 16 zeros = 2^16-2 = 65,534 hosts.

IP Address Classes

There are five classes of IP addresses:

Class Purpose First Octet Range Maximum Hosts Total Networks
Class A Very Large Networks 1-126* 16,777,216 (2^24) 128 (2^7)
Class B Large Enterprise 128-191 65,536 (2^16) 16,384 (2^14)
Class C Small Business 192-223 256 (2^8) 2,097,152 (2^21)
Class D Multicast 224-239 N/A N/A
Class E Experimental 240-255 N/A N/A

*IP addresses that begin with 127 are reserved for various functions.

Some find it easier to remember these addresses via the first binary bits of each network type:

0 = Class A
10 = Class B
110 = Class C
1110 - Class D
1111 - Class E

Private Network Ranges

Each class of IP addresses has a private address range. These ranges were created to conserve public IP addresses. Instead of issuing a real IP address to every host on your network, you can issue a private address and translate the private address to a public one when you communicate with the Internet. For example, a network with 200 or even 200,000 hosts, could use just one public IP address. This process is called NAT/PAT and will be covered in another lesson.

Class A Private Address = 10.0.0.0/8. If an IP address begins with the number 10, it is a class A private address.

Class B Private Address = 172.16.0.0/12. If an IP address begins with 172.16-31, it is a class B private address.

Class C Private Address = 192.168.0.0/16. If an IP address begins with 192.168, it is a class C private address.

Chances are if you look at the IP address of your PC right now, you will have a private IP address in one of the above ranges. If you are at home, your router is likely running DHCP and issued your PC a private IP Address. When you communicate on the Internet, the public IP address that has been issued by your ISP will be used. The router in your home is translating your private address to your public address. Key Topic: A private IP address cannot be routed over the Internet, but can be routed throughout your internal network.

Subnet Mask Short-Hand

Now that we have basic subnetting figured out and know how to convert to binary, this will be a very brief section on subnet mask shorthand.

Instead of writing out a full subnet mask such as 255.255.255.0, we can shorten this to /24. To come to this number, we simply add the number of subnet bits (1's) in our subnet mask.

Subnet Mask Chart

Decimal Shorthand Binary
255.0.0.0 /8 11111111.00000000.00000000.00000000
255.128.0.0 /9 11111111.10000000.00000000.00000000
255.192.0.0 /10 11111111.11000000.00000000.00000000
255.224.0.0 /11 11111111.11100000.00000000.00000000
255.240.0.0 /12 11111111.11110000.00000000.00000000
255.248.0.0 /13 11111111.11111000.00000000.00000000
255.252.0.0 /14 11111111.11111100.00000000.00000000
255.254.0.0 /15 11111111.11111110.00000000.00000000
255.255.0.0 /16 11111111.11111111.00000000.00000000
255.255.128.0 /17 11111111.11111111.10000000.00000000
255.255.192.0 /18 11111111.11111111.11000000.00000000
255.255.224.0 /19 11111111.11111111.11100000.00000000
255.255.240.0 /20 11111111.11111111.11110000.00000000
255.255.248.0 /21 11111111.11111111.11111000.00000000
255.255.252.0 /22 11111111.11111111.11111100.00000000
255.255.254.0 /23 11111111.11111111.11111110.00000000
255.255.255.0 /24 11111111.11111111.11111111.00000000
255.255.255.128 /25 11111111.11111111.11111111.10000000
255.255.255.192 /26 11111111.11111111.11111111.11000000
255.255.255.224 /27 11111111.11111111.11111111.11100000
255.255.255.240 /28 11111111.11111111.11111111.11110000
255.255.255.248 /29 11111111.11111111.11111111.11111000
255.255.255.252 /30 11111111.11111111.11111111.11111100

There is no need to memorize these, as you practice they will become second nature.

Reserved Host Addresses

As mentioned earlier, for every subnet, the first and the last IP addresses are reserved:

First IP Address = Network ID

Last IP Address = Broadcast Address. The broadcast address is used for a specific type of network traffic that is destined for every device attached to a network.

Example:

IP Address = 192.168.1.1
Subnet Mask = 255.255.255.0
Network ID = 192.168.1.0
Broadcast Address = 192.168.1.255
Usable IP's = 192.168.1.1 - 192.168.1.254

Subnet 0

In the not too distant past, it was considered bad practice to use the first network in your subnet range. For example, if we had the IP range of 192.168.1.1 255.255.255.192, our networks would be:

192.168.1.0, 192.168.1.64, 192.168.1.128, 192.168.1.192

In this example, the first network (192.168.1.0) would not be used. However, this command in Cisco equipment is really never used and the default Cisco settings assume subnet 0 will always be used. If you take a Cisco exam and they indicate that the subnet zero command is on, you have to remove the first network from your calculations. However, chances are this will not happen on any current exam. You should always assume the first network can be used unless you are told otherwise.

Subnetting Cheat Sheet

Now that we have all the basics down, we are going to start the actual lesson on subnetting.

The first thing we are going to do is create a Subnet Cheat Sheet. This will help you solve subnetting questions very quickly and without errors. I highly recommend you follow along and create your own subnet cheat sheet. In addition, this is the first thing you should write down on your scratch pad when you sit for the actual CCNA exam. Do this before you even look at the first question!

The first step is to create a grid with three columns and 14 rows:

BitsBlock Size / ExponentsDecimal Mask Value
01255
12254
24252
38248
416240
532224
664192
7128128
8256
9512
101024
112048
124096

Label the columns: Bits, Block Size/Exponent, and Decimal Mask Value:

BitsBlock Size / ExponentsDecimal Mask Value
01255
12254
24252
38248
416240
532224
664192
7128128
8256
9512
101024
112048
124096

For the bits column, begin at the top with a zero and count all the way to 12:

BitsBlock Size / ExponentsDecimal Mask Value
0
1
2
3
4
5
6
7
8
9
10
11
12

For the Block Size / Exponent column, start at the top with a 1, and double the preceding number all the way to the end:

BitsBlock Size / ExponentsDecimal Mask Value
01
12
24
38
416
532
664
7128
8256
9512
101024
112048
124096

In the decimal value column, start at the row that corresponds to the block size / exponent of 128, and enter the value 128. For each row going up, add the value from the row above in the Block Size / Exponent column. Your final sheet should look like this:

BitsBlock Size / ExponentsDecimal Mask Value
01255
12254
24252
38248
416240
532224
664192
7128128
8256
9512
101024
112048
124096

The rows corresponding to the bit values 0-7 represent one IP octet. The remaining rows are a convenience to quickly determine various exponents. E.g. 2^11 = 2048 or 2^10 = 1024.

Putting it all Together

For this next section, I suggest you create your own cheat sheet so you do not have to scroll up to follow along. There are basically three types of subnetting questions that will be asked in our practice section, on any exam, or you need to answer in real life. We will go over these question types and show you how to use the cheat sheet to find the answer very quickly.

Question Type 1: What is the Network ID, Broadcast Address, First Usable IP, or Last Usable IP on the subnetwork that the node 192.168.1.15/26 belongs to?

No matter which of the four criteria the question asks, you should always follow these identical steps. This makes solving the actual question very easy.

Step 1. Convert the shorthand subnet mask to decimal.

  • /26 = 255.255.255. + Two additional subnet bits.
  • Go to your cheat sheet, start at the bottom (128) and count up two, starting with 128. You should get to 192.
  • Thus, our decimal subnet mask is 255.255.255.192

Step 2. Determine the block size.

  • The block size is listed in the block size column parallel to your decimal mask.
  • The block size is 64.

Step 3. What is my Network ID?

  • Since we are working in the fourth octet and the block size is 64, the first network is 192.168.1.0.

Step 4. What is the next Network ID?

  • Again, we look at our block size of 64 to determine the next network is 192.168.1.64.
  • Network ID (First IP in the subnet): 192.168.1.0
  • Broadcast address (last IP in the subnet): 192.168.1.63
  • First Usable IP (the address after the network ID): 192.168.1.1
  • Last Usable IP (the address before the broadcast address): 192.168.1.62

Notes: The block size determines the networks. Since the block size is 64, our networks are 192.168.1.0, 192.168.1.64, 192.168.1.128, and 192.168.1.192. To determine your network, you just have to find the range that includes your IP address. In this example, it is the first network. If your IP was 192.168.1.72, you would belong to the second network 192.168.1.64 - 192.168.1.127.

Let's quickly go through one more: Enter the last valid host on the network that the host 172.30.118.230/23 is a part of:

Step 1. Convert the shorthand subnet mask to decimal.

  • /23 = 255.255. + Seven additional subnet bits.
  • Go to your cheat sheet, start at the bottom (128) and count up seven, starting with 128. You should get to 254.
  • Thus, our decimal subnet mask is 255.255.254.0.

Step 2. Determine the block size.

  • The block size is listed in the block size column parallel to your decimal mask.
  • The block size is 2.

Step 3. What is my Network ID?

  • Since we are working in the third octet and the block size is 2, the first network is 172.30.118.0. (2 * 59 = 118). We are simply looking for the largest multiple of the block size without going over the given octet number (118).

Step 4. What is the next Network ID?

  • Again, we look at our block size of 2 to determine the next network is 172.30.120.0 (118 + 2).
  • Network ID (First IP in the subnet): 172.30.118.0
  • Broadcast address (last IP in the subnet): 172.30.119.255
  • First Usable IP (the address after the network ID): 172.30.118.1
  • Last Usable IP (the address before the broadcast address): 172.30.119.254 (This is the answer to the specific question that was asked.)

Question Type 2: How many subnets and hosts per subnet can you get from the network 192.168.1.0 255.255.255.224?

Step 1: Determine the classful mask.

  • 192 = Class C
  • Class C default mask = 255.255.255.0

Step 2: Determine how many additional subnet bits exist beyond the classful boundary.

  • Since this is a class C address, we are only going to look at the fourth octet. Since the decimal mask is 224, we know there were three subnet bits added (counting up from the bottom of our cheat sheet).

Step 3: Determine how many host bits remain.

  • We are still only working in the fourth octet. Since three bits went to the subnet in step 2, we have five host bits (0's) remaining.

Step 4: Find the exponents of both subnet bits and host bits using the cheat sheet:

  • Subnet Bits = 2^3 = 8
  • Host Bits = 2^5-2 = 30

The answer is 8 subnets and 30 hosts per subnet.

Question Type 3: You have been asked to create a subnet mask for the 172.16.0.0 network. Your organization requires 900 subnets, with at least 50 hosts per subnet. What subnet mask should you use?

Step 1: Determine how many subnet bits (1's), you have to add to the classful boundary to cover the number of required subnets.

  • The IP address given was a class B address, making the first 16 subnet bits static.
  • Using the cheat sheet, find the exponent of 2 that is equal to or greater than the number of subnets we require (900). We can quickly see that 10 additional subnet bits will give us 1,024 subnets. Make note of the corresponding subnet mask. In this case, 255.255.255.192. The third octet is eight 1's, and the four is two 1's. We can count up from the bottom on our cheat sheet to get to 192.

Step 2: Confirm the number of remaining 0's will cover our required hosts. In this case, there are 6 remaining 0's - 2^6-2=62, which is more than enough for our host requirements.

Our subnet mask is 255.255.255.192. Giving us 1024 subnets and 62 hosts per subnet.

For more examples, visit our Tips & Tricks page.

Advanced Topics

Variable Length Subnet Mask (VLSM)

You are a network administrator and you have been assigned the task of setting up the IP network. You have a single class C IP address range and have to setup the following networks:

  • Network A = 100 Hosts
  • Network B = 40 Hosts
  • Network C = 20 hosts
  • Network D = 10 hosts
  • Network E = 6 Hosts
  • Network F = 2 Hosts
IP Range Network Num IPs Subnet Mask
0-127 Network A 128 /25
128-191 Network B 64 /26
192-223 Network C 32 /27
224-239 Network D 16 /28
240-247 Network E 8 /29
248-251 Network F 4 /30

It's really that easy:

  1. Add up all host requirements to make sure you have enough in a single block.
  2. Work from the top down (largest host requirements) removing the number of required hosts for each network.

Route Summarization

A summarized route can increase performance of a router by limiting the route table and reducing routing traffic. Consider the following question:

You have a router with four different LANs attached:

  • Network 1 = 192.168.0.0/24
  • Network 2 = 192.168.1.0/24
  • Network 3 = 192.168.2.0/24
  • Network 4 = 192.168.3.0/24

How would you summarize these networks with a single statement?

Step 1: Convert all four IP addresses to binary and align them in a list:

Decimal Binary
192.168.0.011000000.10101000.00000000.00000000
192.168.1.011000000.10101000.00000001.00000000
192.168.2.011000000.10101000.00000010.00000000
192.168.3.011000000.10101000.00000011.00000000

Step 2: In the binary section of the grid, count the common bits from left to right. In this example, the first two octets are identical, so we know the first 16 bits are common across all four networks. In addition, the first six bits of the third octet are also common. It may be easier to draw a line through all four binary numbers at the point where the bit pattern changes.

Step 3: Count the number of common bits is the mask. In this example, the first 22 bits are common across all four networks. The answer is 192.168.0.0/22.

Let's go through one more:

  • Network 1 = 10.10.0.0/16
  • Network 2 = 10.11.0.0/16
  • Network 3 = 10.12.0.0/16
  • Network 4 = 10.13.0.0/16
  • Network 5 = 10.14.0.0/16
  • Network 6 = 10.15.0.0/16

Here is the list in binary:

Decimal Binary
10.10.0.000001010.00001010.00000000.00000000
10.11.0.000001010.00001011.00000000.00000000
10.12.0.000001010.00001100.00000000.00000000
10.13.0.000001010.00001101.00000000.00000000
10.14.0.000001010.00001110.00000000.00000000
10.15.0.000001010.00001111.00000000.00000000

In this example, the first octet is identical and so are the first five bits of the second octet. 8+5=13. The answer is 10.8.0.0/13. The 8 is derived from our block size of 8 (refer to your cheat sheet).


Now it's time to Practice Subnetting!

☆ Top 10 High Scores ☆
View Top 1000 All Stars
RankAll Star NameScore
1Jakub70
2Darrell69
3Pavel58
4Peter3Name57
5Russ53
6Francois van Niekerk52
7Cannabista52
8Ranjani48
9MK47
10TWGT46

Twitter Facebook Google+