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:
255.255.255.224 (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 - 172.16.1.0
subnet mask - 255.255.255.0
first available host address - 172.16.1.1
broadcast address - 172.16.1.255
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 255.0.0.0, 16777214 hosts, 8 bits network address
- Class B, binary start is 10, first octet range 128-191, subnet mask is 255.255.0.0, 65534 hosts, 16 bits network address
- Class C, binary start is 110, first octet range 192-223, subnet mask is 255.255.255.0, 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 RFC 1918 identifies the networks reserved for internal or private use:
- Class A: 10.0.0.0 to 10.255.255.255
- Class B: 172.16.0.0 to 172.31.255.255
- Class C: 192.168.0.0 to 192.168.255.255
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 http://www.subnettingquestions.com/
Updated with this great link as well: http://faculty.valleycollege.net/rpowell/jscript/subnet2.htm
I'll review "my way" with the current question: "What is the first valid host on the subnetwork that the node 10.201.251.121/20 belongs to?"
- 10.201.251.121 is class A
- /20 is 255.255.240.0, 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 10.201.240.0, first possible address is 10.201.240.1 and broadcast is 10.201.255.255
Contact me if you have questions.