IP Addressing & Protocols lessons
What is an IP address?
An address and its mask in binary; a prefix slider moves the line between network and host bits, with computed readouts.
An IP address is the number that identifies a device on a network. Every piece of data a device sends carries the address it came from and the address it is going to.
An IPv4 address is 32 bits long. The first bits name the network, and the rest name the host, which is the device on that network.
The prefix, like /26, says how many bits belong to the network. By the end of this course you can work out every readout above by hand.
Four numbers, 32 bits
IPv4 addresses are written in dotted decimal, like 192.168.1.10. Each of the four numbers is an octet: 8 bits, so it runs from 0 to 255.
Each octet of 192.168.1.10 in turn, as 8 bits under their place values, with the sum.
Four octets make 32 bits. That allows 2^{32} addresses, about 4.3 billion.
Practice: Read an octet
Turn one octet of an address from binary to decimal, or decimal to 8 bits.
Network part and host part
Devices on the same network share the same network bits. Only their host bits differ.
A device checks the destination's network part before it sends. If it differs, the data goes to the router instead of straight there.
Pairs of addresses compared by network part; the packet goes straight across or through the router.
With a /24 prefix, the network part is the first three octets. With /16 it is the first two, and with /8 just the first.
Practice: Same network or not?
Decide whether two addresses share a network, given the prefix.
Subnet masks
A subnet mask is a second 32-bit number that marks the network bits. It has a 1 for every network bit and a 0 for every host bit.
The prefix /24 is the mask 255.255.255.0: 24 ones, then 8 zeros. Writing the mask as a slash and a count is called CIDR notation.
Address AND mask, octet by octet, with the split octet worked bit by bit, giving the network address.
To find the network address, AND the address with the mask bit by bit. Network bits pass through and host bits become 0.
Masks that split an octet
When the prefix is not a multiple of 8, one octet of the mask is part ones and part zeros. The ones always come first, so that octet has only nine possible values.
Table of the nine mask octet values, from no ones to eight.
To read a mask as a prefix, add 8 for every 255, then the ones in the split octet. So 255.255.240.0 is 8 + 8 + 4, a /20.
Practice: Masks and prefixes
Turn a mask into its prefix, or a prefix into its mask.
Practice: Find the network address
Type the network address for an address and prefix.
Broadcast address and host range
Set every host bit to 1 and you get the broadcast address. Data sent there reaches every device on the network.
Each network is a block of 2^h addresses, where h is the number of host bits. The block starts at a multiple of its size.
The last octet as a strip from 0 to 255, cut into blocks for /24 to /28, with the block holding .77 marked.
The addresses between the network and broadcast addresses are the usable hosts. Those two ends are reserved, so a block has two fewer hosts than addresses.
For a /n network: \text{usable hosts} = 2^{32-n} - 2
Practice: Network, host or broadcast?
Sort addresses into network address, usable host, broadcast address or outside the subnet.
Practice: Count the hosts
Type the usable hosts for a prefix, or the longest prefix that fits a number of hosts.
Ports
An IP address gets data to the right device. A port number gets it to the right program on that device.
Ports run from 0 to 65535. Servers listen on well-known ports, like 443 for secure web pages and 22 for SSH.
Packets for one server address, each sent on to the program listening on its port.
Your own device picks a spare port for its side of each connection. An address and port are written together, like 203.0.113.5:443.
Practice: Match the port
Match well known port numbers to their services.
TCP and UDP
TCP opens a connection with a three-way handshake: SYN, SYN-ACK, ACK. It then numbers the data, and resends any piece the other side does not acknowledge.
UDP skips the handshake and the acknowledgements. It is faster and lighter, but lost data stays lost.
A message ladder: TCP with its handshake, acknowledgements and a resend, then UDP losing a packet.
Use TCP when every byte matters, like email or copying files. Use UDP when late data is useless, like a video call or an online game.
Practice: TCP or UDP?
Sort everyday tasks by the protocol they use.
Private addresses and NAT
Three ranges are private: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. They are never routed on the public internet, so every home and office can reuse them.
Your router has one public address from your internet provider. NAT (network address translation) swaps each device's private address for that public one on the way out.
A laptop and a phone send through a NAT router; the router rewrites addresses and ports and keeps a table to route the reply.
The router gives each connection its own public port and notes it in a table. When a reply comes back to that port, the table says which device gets it.
Practice: Spot the private addresses
Tap every private address in a set of eight.
Practice: Route the reply
Use a NAT table to say where packets go and what addresses they carry.
DHCP: getting an address
A device that joins a network has no address yet. DHCP (Dynamic Host Configuration Protocol) hands it one automatically.
It takes four messages: Discover, Offer, Request and Acknowledge, or DORA. The device broadcasts the first one, because it does not know where the DHCP server is.
The four DORA messages between a laptop and the DHCP server, ending in a lease.
The result is a lease: an address for a set time, plus the mask, the router's address and a DNS server. The device renews it before it runs out.
Practice: Fill in the DHCP messages
Drag addresses into a Discover message and a lease.
DNS: names to addresses
People remember names like www.example.com, but packets need addresses. DNS (the Domain Name System) turns one into the other.
Your device asks a resolver, often run by your internet provider. If it has no saved answer, it asks a root server, then a top-level domain server, then the site's own name server.
A resolver works through root, .com and the site's name server to answer one lookup.
Answers are cached for a while. The next lookup for the same name skips the whole chain.
Practice: Order the lookup
Put the steps of a DNS lookup in order, with and without a cached answer.
IPv6
The central pool of unused IPv4 addresses ran out in 2011. IPv6 uses 128-bit addresses instead, which allows about 3.4 \times 10^{38}.
An IPv6 address is eight groups of four hex digits, with colons between them. Each group is 16 bits.
A full IPv6 address shortened by the two rules, step by step.
Two rules make it shorter. Drop the leading zeros in each group, then swap the longest run of zero groups for ::, once only.
Practice: Shorten an IPv6 address
Type the shortest form of a full IPv6 address.