Search this blog

Tuesday, January 12, 2010

Day 20: IP Addressing and Subnetting

An IP address is typically assigned to the NIC, routers need an IP address for each interface.

An IPv4 address is made up of 32 binary bits, divided in four octects and represented in decimal format. I'm not going to cover converting to decimal or binary! Only remember that the maximum decimal equivalent for an octet is 255, the minimum is obviously 0.

The RPC 2460 proposed IPv6 in 1998 to increase address space. For now it's enough to know that they're 128-bit addresses respresented as 32 hexadecimal digits, broken into 8 groups of 4 digits separated by colons.

An IP address contains a network portion and host portion. The first part is the network portion and the second is the host portion. The network portion is determined with the subnet mask, a 32-bit address in which the binary 1s identify the network portion. For example: (or /27) - the last octet is 11100000

We also focus on the network address which has all 0s in the host portion and the broadcast address which has all 1s in the host portion. An example:
network address -
subnet mask -
first available host address -
broadcast address -
As you can see you always lose two host IP addresses from the possible combinations.

You probably know all the classes but I'll give a quick overview:
  • Class A, binary start is 0, first octet range 1-126, subnet mask is, 16777214 hosts, 8 bits network address
  • Class B, binary start is 10, first octet range 128-191, subnet mask is, 65534 hosts, 16 bits network address
  • Class C, binary start is 110, first octet range 192-223, subnet mask is, 254 hosts, 24 bits network address
  • Class D, binary start is 1110, first octet range 224-239, multicast
  • Class E, binary start is 1111, first octet range 240-255, used for research
The complete 127 range is used for loopback testing (TCPIP stack), you probably know the loopback address but it actually works with all hosts in this range (

The RFC 1918 identifies the networks reserved for internal or private use:
  • Class A: to
  • Class B: to
  • Class C: to
I've mentioned multicast, this is used by devices that send multicasts to the hosts that are part of the multicast group. Might be used for videoconferencing or remote gaming.
Devices use broadcast addresses to communicate with all hosts on a network (ARP, DHCP). Directed broadcasts are forwarded to remote networks (normally all 1's are not forwarded).
Devices use unicast to communicate with another device, one-to-one.

When we divide a network beyond its default class, and use bits from the host portion as network bits; the router looks at the new mask and determines the network address regardless of the default class. This is called Classless Interdomain Routing (CIDR).

I'm not going to cover subnetting as there are a zillion good places to find more information, CBTNuggets explains it well, Todd Lammle, the Cisco Learning Discussions...

A great site to practice is
Updated with this great link as well:

I'll review "my way" with the current question: "What is the first valid host on the subnetwork that the node belongs to?"
  • is class A
  • /20 is, so third octet is important!
  • 4 network bits in the relevant octet, 12 subnet bits in total so 2^12 is 4096, so 4096 possible subnets. The formula is 2 to the n-th power where n is the number of network bits.
  • 4 host bits in the relevant octet so 2^4 is 16 (this is my block size or increment size). If we want the number of hosts it's 12 host bits (including last octet), so 2^12 minus 2 because we need to subtract 2 (network and broadcast address) so 4094 possible hosts
  • my block size is 16 so multiplications of 16 (0-16-32-48-64-80-96-112-etc), third octet is important and the closest to 251 is obviously 240
  • the network address is then, first possible address is and broadcast is
Please note that I know the multiplications of 8 and 16 by heart, this makes it all a lot easier. However, I admit that my method is not the easiest :)
Contact me if you have questions.

No comments:

Post a Comment