You are on page 1of 40

IPv4

Addressing and Subnetting

What is an IP address?
An IP address is a 32 bit number So . 32 1s and 0s 10100110100110000101110100100111 This is what the computer sees but it is not so nice for people.

Making it Easier for People


The 32 bits are divided up into 4 groups of 8 bits each. The groups are separated by periods dots becoming.. 10100110.10011000.01011101.00100111 And then each group of 8 bits is converted to decimal.

Converting from Binary to Decimal


Each group of 8 bits is called an octet and it is converted from binary to decimal using the binary place value. ___ ___ ___ ___ ___ ___ ___ ___ 128 64 32 16 8 4 2 1
(This is BASE 2 Binary)

Examples binary to decimal


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

1 x 128 + 0 x 64 + 1 x 32 + 0 x 16 + 0 x 8 + 1 x 4 + 1 x 2 + 0 x 1 = 166

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

1 x 128 + 0 x 64 + 0 x 32 + 1 x 16 + 1 x 8 + 0 x 4 + 0 x 2 + 0 x 1 = 152

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

0 x 128 + 1 x 64 + 0 x 32 + 1 x 16 + 1 x 8 + 1 x 4 + 0 x 2 + 1 x 1 = 93

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

0 x 128 + 0 x 64 + 1 x 32 + 0 x 16 + 0 x 8 + 1 x 4 + 1 x 2 + 1 x 1 = 39

The Decimal version


Using the previous conversions, our binary ip address becomes: 166.152.93.39 An easier number for us, but remember that the ip address really is a BINARY number.

The Two Parts to an IP address


IP addresses have TWO parts: network and host. Which part is network and which is host? 10100110.10011000.01011101.00100111 network host Left Part is network and Right Part is host!

Soooo Two questions arise:


If you wanted 10 subnets. With 25 hosts on each.

Where do we separate left and right for network and host?


(ans: wherever we wantwith some conditions)

How do we actually separate network from host?


Entirely controlled by the subnet mask.

The Conditions class A, B, C


IPv4 addresses are divided into classes. We need to understand three classes of ip addresses Class A Class B Class C

We will look at the first octet of the IP address.

Class A Really Big Networks


First octet has 0 in left bit:

0
128 64 32 16 8 4 2 1

The smallest first octet value has all 0s in the rest of the bits producing 0 in the first octet. The largest first octet value has all 1s in the rest of the bits producing 127 in the first octet. 0 and 127 are reserved values, so all CLASS A ip addresses have 1 126 in the first octet.
127.0.0.1 is the Loopback Address. The computer version of myself. Im Gerry. Refer to myself as Me. 127.0.0.1 is Me

Class A continued
Class A was intended for very large networks, so only the first octet is fixed for a particular network ID. The owner could use whatever values they wanted in the other 3 octets. This was determined by the default subnet mask of 255.0.0.0The 24 bits in the last 3 octets produce nearly 17,000,000 ip addresses in each class A.

Class B medium sized nets


First octet has 1 0 in left 2 bits:

1 0
128 64 32 16 8 4 2 1

The smallest first octet value has all 0s in the rest of the bits producing 128 in the first octet. The largest first octet value has all 1s in the rest of the bits producing 191 in the first octet. So all Class B ip addresses have 128 191 in the first octet.

Class B continued
Class B was intended for medium sized networks, so the first two octets are fixed for a particular network. The owner could use whatever values they wanted in the other 2 octets. This was determined by the default subnet mask of 255.255.0.0 The 16 bits in the last 2 octets produce a little over 65,000 ip addresses in each class B.

Class C small networks


First octet has 1 1 0 in left 3 bits:

1 1 0
128 64 32 16 8 4 2 1

The smallest first octet value would have all 0s in the rest of the bits producing 192 in the first octet. The largest first octet value would have all 1s in the rest of the bits producing 223 in the first octet. So all Class C ip addresses have 192 223 in the first octet.

Class C continued
Class C was intended for small networks, so the first three octets are fixed. The owner could use whatever values they wanted in the 4th octet. This was determined by the default subnet mask of 255.255.255.0 The 8 bits in the last octet produce 254 ip addresses in each class B.
2 to the power of 8 = 256. So no all zeros or all ones. So to numbers taken for a of MAX 254 hosts.

Class A,B,C considerations


It is important to understand what class IP address you are working with. Class A you can subnet within the last 3 octets. Class B you can subnet within the last 2 octets. Class C you can subnet within the last octet.

Subnetting
By default, a class A network is one network with nearly 17,000,000 hosts not too practical! A class B network by default would have one network with over 65,000 hosts still not very practical. Class C networks can have up to 254 hosts more reasonable, but we may still want to divide it up into more networks.

The Subnet Mask Dividing the Network part and the Host part
The subnet mask is another 32 bit number. It has 1s in the network part and 0s in the host part. The subnet mask is ANDed with the ip address to calculate the Network ID. 1 AND 1 = 1 1 AND 0 = 0 AND 1 = 0 0 AND 0 = 0

Consider the original ip address in binary: 10100110.10011000.01011101.00100111 From the 10 in the first two bits, we know this is a class B address. The default subnet mask is 255.255.0.0 or in binary: 11111111.11111111.00000000.00000000 ANDing the two numbers: 10100110.10011000.01011101.00100111 11111111.11111111.00000000.00000000 Gives (just do two bits at a time): 10100110.10011000.00000000.00000000 Or: 166.152.0.0 the first two octets are unchanged and the host part becomes 0. This is the network ID.
The ip address ANDed Subnet Mask = Network ID

Or
In decimal, any octet of the IP address with 255 in the same octet of the subnet mask, comes through unchanged in the network ID Any octet of the IP address with 0 in the subnet mask becomes 0 in the network ID.

Subnetting
Subnetting is the process of using some of the host bits in a particular network ID to create additional subnets. It is accomplished by appending 1s to the subnet mask making the mask longer. This allows us to have more networks each with fewer hosts.

Simple Subnet Example


Suppose 166.152.0.0 were combined with the subnet mask of 255.255.255.0 Now the 3rd octet becomes part of the network ID. Only the 4th octet is the host ID. The 8 bits of the 3rd octet would produce 28 = 256 different network IDs. Now we have 256 subnets each with 28 2 = 254 hosts.

Why 254 hosts?


Every network has 2 special values in the host portion of the IP address. All 0s in the host part is used for the network ID. This cannot be used to address a network device. All 1s in the host part is the directed broadcast for that subnet. This address also cannot be used for a network device. Consequently, we calculate the number of hosts by using 2n 2, where n is the number of bits in the host portion of the address.

What part of the address can be used for subnetting?


Class A first octet is fixed we cannot change this value or we trespass on some elses address. We can use the last 3 octets for subnetting. Class B first 2 octets are fixed. We can use the last 2 octets for subnetting. Class C first 3 octets are fixed. We can use the last octet for subnetting.

Class B example
Suppose we use 5 bits of the host portion for subnets (leaving 11 host bits):
Fixed

X.Y. _ _ _ _ _ _ _ _ . _ _ _ _ _ _ _ _
248 Subnets 2 to power of 11 (# of hosts on each on of 248 subnets 2 for Network ID and Broadcast ID)

Subnet Part

Host Part

Putting 1s under the network part gives a subnet mask of:


255.255.11111000.00000000 = 255.255.248.0

Continued
The 5 subnet bits give us 25 = 32 different subnets. (It used to be necessary to subtract 2 from the number of subnets. This is no longer required, but you may run into presentations or people who still do this.) 11 host bits will give 211 2 = 2046 hosts

Lets apply this 255.255.248.0 subnet mask to our original ip address: 166.152.93.39 The result in the first, second and fourth octets is obvious: 166.152.???.0, so lets focus on the third octet and write both the ip address and subnet mask in binary: 0 1 0 1 1 1 0 1 (3rd octet of ip address) 1 1 1 1 1 0 0 0 (3rd octet of subnet mask) = 0 1 0 1 1 0 0 0 = 88 So the network ID = 166.152.88.0
AND AND AND AND AND AND AND AND

Finding network IDs


Fixed
128

X.Y. _ _ _ _ _ _ _ _ . _ _ _ _ _ _ _ _
64 32 16 8 4 2 1

Subnet Part

Host Part

Focusing on the subnet part, lets look at the possible values by counting up in binary. 00000000 0 Notice that the network values are increasing 00001000 8 by 8. It is very useful 0 0 0 1 0 0 0 0 16 to have a quicker way to find this magic 0 0 0 1 1 0 0 0 24 value. and so on

Finding the Magic Number


Fixed

X.Y. _ _ _ _ _ _ _ _ . _ _ _ _ _ _ _ _
128 64 32 16 8 4 2 1

Subnet Part

Host Part

Two ways to find this value: Within the interesting octet there are 3 bits in the host portion. 23 = 8 gives the value. The place value of the rightmost bit in the subnet portion is 8. This is the value.

Example 1
Use 3 bits for subnets in the class B network Subnet X.Y. _ _ _ _ _ _ _ _ . _ _ _ _ _ _ _ _
128 64 32 16 8 4 2 1

The rightmost bit in the subnet part is 32. 5 bits on the host side in 3rd octet, 25=32 Network IDs in the 3rd octet are: 0, 32, 64, 96, 128, 160, 192, 224 8 nets Subnet mask is 255.255.224.0 do you see why? 255.255.11100000.0 255.255.224.0

Example 2
Use 10 bits for subnets in Subnet _ X.Y. _ _ _ _ _Part_ _ . _ _ _ _ _ _ _ _
128 64 32 16 8 4 2 1

The rightmost bit in the subnet part is 64 6 bits in the host part 26 = 64, therefore net IDs: X.Y.0.0, X.Y.0.64, X.Y.0.128, X.Y.0.192 X.Y.1.0, X.Y.1.64, X.Y.1.128, X.Y.1.192, etc. etc. The 3rd octet will keep incrementing until all 1024 subnets are generated. Subnet mask is: 255.255.255.192

What about Host IDs?


Lets look at the 6th subnet from Example 2: X.Y.1.64 =X.Y.0 0 0 0 0 0 0 1.0 1 0 0 0 0 0 0
128 64 32 16 8 4 2 1

Remembering that all 0s and all 1s can not be used in the host part, the host ids range from: X.Y.1.0 1 0 0 0 0 0 1 to X.Y.1.0 1 1 1 1 1 1 0 OR: X.Y.1.65 to X.Y.1.126

Host IDs Quickly


In the previous example, we found the host ids for X.Y.1.64. Lets look at how the host ids fit between X.Y.1.64 and the next network id of X.Y.1.128 Net ID: X.Y.1.64 Host IDs: X.Y.1.65 X.Y.1.126 next Net ID: X.Y.1.128 First host ID: One more than the net ID Last host ID: Two less than the next net ID

Putting it all together


Given the class B address 172.16.0.0, subnet it to provide 10 subnets. a) How many subnets will you have? b) How many hosts on each subnet? c) Find the network ID of the 5th subnet. d) Find the subnet mask. e) Find the first and last usable host ip address in the 5th subnet. f) What is the broadcast address for the 5th subnet?

Solution How many bits are needed? 4 bits will provide 16 subnets, more than needed but 3 bits would only provide 8 not enough. 4 bits in the subnet part results in 255.255.11110000.0 = 255.255.240.0 for the subnet mask. There are 24 = 16 subnets There are 212 -2 = 4096 2 = 4094 hosts on each The magic number is 16, so the 3rd octet of the network IDs increase by 16 giving: 0, 16, 32, 48, 64, 80, 96, 112, . . . So the 5th subnet would be 172.16.64.0

Solution continued The host addresses lie between 172.16.64.0 and 172.16.80.0, giving the range of: 172.16.64.1 172.16.79.254 (1 more than 172.16.64.0 and 2 less than 172.16.80.0) And the broadcast address is 172.16.79.255

CIDR notation
Each of the network IDs that appeared in the previous slides were not really complete without the subnet mask. A short way to write the ip address together with the subnet mask is: 172.16.64.0/20 where the /20 refers to the number of bits in the entire network part or the number of 1s in the subnet mask.

Another Example
Subnet the class C address 192.168.1.0 to provide 25 hosts on each subnet. a) How many subnets will you have? b) How many hosts on each subnet? c) Find the network ID of the 5th subnet. d) Find the subnet mask. e) Find the first and last usable host ip address in the 5th subnet. f) What is the broadcast address for the 5th subnet?

Solution Even though this question specifies the number of hosts, the approach is the same. How many bits? 5 bits will give 25 = 32, more than we need but 4 is not enough. Since we specified HOSTS, the 5 bits must be in the host part, leaving 3 bits in the network part. The subnet mask is 255.255.255.11100000 = 255.255.255.224

Solution continued 3 bits in subnet part gives 23 = 8 subnets. 5 bits in host part gives 25 2 = 30 hosts. The magic number is 32. The 4th octet of the network IDs are: 0, 32, 64, 96, 128, 160, 192, 224, so the 5th network ID is 192.168.1.128/28 The usable host addresses in the 5th octet are 192.168.1.129 192.168.1.158 The broadcast address is 192.168.1.159

You might also like