You are on page 1of 37

Summary

Classful addressing Class Range Allocation A 1-126 N.H.H.H B 128-191 N.N.H.H C 192-223 N.N.N.H D 224-239 Not applicable N=Network H=Host

...

Introduction
IPv4 addresses are 32 bits in length. Each 8-bit field, or octet, is represented by a decimal number between 0 and 255 (for example, 129.150.182.31). Each IPv4 address identifies a network (network number) and a unique interface on that network (host number) Originally, the 32-bit IPv4 address consisted simply of an 8-bit network number field (which specified the particular network a host was attached to), and a rest field, which gave the address of the host within that network. This format was picked before the advent of local area networks (LANs), when there were only a few, large, networks such as the ARPANET. This resulted in a very low count (256) of network numbers being available, and very early on, as LANs started to appear, it became obvious that that would not be enough. As a kludge, the definition of IP addresses was changed to allow three different sizes of the network number field (and the associated rest field), as specified in the table below:

Class Class A Class B Class C Class D (multicast) Class E (reserved)

Leading Value 0 10 110 1110 1111

Network Number Bits 7 14 21

Rest Bits 24 16 8

The value of the high-order bits (first three bits) determine which portion of the IPv4 address is the network number and which portion is the host number. That means that netmask was essentially was encoded in the first three bits.

The network numbers are divided into three classes: Class A, Class B, and Class C. This addressing scheme is called classful IPv4 addressing.

Old Classes A, B and C of Unicast Addresses


A system uses unicast addresses when it needs to communicate with another system. There are three "old" classes of unicast addresses: Class A, Class B, and Class C. Class A addresses are for very large networks and provide 16,777,214 host addresses. Class A address is split by the first byte with the first byte defining network number and that last three bytes defining host number. The first bit in class A address is always 0. This allows for up to 128 Class A networks but two (10 and 127) are reserved for special purposes. Zero network also is has special purpose. For example 10.102.2.113 is class A unicast address The Internet Assigned Numbers Authority (IANA) has reserved two class A network for special purposes:
y y

10.0.0.0 10.255.255.255 for private networks. These addresses are not routed in the Internet. Refer to RFC 1918 for additional details. 127.0.0.1 is reserved for the loopback interface.

The remaining 24 bits define the host number. Class B addresses are for large networks and provide 65,534 host addresses. In class B address both network number and host number occupies two bytes. The first two bits of class B address are 10, those two bits and the next 14 bits define the network number, and the remaining 16 bits define the host number. This allows for 16,384 Class B networks. The IANA has reserved 172.16.0.0172.31.255.255 for private networks. These addresses are not routed in the Internet. Refer to RFC 1918 for additional details. Class C addresses are for small-sized and mid-sized networks and provide 254 host addresses. In class C address network number occupies first three bytes and host number occupies the last byte. The first three bits are 110, those three and the next 21 bits define the network number, and. the remaining eight bits define the host number. This allows for up to 2,097,152 Class C networks. The IANA has reserved 192.168.0.0192.168.255.255 for private networks. These addresses are not routed in the Internet. Refer to RFC 1918 for additional details.

This first round of changes was enough to work in the short run, however; an IP address shortage still developed. The principal problem was that most sites were too big for a "class C" network number, and received a "class B" number instead. With the rapid growth of the Internet, the available pool of class B addresses (basically 214, or about 16,000 total) was rapidly being depleted. Classful networking was replaced by Classless Inter-Domain Routing (CIDR), starting in about 1993, to solve this problem (and others). Early allocations of IP addresses by IANA were in some cases not made very efficiently, which contributed to the problem. (However, the commonly-held notion that some organizations unfairly or unnecessarily received class A networks is a canard; most such allocations date to the period before the introduction of address classes, when the only thing available was what later became known as "class A" network number.) Broadcast Addresses A broadcast address is the address that reaches all systems on the network. A broadcast means that data is simultaneously sent to all of the hosts on the local area network (LAN). In Solaris, the default broadcast address is an address that has a host number of all ones when represented in binary. An example of a broadcast address is 128.50.255.255. You use the ifconfig utility to configure an interfaces broadcast address. Multicast Addresses Multicasting is a very efficient way to send large amounts of data to many systems at the same time. A multicast address identifies interfaces that belong to a specific multicast group. Packets that are sent to a multicast address are received by all interfaces that are associated with the multicast address. If the first four bits are 1110, which makes the first field an integer value between 224 and 239, the address is a multicast address. The remaining 28 bits comprise a group identification number for a specific multicast group. An IPv4 multicast address is a destination address for one or more hosts, while a Class A, B, or C address is an address for an individual host. The IPv4 multicast address maps to an Ethernet multicast address so that the network interface listens for a multicast traffic. The low-order 23 bits of the IPv4 multicast address are placed into the low-order 23 bits of the Ethernet multicast address. Therefore, an IPv4 multicast address of 224.0.0.1 maps to 01:00:5e:00:00:01.

Introducing Subnetting and VLSM


The Internet is composed of many routers that interconnect different networks. Each router interface must be on a unique network and must have a unique address. Assigning different IP addresses to different networks is required because of the IP addressing scheme required by routers. Subnetting and VLSMs are two ways of dividing an assigned network address into multiple, smaller networks for use within an organization. These smaller networks are referred to as subnetworks.
3

Subnetting You can divide a network into subnetworks to:


y y y y y

Isolate network traffic within local subnets, therefore reducing contention for network bandwidth Secure or limit access to a subnet Enable localization of specific network protocols to a subnet Allow the association of a subnet with a specific geography or a department Allow administrative work to be broken into logical units

The basic idea of subnetting is to divide the standard host number field into two parts: the subnet number and the host number on that subnet. That leads us from two level hierarchy (NetworkNumber/HostNumber) to three level hierarchy (NetworkNumber/SubnetNumber/HostNumber).

The /etc/inet/netmasks File


A network mask (netmask) is defined for each of the three classes of IPv4 addresses so that the system can compute the network number from any given IPv4 address. The /etc/inet/netmasks file is linked to the /etc/netmasks file. The file enables the permanent assignment of a netmask. When the system reboots, this file is consulted before the configuration of the network interfaces. The /etc/rcSd/S30network.sh script consults the /etc/inet/netmasks file at run level S. At run level 2, the /etc/rc2.d/S72inetsvc script can recalculate the netmask using the Network Information Service (NIS) maps or Network Information Service Plus (NIS+) databases. For every network that is subnetted, an individual line is entered into this file. The fields in the /etc/inet/netmasks file list the network number and the netmask definition. An example of an entry for a subnetted Class B network is: 172.16.0.0 255.255.255.0 An example of an entry for a subnetted Class C network is: 192.168.43.0 255.255.255.240 If a netmask is not specified in the /etc/inet/netmasks file for the system to use during system startup, a default Class A, B, or C netmask is assumed. You can also configure an interfaces netmask from the command line by using the ifconfig utility. # ifconfig qfe0 192.168.1.1 netmask 0xffffff00 up or # ifconfig qfe0 192.168.1.1 netmask 255.255.255.0 up
4

Contiguous Netmasks
RFC 950 recommends the use of contiguous subnet masks. A contiguous subnet mask is one that only uses contiguous high-order bits. For example: 11111111 11111111 11111111 11110000 Noncontiguous Netmasks Although RFC 950 recommends only the use of contiguous subnet masks, nothing prevents the use of noncontiguous subnet masks. For example: 11111111 11111111 11111111 01001010 However, using noncontiguous subnet masks makes administration more difficult. Avoid the use of noncontiguous subnet masks if at all possible.

VLSM
One of the major problems with supporting only a single subnet mask across a given network number is that once the mask is selected, it locks the organization into a fixed number of fixedsized subnets. For example, a Class B subnet that is masked with 255.255.252.0 yields additional 64 subnets with 1024 hosts per subnet. If you need 1028 subnets with some as large as 1000 hosts and some as small as 64 hosts you are out of luck. Similar to the IP space separation into A,B, and C classes VLSM permits organization to use subnets with different number of hosts. In 1985, RFC 950 specified how an IP network could use multiple subnet masks. The key idea here is similar to idea of class A,B,and C network recursively applied to host part of the address. Variable-Length Subnet Masking (VLSM) is the same concept as CIDR, but the term is now obsolite. Because the old class distinctions are ignored, the new system was called classless routing. This led to the original system being called, classful routing. When an IP network is assigned more than one subnet mask, it is considered a network with VLSMs because the extended-network numbers have different lengths at each subnet level. To provide the address mask information the ICMP protocol was extended by adding a new pair of ICMP message types, "Address Mask Request" and "Address Mask Reply", analogous to the "Information Request" and "Information Reply" ICMP messages (type 17 and 18 messages). In key idea was that netmask becomes the part that is nessesary for the interpretation of the address and can be specified by the number of the bit in network part of the address, for example 10.10.10.10/24 mean C class network (24-bit network part of of the address and 8-bit host part of the address) Two of the main advantages to assign more than one subnet mask to a given IP network number are:
y

Multiple subnet masks permit more efficient use of an organizations assigned IP address space.
5

Multiple subnet masks permit route aggregation, which can significantly reduce the amount of routing information at the backbone level within an organizations routing domain.

An example of a VLSM entry is:

12.0.0.0 255.255.0.0 12.3.0.0 255.255.255.0 12.3.254.0 255.255.255.224 Note VLSM subnet masks syntax has been recognized since the Solaris 2.6 OE.

CIDR
VLSM Subnetting, documented in RFC 950, originally referred to the subdivision of a classbased network into subnetworks, but it was generalized for the subdivision of the whole IP addess space into more flexible CIDR blocks instead of fixed A,B and C networks. Classless Inter-Domain Routing (CIDR, pronounced "cider" or "cedar") was introduced in 1993 and is the latest refinement to the way IP addresses are interpreted. It replaced the previous generation of IP address syntax; classful networks. It allowed increased flexibility when dividing ranges of IP addresses into separate networks and thereby promoted:
y y

More efficient use of increasingly scarce IPv4 addresses. Greater use of hierarchy in address assignments (prefix aggregation), lowering the overhead of the Internet-wide routing (routes aggregation)

CIDR allows single routing entries to refer either to the larger block or to its individual constituents. This permits a single, general routing entry to be used through most of the Internet, more specific routes only being required for routers in the subnetted block. A subnet mask is a 32-bit number that determines how an IP address is split into network and host portions, on a bitwise basis. For example, 255.255.0.0 is a standard class B subnet mask, since the first two bytes are all ones (network), and the last two bytes are all zeros (host). In a subnetted network, the network portion is extended. For example, a subnet mask of 255.255.255.0 would subnet a class B address space using its third byte. Using this scheme, the first two bytes of an IP address would identify the class B network, the next byte would identify the subnet within that network, and the final byte would select an individual host. Since subnet masks are used on a bit-by-bit basis, masks like 255.255.240.0 (4 bits of subnet; 12 bits of host) are perfectly normal.

In a traditional subnetted network, several restrictions apply, which have been lifted by CIDR. However, if older, non-CIDR routing protocols (such as RIP version 1) are in use, these restrictions must still be observed. 1. Identical subnet masks. Since non-CIDR routing updates do not include subnet masks, a router must assume that the subnet mask it has been configured with is valid for all subnets. Therefore, a single mask must be used for all subnets with a network. Different masks can be used for different networks. Based on this assumption, a router can exchange subnet routes with other routers within the network. Since the subnet masks are identical across the network, the routers will interpret these routes in the same manner. However, routers not attached to the subnetted network can't interpret these subnet routes, since they lack the subnet mask. Therefore, subnet routes are not relayed to routers on other networks. This leads to our second restriction.

2. Contiguous subnets. A subnetted network can't be split into isolated portions. All the subnets must be contiguous, since routing information can't be passed to non-members. Within a network, all subnets must be able to reach all other subnets without passing traffic through other networks. The Internet is composed of many routers that interconnect different networks. Each router interface must be on a unique network and must have a unique address. Assigning different IP addresses to different networks is required because of the IP addressing scheme required by routers. Subnetting and VLSMs are two ways of dividing an assigned network address into multiple, smaller networks for use within an organization. These smaller networks are referred to as subnetworks. VLSM, conceptually a stepping stone from subnetting to CIDR, lifted the restrictions of subnetting by relaying subnet information through routing protocols.

Recommended Links
IP 101 All About IP Addresses Classless Inter-Domain Routing - Wikipedia, the free encyclopedia Online IP CIDR Calculator IP Calculator - IP Subnetting

Quiz
Q1. A subnets mask is 255.255.255.224. How many nodes can this subnet have? A: 254-224=30
7

Q2. A subnets mask is 255.255.255.240. How many nodes can this subnet have? A: 254-40=14 Q3. A subnets mask is 255.255.255.192. How many nodes can this subnet have? A: 254-192=62 Q4. You have a class C subnet. You would like divide it up into 30 more subnets by "subnetting" ? What would be the subnet mask? A: 255.255.255.248 The length of subnet section to accomodate 30 subnet should be 5 bits. That means that host contans 3 bits Mask = 256-8=248 Q5. You have a class C subnet. You would like to divide it up into 10 more Subnets by "subnetting" . How many hosts can you have per subnet? A: 14 Host part will be 4 bits. Max hosts per subnet = 2^4 -2 = 14

Q6. You have a class C subnet. You would like divide it up into 12 more subnets by "subnetting". However you also have to have at least 13 hosts per subnet. Can you do it ? A: Yes. See explanation to the answer to Q5 Q7. You have a class C subnet and need 48 nodes per subnet. How many subnets can you have ? A: 2 # max hosts/subnet = 2^N -2 , that means host part should be 6 bits That means M can be at most 2 bits # max subnets = 2^M -2 = 2 Q8. Your class C network has been subnet-ed. Mask for the new subnets is 255.255.255.224. How many subnets and how many nodes per subnet can you have ?

A: 254-224=30 Q9. You have divided your class C network into 2 subnets. Your subnet mask is 255.255.255.192. What are the ranges of IPs for your subnets ? Your Network address before subnetting was 200.252.144.0 A: 200.252.144.65-200.252.144.126 and 200.252.144.129-200.252.144.190 explanation: M=2 N=6 The First range = 2^6+1 to 2^7-2 = 65 to 126 The Second range = 65+2^6 to 126+2^6 = 129 to 190 Q10. Your previous Network Administrator had subnneted your class C network into many subnets. Only info you have is that one of the IP range was 200.252.144.33 through 128.252.144.46. How many subnets did he make ? what was the mask ? A: 14, 255.255.255.240 explanation: We see that the subnet has 14 nodes. That means N=4 (2^4-2 = 16). M= 8-4 =4 . Number of Subnets = 2^M -2 = 14. Mask = 128+64+32+16 (add 4 bits) 255.255.255.240 Q11. You have a class B subnet. You would like divide it up into 30 more subnets by "subnetting" ? What would be the subnet mask ? A: 255.255.248.0 Refering to the formulas in the "SUBNETTING FORMULAS" section : M = 5 (since max number of subnets would be 30 if M = 5) Mask = 2^7+2^6+2^5+2^4+2^3 = 248 Q12. You have a class B subnet. You would like to divide it up into 10 more subnets by "subnetting" . How many hosts can you have per subnet? A: 4094 Refering: to the formulas in the "SUBNETTING FORMULAS" section. M = 4 (since max number of subnets would be 6 if M = 3)

N = 16-4 = 12 Max hosts per subnet = 2^12 -2 = 4094 Q13. You have a class B subnet. You would like to divide it up into 12 more subnets by "subnetting". However you also have to have at least 4000 hosts per subnet. Can you do it? A: Yes. Refering: to the formulas in the "SUBNETTING FORMULAS" section. M = 4 (since max number of subnets would be 6 if M = 3) N = 16-M = 12 Max hosts per subnet = 2^12 -2 = 4094 Q14. You have a class B subnet (128.252.0.0). You want to divide it into 2 subnets. will the ranges of IPs? A: 128.252.65.1 to 128.252.126.254 AND 128.252.129.1 to 128.252.190.254 explanation: Referring to the 'SUBNETTINg FORMULA" section: M=2 N=14. 2^(14-8)+1=65 2^(14-8+1)-2=126 Q15. What IP network addresses are set-aside for class B (for private use)? a. 128.0.0.0 (mask 255.255.0.0) b. 128.252.0.0 (mask 255.255.0.0) c. 172.16.0.0 (mask 255.240.0.0) d. 172.16.0.0 (mask 255.255.0.0) e. 172.240.0.0 (mask 255.255.0.0) A: C Q16. IP classes and their ranges (A-C): a. 1-127, 128-191, 192-223 b. 1-127, 128-191, 192-254 What

10

c. 1-126, 128-192, 193-223 d. 1-126, 128-191, 192-223 A: D Q17. What IP network addresses are set aside for class C (for private use) ? a. 172.16.0.0 (mask 255.240.0.0) b. 172.16.0.0 (mask 255.255.0.0) c. 196.168.0.0 (mask 255.255.0.0) d. 192.168.0.0 (mask 255.255.0.0) e. 198.168.0.0 (mask 255.255.255.0) A: D Q18. What leading bit values in the IP address indicate a class A and Class B address ? a. 0 and 10 b. 0 and 11 c. 1 and 11 d. 01 and 10 e. 10 and 110 A: A Q19. What leading bit values in the IP address indicate a class C address ? a. 0 b. 01 c. 10 d. 11

11

e. 110 A: C Q20. Consider the IP address 128.252.144.84. What is the network id and what is the node id ? assume classful networking. a. 0.0.0.0 and 128.252.144.84 b. 128.0.0.0 and 252.144.84 c. 128.252.0.0 and 144.84 d. 128.252.144.0 and 84 A: C (class B network)

Q21. You have a class C subnet. You would like divide it up into 8 more subnets by "subnetting" ? What would be the subnet mask ? a. 255.255.255.192 b. 255.255.255.224 c. 255.255.255.240 d. 255.255.255.248 d. 255.255.255.252 A: C Explanation: Refer to the formulas in the "SUBNETTING FORMULAS" section. M = 4 (since max number of subnets would be 6 if M = 3) Mask = 2^7+2^6+2^5+2^4 = 240 Q22. You have a class C subnet. You would like divide it up into 5 more subnets by "subnetting" . How many hosts can you have per subnet ?

12

a. 30 b. 31 c. 30 d. 62 e. 126 A: C Explanation: Refering: to the formulas in the "SUBNETTING FORMULAS" section. M = 3 (since max number of subnets would be 2 if M = 2) N = 8-M = 5 Max hosts per subnet = 2^5 -2 = 30 Q23. You have a class C subnet. You would like divide it up into 5 more subnets by "subnetting". However you also have to have at least 31 hosts per subnet. Can you do it ? a. Yes b. No ans: B Explanation: Answer is NO (Even though you are asking for 5x31=155 nodes) Referring: to the formulas in the "SUBNETTING FORMULAS" section. M = 3 (since max number of subnets would be 2 if M = 2) N = 8-M = 5 Max hosts per subnet = 2^5 -2 = 30 Q24. You have a class C subnet. You would like divide it up into subnets by "subnetting". You have to have at least 24 nodes per subnet. How many subnets can you have ?
13

a. 2 b. 6 c. 7 d. 8 e. 14

A: B Explanation: Refering: to the formulas in the "SUBNETTING FORMULAS" section: # max hosts/subnet = 2^N -2 , that means N has to be at least 5 That means M can be at most 3 # max subnets = 2^M -2 = 6 Q25. Your class C network has been subnet-ed. Mask for the new subnets is 255.255.255.248. How many subnets and how many nodes per subnet can you have ? a. 30, 6 b. 30, 7 c. 62, 2 d. 62, 6 e. 62, 7 A: A Q26. You have divided your class C network into 6 subnets. Your subnet mask is 255.255.255.224. What are the ranges of IPs for your subnets ? Your Network address before subnetting was 200.252.144.0 a. 32-62, 64-93, 96-125, 128-157, 160-189, 192-221 b. 33-63, 65-94, 97-126, 129-158, 161-190, 193-222
14

c. 34-64, 66-95, 98-127, 130-159, 162-191, 194-223 d. 35-65, 67-96, 99-128, 131-160, 163-192, 195-224 A: B Explanation: M=3 N=5 From the formulas in "SUBNETTING FORMULAS" section : The First range = 2^5+1 to 2^6-2 = 33 to 62 The 2nd range = 33+32 to 62+32 = 65 to 94 The 3rd range = 65+32 to 94+32 = 97 to 126 The 4rd range = 97+32 to 126+32 = 129 to 158 The 5th range = 129+32 to 158+32 = 161 to 190 The 6th range = 161+32 to 190+32 = 193 to 222 Q26. Your previous Network Administrator had subnneted your Class C network into many subnets. Only info you have is that the mask was 255.255.255.224 How many subnets did he make ? How many nodes were there per subnet ? a. 2, 62 b. 7, 30 c. 6, 30 d. 6, 62 e. 7, 62 A: C Explanation: 224=128+64+32 . That means number borrowed 1 bits = 3. M=3. Subnets = 2^M -2 = 6 . Nodes per subnet = 2^N - 2 = 30 . Q27. You have a class B subnet. You would like divide it up into 5 more subnets by "subnetting" . How many hosts can you have per subnet ? a. 30
15

b. 1022 c. 2046 d. 4094 e. 8190

A: E

Explanation:

Refering: to the formulas in the "SUBNETTING FORMULAS" section. M = 3 (since max number of subnets would be 2 if M = 2) N = 16-M = 13 Max hosts per subnet = 2^13 -2 = 8190 Q30. You have a class B subnet. You would like divide it up into 5 more subnets by "subnetting". However you also have to have at least 6000 hosts per subnet. Can you do it ? a. Yes b. No. A: B Explanation:

Refering to the formulas in the "SUBNETTING FORMULAS" section. M = 3 (since max number of subnets would be 2 if M = 2) N = 16-M = 13 Max hosts per subnet = 2^13 -2 = 3070
16

Q31. Class D IP address range an its use? a. 192-223, broadcast b. 224-239, multicast c. 224-255, broadcast d. 192-255, multicast

A: B Q32. Class E IP address range and its use ? a. 240-255, experimental b. 224-239, multicast c. 224-255, multicast d. 192-255, experimental A: A Q33. CIDR stands for ____________________? a. Carrier International Domain Routing b. Carrier Independent Domain Routing c. Classless Inter-Domain Routing d. Cross-platform Inter-Domain Routing A: C 479. Which IP-class provides the fewest numbers of Hosts?

a. Class A b. Class B

17

c. Class C d. Class D

ans: D

480. You see the following subnet addresses ; what is the subnet mask ?

128.252.4.0 128.252.8.0 128.252.12.0 128.252.16.0

a. 255.255.255.0 b. 255.255.192.0 c. 255.255.240.0 d. 255.255.252.0

ans: D

Subnetting
Subnetting - Just what is it and why do we use it? A Very Brief History

18

When networks were first used all hosts on the network were allocated hostnames such as PC 1 or admin_PC but it was soon discovered that it was hard to keep track of all of these names and then routing across a WAN was almost impossible. A RFC (request for comment) was submitted which suggested that we could allocate numbers to hosts on networks instead of hostnames. The current implementation of this scheme is IP version 4 although IPv6 is now replacing this. The idea is that every address would be made up from four groups of eight binary numbers. Each group of eight binary numbers is known as an octet. Because we struggle to write numbers out in binary we usually convert them into decimal but computers and network devices still see all numbers in binary because they can only recognise on and off signals so either a 0 or a 1. How it Works Each number you allocate to a host on your network will be in groups of four separated by a dot e.g 192.168.1.23. This was working just fine until somebody realised that we needed to identify which parts of the address were for the network and which were for the host on the network. To deal with this we began to add subnet masks to IP addresses. You must use subnet masks even if you only use a basic IP numbering scheme on your network. The rules are that 255.0.0.0 is used for Class A addresses 255.255.0.0 is for Class B and 255.255.255.0 is for Class C addresses. The 255 tells the router that this part of the address is reserved for the network portion of the address.
Network Class A 255 Host 0 Host 0 Host 0

Network Class B 255

Network 255

Host 0

Host 0

Network Class C 255

Network 255

Network 255

Host 0

But is Still Wasn't Enough When this addressing scheme was devised nobody could have predicted the exponential growth of PC use in companies and then homes all over the world. Instead of only huge companies paying millions for a huge computing device now most people could afford them and they were big enough to put into a box and carry home.

19

VLSM was devised as an interim measure to prevent us running out of IP addresses. Variable length subnet masking allows you to cut your subnet down to even smaller portions which mean you can conserve huge amounts of wasted addresses. Instead of being stuck with the below example you could get far more use out of your IP addresses. Class C 192.168.1.0 255.255.255.0 means you can only use the last octet for host addresses on your network. You are not allowed to use 0 at the end because that is your subnet number. You are not allowed to use 255 on the end because that tells the network that it is a broadcast so here are your allowed host numbers. Anything from 192.168.1.1 to 192.168.1.254 so you can only have one large network with 254 hosts on. Imagine 254 hosts all passing huge amounts of traffic across the network.

VLSM
VLSM - A Very Brief History You read in the subnetting section that we were about to run out of IP addresses. One way to preserve IP addresses was to allocate certain ranges of IP address which can be used for free on your network so long as you don't use them to get out to the internet. If you want to get out to the internet using them then your router can just swap it for a routable address using a technique called Network Address Translation (NAT). Free addresses to use are: 10.0.0.0 - anything starting with a 10 172.16.0.0 to 172.31.0.0 - inclusive 192.168.0.0 - any address starting with these two numbers Using VLSM Say you are using the following number: 192.168.1.0 which if you have read the subnetting section you know lets you use 254 hosts on your network. If you only have 20 hosts on your network it means you have wasted 204 addresses. Now imagine if you are paying for each block of addresses, you are going to waste a huge amount of money as well. VLSM lets you cut your network into smaller chunks which are called subnets. All you have to do it add some numbers to the end of your subnet mask and your network will see that you are subnetting it down. Please see the easy way to subnet section for more information on how to actually do it. How VLSM Works

20

If you change your subnet mask from 192.168.1.0 255.255.255.0 to 255.255.255.224 your network device will see the change and let you break down your network into smaller parts. That actual number tells the network to chunk your network down into subnet blocks of 32. If you use the subnetting cheat chart you will see how this actually works. The subnet mask 255.255.255.224 gives you 8 subnets with 32 available addresses. Each subnet must start with a subnet number and end with a broadcast number so technically that leaves you with 30 host addresses per subnet. This is still plenty if you only needed 20 per subnet. We have gone from one subnet with 255 addresses:

To 8 subnets with 32 IP addresses per subnet.

21

Click here to enlarge A RFC (request for comment) was submitted which suggested that we could allocate numbers to hosts on networks instead of hostnames. The current implementation of this scheme is IP version 4 although IPv6 is now replacing this. The idea is that every address would be made up from four groups of eight binary numbers. Each group of eight binary numbers is known as an octet. Because we struggle to write numbers out in binary we usually convert them into decimal but computers and network devices still see all numbers in binary because they can only recognise on and off signals so either a 0 or a 1. If you want to see how to apply this to a network then please read the easy way to subnet. There is a lot more in Subnetting Secrets. More than we could fit on one web site in face.

IP Addressing and Subnetting for New Users


Document ID: 13788
Downloads IP Addressing and Subnetting for New Users

Contents
Introduction Prerequisites Requirements 22

Components Used Additional Information Conventions Understanding IP Addresses Network Masks Understanding Subnetting Examples Sample Exercise 1 Sample Exercise 2 VLSM Example VLSM Example CIDR Appendix Sample Config Host/Subnet Quantities Table Cisco Support Community - Featured Conversations Related Information

Introduction
This document gives you basic information needed to configure your router for routing IP, such as how addresses are broken down and how subnetting works. You learn how to assign each interface on the router an IP address with a unique subnet. There are many examples to help tie everything together.

Prerequisites
Requirements
There are no specific prerequisites for this document.

Components Used
This document is not restricted to specific software and hardware versions.

Additional Information
If definitions are helpful to you, use these vocabulary terms to get you started:
y y

AddressThe unique number ID assigned to one host or interface in a network. SubnetA portion of a network sharing a particular subnet address.
23

y y

Subnet maskA 32-bit combination used to describe which portion of an address refers to the subnet and which part refers to the host. InterfaceA network connection.

If you have already received your legitimate address(es) from the Internet Network Information Center (InterNIC), you are ready to begin. If you do not plan to connect to the Internet, Cisco strongly suggests that you use reserved addresses from RFC 1918 .

Conventions
Refer to Cisco Technical Tips Conventions for more information on document conventions.

Understanding IP Addresses
An IP address is an address used to uniquely identify a device on an IP network. The address is made up of 32 binary bits which can be divisible into a network portion and host portion with the help of a subnet mask. The 32 binary bits are broken into four octets (1 octet = 8 bits). Each octet is converted to decimal and separated by a period (dot). For this reason, an IP address is said to be expressed in dotted decimal format (for example, 172.16.81.100). The value in each octet ranges from 0 to 255 decimal, or 00000000 - 11111111 binary. Here is how binary octets convert to decimal: The right most bit, or least significant bit, of an octet holds a value of 20. The bit just to the left of that holds a value of 21. This continues until the left-most bit, or most significant bit, which holds a value of 27. So if all binary bits are a one, the decimal equivalent would be 255 as shown here:

1 1 1 1 1 1 1 1 128 64 32 16 8 4 2 1 (128+64+32+16+8+4+2+1=255)
Here is a sample octet conversion when not all of the bits are set to 1.

0 1 0 0 0 0 0 1 0 64 0 0 0 0 0 1 (0+64+0+0+0+0+0+1=65)
And this is sample shows an IP address represented in both binary and decimal.

10. 1. 23. 19 (decimal) 00001010.00000001.00010111.00010011 (binary)


These octets are broken down to provide an addressing scheme that can accommodate large and small networks. There are five different classes of networks, A to E. This document focuses on addressing classes A to C, since classes D and E are reserved and discussion of them is beyond the scope of this document.

24

Note: Also note that the terms "Class A, Class B" and so on are used in this document to help facilitate the understanding of IP addressing and subnetting. These terms are rarely used in the industry anymore because of the introduction of classless interdomain routing (CIDR). Given an IP address, its class can be determined from the three high-order bits. Figure 1 shows the significance in the three high order bits and the range of addresses that fall into each class. For informational purposes, Class D and Class E addresses are also shown.
Figure 1

In a Class A address, the first octet is the network portion, so the Class A example in Figure 1 has a major network address of 1.0.0.0 - 127.255.255.255. Octets 2, 3, and 4 (the next 24 bits) are for the network manager to divide into subnets and hosts as he/she sees fit. Class A addresses are used for networks that have more than 65,536 hosts (actually, up to 16777214 hosts!). In a Class B address, the first two octets are the network portion, so the Class B example in Figure 1 has a major network address of 128.0.0.0 - 191.255.255.255. Octets 3 and 4 (16 bits) are for local subnets and hosts. Class B addresses are used for networks that have between 256 and 65534 hosts. In a Class C address, the first three octets are the network portion. The Class C example in Figure 1 has a major network address of 192.0.0.0 - 233.255.255.255. Octet 4 (8 bits) is for local
25

subnets and hosts - perfect for networks with less than 254 hosts.

Network Masks
A network mask helps you know which portion of the address identifies the network and which portion of the address identifies the node. Class A, B, and C networks have default masks, also known as natural masks, as shown here:

Class A: 255.0.0.0 Class B: 255.255.0.0 Class C: 255.255.255.0


An IP address on a Class A network that has not been subnetted would have an address/mask pair similar to: 8.20.15.1 255.0.0.0. To see how the mask helps you identify the network and node parts of the address, convert the address and mask to binary numbers.

8.20.15.1 = 00001000.00010100.00001111.00000001 255.0.0.0 = 11111111.00000000.00000000.00000000


Once you have the address and the mask represented in binary, then identifying the network and host ID is easier. Any address bits which have corresponding mask bits set to 1 represent the network ID. Any address bits that have corresponding mask bits set to 0 represent the node ID.

8.20.15.1 = 00001000.00010100.00001111.00000001 255.0.0.0 = 11111111.00000000.00000000.00000000 ----------------------------------net id | host id netid = 00001000 = 8 hostid = 00010100.00001111.00000001 = 20.15.1

Understanding Subnetting
Subnetting allows you to create multiple logical networks that exist within a single Class A, B, or C network. If you do not subnet, you are only able to use one network from your Class A, B, or C network, which is unrealistic. Each data link on a network must have a unique network ID, with every node on that link being a member of the same network. If you break a major network (Class A, B, or C) into smaller subnetworks, it allows you to create a network of interconnecting subnetworks. Each data link on this network would then have a unique network/subnetwork ID. Any device, or gateway, connecting n networks/subnetworks has n distinct IP addresses, one for each network /
26

subnetwork that it interconnects. In order to subnet a network, extend the natural mask using some of the bits from the host ID portion of the address to create a subnetwork ID. For example, given a Class C network of 204.17.5.0 which has a natural mask of 255.255.255.0, you can create subnets in this manner:

204.17.5.0 11001100.00010001.00000101.00000000 255.255.255.224 11111111.11111111.11111111.11100000 --------------------------|sub|--By extending the mask to be 255.255.255.224, you have taken three bits (indicated by "sub") from the original host portion of the address and used them to make subnets. With these three bits, it is possible to create eight subnets. With the remaining five host ID bits, each subnet can have up to 32 host addresses, 30 of which can actually be assigned to a device since host ids of all zeros or all ones are not allowed (it is very important to remember this). So, with this in mind, these subnets have been created.

204.17.5.0 255.255.255.224 to 30 204.17.5.32 255.255.255.224 33 to 62 204.17.5.64 255.255.255.224 65 to 94 204.17.5.96 255.255.255.224 97 to 126 204.17.5.128 255.255.255.224 129 to 158 204.17.5.160 255.255.255.224 161 to 190 204.17.5.192 255.255.255.224 193 to 222 204.17.5.224 255.255.255.224 225 to 254

host address range 1 host address range host address range host address range host address range host address range host address range host address range

Note: There are two ways to denote these masks. First, since you are using three bits more than the "natural" Class C mask, you can denote these addresses as having a 3-bit subnet mask. Or, secondly, the mask of 255.255.255.224 can also be denoted as /27 as there are 27 bits that are set in the mask. This second method is used with CIDR. Using this method, one of these networks
27

can be described with the notation prefix/length. For example, 204.17.5.32/27 denotes the network 204.17.5.32 255.255.255.224. When appropriate the prefix/length notation is used to denote the mask throughout the rest of this document. The network subnetting scheme in this section allows for eight subnets, and the network might appear as:
Figure 2

Notice that each of the routers in Figure 2 is attached to four subnetworks, one subnetwork is common to both routers. Also, each router has an IP address for each subnetwork to which it is attached. Each subnetwork could potentially support up to 30 host addresses. This brings up an interesting point. The more host bits you use for a subnet mask, the more subnets you have available. However, the more subnets available, the less host addresses available per subnet. For example, a Class C network of 204.17.5.0 and a mask of 255.255.255.224 (/27) allows you to have eight subnets, each with 32 host addresses (30 of which could be assigned to devices). If you use a mask of 255.255.255.240 (/28), the break down is:

204.17.5.0 11001100.00010001.00000101.00000000 255.255.255.240 11111111.11111111.11111111.11110000 --------------------------|sub |-Since you now have four bits to make subnets with, you only have four bits left for host addresses. So in this case you can have up to 16 subnets, each of which can have up to 16 host addresses (14 of which can be assigned to devices). Take a look at how a Class B network might be subnetted. If you have network 172.16.0.0 ,then you know that its natural mask is 255.255.0.0 or 172.16.0.0/16. Extending the mask to anything
28

beyond 255.255.0.0 means you are subnetting. You can quickly see that you have the ability to create a lot more subnets than with the Class C network. If you use a mask of 255.255.248.0 (/21), how many subnets and hosts per subnet does this allow for?

172.16.0.0 10101100.00010000.00000000.00000000 255.255.248.0 - 11111111.11111111.11111000.00000000 -----------------| sub |----------You are using five bits from the original host bits for subnets. This allows you to have 32 subnets (25). After using the five bits for subnetting, you are left with 11 bits for host addresses. This allows each subnet so have 2048 host addresses (211), 2046 of which could be assigned to devices. Note: In the past, there were limitations to the use of a subnet 0 (all subnet bits are set to zero) and all ones subnet (all subnet bits set to one). Some devices would not allow the use of these subnets. Cisco Systems devices allow the use of these subnets when theip subnet zero command is configured.

Examples
Sample Exercise 1
Now that you have an understanding of subnetting, put this knowledge to use. In this example, you are given two address / mask combinations, written with the prefix/length notation, which have been assigned to two devices. Your task is to determine if these devices are on the same subnet or different subnets. You can do this by using the address and mask of each device to determine to which subnet each address belongs.

DeviceA: 172.16.17.30/20 DeviceB: 172.16.28.15/20


Determining the Subnet for DeviceA:

172.16.17.30 10101100.00010000.00010001.00011110 255.255.240.0 11111111.11111111.11110000.00000000 -----------------| sub|----------subnet = 10101100.00010000.00010000.00000000 = 172.16.16.0

29

Looking at the address bits that have a corresponding mask bit set to one, and setting all the other address bits to zero (this is equivalent to performing a logical "AND" between the mask and address), shows you to which subnet this address belongs. In this case, DeviceA belongs to subnet 172.16.16.0. Determining the Subnet for DeviceB:

172.16.28.15 10101100.00010000.00011100.00001111 255.255.240.0 11111111.11111111.11110000.00000000 -----------------| sub|----------subnet = 10101100.00010000.00010000.00000000 = 172.16.16.0


From these determinations, DeviceA and DeviceB have addresses that are part of the same subnet.

Sample Exercise 2
Given the Class C network of 204.15.5.0/24, subnet the network in order to create the network in Figure 3 with the host requirements shown.
Figure 3

Looking at the network shown in Figure 3, you can see that you are required to create five subnets. The largest subnet must support 28 host addresses. Is this possible with a Class C network? and if so, then how? You can start by looking at the subnet requirement. In order to create the five needed subnets you would need to use three bits from the Class C host bits. Two bits would only allow you four subnets (22).

30

Since you need three subnet bits, that leaves you with five bits for the host portion of the address. How many hosts does this support? 25 = 32 (30 usable). This meets the requirement. Therefore you have determined that it is possible to create this network with a Class C network. An example of how you might assign the subnetworks is:

netA: netB: 62 netC: 94 netD: 126 netE: 158

204.15.5.0/27 204.15.5.32/27 204.15.5.64/27 204.15.5.96/27 204.15.5.128/27

host address range 1 to 30 host address range 33 to host address range 65 to host address range 97 to host address range 129 to

VLSM Example
In all of the previous examples of subnetting, notice that the same subnet mask was applied for all the subnets. This means that each subnet has the same number of available host addresses. You can need this in some cases, but, in most cases, having the same subnet mask for all subnets ends up wasting address space. For example, in the Sample Exercise 2 section, a class C network was split into eight equal-size subnets; however, each subnet did not utilize all available host addresses, which results in wasted address space. Figure 4 illustrates this wasted address space.
Figure 4

31

Figure 4 illustrates that of the subnets that are being used, NetA, NetC, and NetD have a lot of unused host address space. It is possible that this was a deliberate design accounting for future growth, but in many cases this is just wasted address space due to the fact that the same subnet mask is being used for all the subnets. Variable Length Subnet Masks (VLSM) allows you to use different masks for each subnet, thereby using address space efficiently.

VLSM Example
Given the same network and requirements as in Sample Exercise 2 develop a subnetting scheme with the use of VLSM, given:

netA: must support 14 hosts netB: must support 28 hosts netC: must support 2 hosts
32

netD: must support 7 hosts netE: must support 28 host


Determine what mask allows the required number of hosts.

netA: requires a /28 (255.255.255.240) mask to support 14 hosts netB: requires a /27 (255.255.255.224) mask to support 28 hosts netC: requires a /30 (255.255.255.252) mask to support 2 hosts netD*: requires a /28 (255.255.255.240) mask to support 7 hosts netE: requires a /27 (255.255.255.224) mask to support 28 hosts * a /29 (255.255.255.248) would only allow 6 usable host addresses therefore netD requires a /28 mask.
The easiest way to assign the subnets is to assign the largest first. For example, you can assign in this manner:

netB: netE: netA: netD: netC:

204.15.5.0/27 204.15.5.32/27 204.15.5.64/28 204.15.5.80/28 204.15.5.96/30

host host host host host

address address address address address

range range range range range

1 to 30 33 to 62 65 to 78 81 to 94 97 to 98

This can be graphically represented as shown in Figure 5:


Figure 5

33

Figure 5 illustrates how using VLSM helped save more than half of the address space.

CIDR
Classless Interdomain Routing (CIDR) was introduced to improve both address space utilization and routing scalability in the Internet. It was needed because of the rapid growth of the Internet and growth of the IP routing tables held in the Internet routers. CIDR moves way from the traditional IP classes (Class A, Class B, Class C, and so on). In CIDR , an IP network is represented by a prefix, which is an IP address and some indication of the length of the mask. Length means the number of left-most contiguous mask bits that are set to one. So network 172.16.0.0 255.255.0.0 can be represented as 172.16.0.0/16. CIDR also depicts a more hierarchical Internet architecture, where each domain takes its IP addresses from a higher level. This allows for the summarization of the domains to be done at the higher level. For example, if an ISP owns network 172.16.0.0/16, then the ISP can offer 172.16.1.0/24, 172.16.2.0/24, and so on to customers. Yet, when advertising to other providers, the ISP only needs to advertise 172.16.0.0/16. For more information on CIDR, see RFC 1518 and RFC 1519 .

34

Appendix
Sample Config
Routers A and B are connected via serial interface. Router A

hostname routera ! ip routing ! int e 0 ip address 172.16.50.1 255.255.255.0 !(subnet 50) int e 1 ip address 172.16.55.1 255.255.255.0 !(subnet 55) int t 0 ip address 172.16.60.1 255.255.255.0 !(subnet 60) int s 0 ip address 172.16.65.1 255.255.255.0 (subnet 65) !S 0 connects to router B router rip network 172.16.0.0
Router B

hostname routerb ! ip routing ! int e 0 ip address 192.1.10.200 255.255.255.240 !(subnet 192) int e 1 ip address 192.1.10.66 255.255.255.240 !(subnet 64) int s 0 ip address 172.16.65.2 (same subnet as router A's s 0)
35

!Int s 0 connects to router A router rip network 192.1.10.0 network 172.16.0.0


Host/Subnet Quantities Table

Class B # bits ------1 2 3 4 5 6 7 8 9 10 11 12 13 14 Class C # bits ------1 2 3 4 5 6

Mask --------------255.255.128.0 255.255.192.0 255.255.224.0 255.255.240.0 255.255.248.0 255.255.252.0 255.255.254.0 255.255.255.0 255.255.255.128 255.255.255.192 255.255.255.224 255.255.255.240 255.255.255.248 255.255.255.252

Effective Subnets --------2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 Effective Subnets --------2 4 8 16 32 64

Effective Hosts --------32766 16382 8190 4094 2046 1022 510 254 126 62 30 14 6 2 Effective Hosts --------126 62 30 14 6 2

Mask --------------255.255.255.128 255.255.255.192 255.255.255.224 255.255.255.240 255.255.255.248 255.255.255.252

*Subnet all zeroes and all ones included. These might not be supported on some legacy systems.
36

*Host all zeroes and all ones excluded.

37

You might also like