Well the sheet gave a lot of stuff about broadcasting address and binary math and classed A and B IPs (???) and subnetting (I know this is done to manage networks) and public and private. It was very much stuff
Sounds like a terrible teacher. I could understand using classes as an introduction (they're deprecated, but are easier to understand), but he was going to explain subnetting he might as well do it correctly.
And no, Till, wikipedia doesn't really try to explain this carefully. I guess that it probably merits at attempt at explaining it here:
The basics:
You just have to know that those user-friendly 1-255 numbers you see in the four parts of an IP address are really representations of a binary number. Each of the four numbers represents an "octet", a sequence of 8 bits.
2x2x ..., or 2^8, gives 256 combination, thus represented as 0...255. For ease of writing these 8 zeros and ones are represented as this single number. An IP adreess has four of these octets.
There are several "kinds" of IP addresses:
- a single host address, for example 192.168.57.25
- a network address, for example 192.168.0.0/16
- a broadcast address, for example, 192.168.255.255
- etc (the ones above cover the basics).
The way you convert a network address to binary is to take each of the four numbers and use some calculator to covert it, one octet at a time (I just can't be bothered to do it on my head):
So 192.168.57.25 is 11000000.10101000.00111001.00011001
and 192.168.0.0/16 is 11000000.10101000.00000000.00000000
and 192.168.255.255 is 11000000.10101000.11111111.11111111
As you can see a network address is just like a host address, except that the last bits are all zero. The network bits are the number of bits given in the "/x" notation, in this case 16. The first 16 bits. The rest of the bits are set as zero.
And the broadcast address is just the same bits as the network bits, but with the rest all as ones instead of zeroes.
Some obnoxious bastards insist in representing a network address not as 192.168.0.0/16 but as:
192.168.0.0 netmask 255.255.0.0
in other words, a "netmask" is just the network address with all its network bits set to one. This is easy to calculate when subnets match an octet border (/8, /16, /24), but the broadcast address (and the broadcast too) becomes a PITA to calculate when they don't.
Subnetting:
Now, it's hard to explain this rationally without explaining how routing protocols work. I could just say "it's like this", but you wouldn't understand why the "bits" are important. So:
The IP address is, well, the address for each packet of information. When a packet reaches one of the (possibly) many routers on its way, the router compares the destination address (typically, a host address) on the packet with the network addresses of its own networks. It does so by matching the initial bits of the address to the bits of each network, up to the number of bits of the network given in the "/x" in the end of the network address.
Consider a router which did had the 192.168.0.0/16 network and received a packed meant for host 192.168.57.25. Because it's a router, it also has a few other networks.
Suppose it will be comparing, in binary:
host - 11000000.10101000.00111001.00011001
network1 - 11000000.10100000.00000000.00000000 (/12)
network2 - 11000000.10101000.00000000.00000000 (/16)
network3 - 11000000.10101000.11100000.00000000 (/24)
Without getting into routing, because it's not necessary, I'll just add that routers will route packets into the most specific network, i.e., that which matches
the most bits of the destination address with the "/x" bits of the network address, and only those bits. So, dumping the padding zeroes, we have:
host - 11000000.10101000.00111001.00011001
network1 - 11000000.1010 (/12)
network2 - 11000000.10101000 (/16)
network3 - 11000011.10101000.11100000 (/24)
So for the example above the router will compare the first 12 bits of the host address with network1, and the first 16 with network2, and the first 24 with network3.
The first and the second comparison match, so this "tie" will be broken in favor of the most specific: network2.
Now, why do both network match? What does that mean? Well, it means that network2, in the example above, is logically a subnet of network1. You wouldn't know from looking at its representation in decimal:
network1 - 192.160.0.0 (/12)
network2 - 192.168.0.0 (/16)
but in binary you can see it:
network1 - 11000000.10100000.00000000.00000000 (/12)
network2 - 11000000.10101000.00000000.00000000 (/16)
(and yes, it is valid for two networks to be connected to the same router even when one is a subnet of the other. The rules make sure that there's no ambiguity in the routing of traffic)
The size of a network address, as you can see, can be chosen arbitrarily. It was not always so: initially there were only supposed to be networks with three sizes: /8, /16, /24, the old classes A, B and C, but that's all ancient internet history. It was easier, though!
Now, with subnetting, you can have a network which is, for example, a /12 like the one above, given to you as 192.160.0.0/12, and in order to calculate the broadcast address you have to convert it to binary and then replace all the extra zeros with ones.
Starting with:
192.160.0.0/12,
convert to binary:
network1 - 11000000.10100000.00000000.00000000 (/12)
replace the last (32 - 12 = 20) zeros with ones:
network1 broadcast address - 11000000.10101111.11111111.11111111 (/12)
and convert back to decimal:
network1 broadcast address - 192.175.255.255
Not at all intuitive, unlike the old class system. But it's what we must use now. But don't complain too much, we're supposed to move to IPv6, and
then the PITA will be worse!