IP addressing and subnets — theory with masks, a bitwise AND and a router that only looks at the network (and the mask that left me talking to myself)
Network configuration lab, desk 7. I had to set my laptop to the IP 10.110.7.24 and, as usual, I copied the settings in a rush. ping to the gateway: perfect. ping to the campus server: perfect. ping to the classroom 12 printer: “Destination Host Unreachable”, over and over again. I blamed the cable, the switch and the printer. The mistake was mine: I had typed the mask 255.255.0.0 instead of 255.255.255.0. With that mask, my laptop believed the printer was on its own network, so it looked for it around classroom 7, shouting “who has this IP?” and, of course, nobody answered. I was talking to myself.
That day I understood that the mask is not a number you fill in just because: it is what decides whether a datagram is delivered directly or handed to the router. Today you will see how many networks are joined into an internetwork, what an IP address looks like (format and classes), what service the IP protocol gives, the IPv4 datagram header with fragmentation, how a router decides with its table, subnets with their mask, and the protocols that help IP: ARP, RARP, ICMP and DHCP. If you come from the OSI and TCP/IP models, you already know that IP lives in the Internet layer; today we go inside it. And when you finish, the exam-style IP addressing and subnets exercises are waiting.
The example that runs through the whole article is the faculty network, the same one as in the previous topic. The laptop has the IP 10.110.7.24 with mask 255.255.255.0 and its gateway is 10.110.7.1, the faculty router. The campus server, 10.200.1.80, is on another network, the data centre’s, behind a second router, 10.110.1.2.
Table of Contents
Internetworking at the network level
A single network is not enough for everybody: the classroom network is a LAN, the operator’s is a WAN, each with its own technology. But users want to talk to anyone, wherever they are. TCP/IP’s answer is a unified, cooperative interconnection of networks that gives a universal communication service: many physical networks that, from the outside, look like one. That is the Internet, the internetwork.
The pieces that join the networks are gateways or routers (the notes use both names for the same thing). Their goal is to hide the hardware details of the underlying networks and give the appearance of a single network.
Look at the two halves of the picture. At the top, what the user sees: their laptop, “the Internet” and the server. At the bottom, what is really there: the classroom 7 network, the faculty backbone and the data centre network, joined by two routers. To make that work, the TCP/IP internetwork rests on three premises:
- Hide the interconnection architecture from users and applications.
- Do not impose a particular topology: the networks can be joined in any way.
- The internetwork is independent of the user interface: the application does not change even if the networks underneath do.
And one idea you will see all through the topic: routers forward packets based on the destination network, not the destination device. The faculty router has no route for the server 10.200.1.80; it has one for the network 10.200.1.0, and that is enough to know which next router to pass it to.
Remember the difference from the previous topic. The switch works with MAC addresses and joins devices on the same network (network access layer). The router needs the IP address and joins different networks (it reaches the Internet layer). Everything today is the router’s job.
IP addresses
For a datagram to arrive, every connection to the internetwork needs an address that identifies it worldwide: the IP address.
The format: 32 bits in four numbers
An IPv4 address has 32 bits (4 bytes) and an IPv6 address has 128 bits. Writing 32 ones and zeros would be torture, so each byte is written in decimal and separated by dots. That is why each number goes from 0 to 255: it is what fits in 8 bits.
In the picture you have 10.110.7.24 inside out: 10 is 00001010, 110 is 01101110, 7 is 00000111 and 24 is 00011000. Below it, the mask 255.255.255.0: ones in the first three bytes and zeros in the last. You will see that those ones mark which part of the address is the network (10.110.7) and which part is the host (24).
Two things that come up in the exam:
- The IP address identifies the device’s connection to the Internet, not the device itself. A router with three interfaces has three IPs, one on each network.
- The IP is not the same as the hardware address of the network card (the MAC). The MAC comes from the factory and only works inside the local network; the IP comes from the configuration and works across the whole internetwork.
Classes A, B, C and D
In the original design, the address was split into two parts, the network identifier and the device identifier, and the size of each part depended on the class. The class is recognised by the first bits of the address.
Look at the coral bits at the start of each bar: a 0 is class A, 10 is class B, 110 is class C and 1110 is class D. Each class adds a 1 in front, which is why the first byte is enough to know the class:
| Class | Starts with | Network / host | First byte | Example |
|---|---|---|---|---|
| A | 0 | 8 bits / 24 bits | 0 – 127 | 10.110.7.24 |
| B | 10 | 16 bits / 16 bits | 128 – 191 | 172.30.3.5 |
| C | 110 | 24 bits / 8 bits | 192 – 223 | 193.145.138.32 |
| D | 1110 | multicast address | 224 – 239 | 224.0.0.9 |
What class is 191.4.20.1? 191 = 10111111, it starts with 10: class B. And 192.5.48.3? 192 = 11000000, it starts with 110: class C. One unit of difference in the first byte and the class changes.
Do not convert anything to binary in the exam unless you need to. Learn the first-byte cut-offs: 128, 192 and 224. Below 128, A; up to 191, B; up to 223, C; from 224, D.
Class D addresses do not belong to one device but to a group (multicast): a datagram sent to one of them reaches every device that has joined that group. That is why in the picture they have no network part and host part.
Outside class you will see addresses written like 10.110.7.24/24. The /24 says how many ones the mask has (24 = 255.255.255.0). It is the modern way to split the address without depending on the class; the IC2 exam asks with classes and masks, but it is worth recognising.
The IP protocol and its features
IP carries the units of information between the source computer and the destination, whether they are on the same network or on different networks joined by routers, and it makes the Internet transparent to the devices that communicate: they do not even know how many networks there are in between.
The unit it handles is the datagram: a data packet that is the smallest block of information in a datagram-switched network. Since each datagram carries the source and destination addresses in its header, each one is handled independently.
And what does IP guarantee? Less than it seems:
| IP does | IP does not do |
|---|---|
| Gives a connectionless service (it does not ask before sending) | Sequence control (it does not reorder) |
| Makes independent routing decisions for each datagram | Flow control (it does not slow the sender down) |
| Carries the datagram from source to destination across the networks | Error recovery (it does not resend what is lost) |
Since each datagram travels on its own, three things can happen: lost datagrams, out-of-sequence datagrams and duplicated datagrams. So how does your assignment reach the campus intact? Because TCP runs on top of IP, and TCP does number, reorder and ask for resends.
Saying IP is “reliable” because the Internet works. IP does what it can (best effort); reliability comes from TCP, in the transport layer.
The IPv4 datagram header
Every datagram starts with a header that routers read at every hop. It is drawn in 32-bit rows, and these are the values of our example datagram (1400 bytes of data from the laptop to the campus server):
The fields in purple are the ones asked most. One by one:
| Field | Bits | What it holds |
|---|---|---|
| Version | 4 | Protocol version number (4 for IPv4) |
| IHL | 4 | Header length, in 32-bit words; the minimum is 5 (20 bytes) |
| Type of service | 8 | Precedence (from 0, normal, to 7, network control) and the D (low delay), T (high throughput) and R (high reliability) bits |
| Total length | 16 | Length of the whole datagram, header plus data, in bytes |
| Identification | 16 | Number that uniquely identifies the datagram and helps reassemble its fragments |
| Flags | 3 | Bit 0 reserved (0), DF (don’t fragment) and MF (more fragments) |
| Fragment offset | 13 | Which part of the original datagram the fragment belongs to |
| Time to live | 8 | Makes sure datagrams do not circulate in the network forever |
| Protocol, checksum | 8 + 16 | Who the data is handed to (6 = TCP) and the header check |
| Source and destination addresses | 32 + 32 | The two IPs |
Let’s check the numbers in the picture. Five rows of 32 bits are 5 × 4 = 20 bytes, so IHL = 5. With 4 bytes of options it would be 24 bytes and IHL = 6: always IHL × 4 = header bytes. And the total length is 20 + 1400 = 1420 bytes.
Answering IHL = 20. IHL does not count bytes, it counts 4-byte words. With the minimum header it is 5.
The time to live (TTL) goes down at every router and, when it reaches 0, the datagram is discarded. Without it, a datagram caught in a loop between two routers with bad tables would go round forever.
Fragmentation and reassembly
Every network has an MTU, the largest size that fits in one of its frames. Ethernet allows 1500 bytes, but there may be a smaller network along the way. If the datagram does not fit, the router fragments it: it splits it into pieces, each with its own IP header.
This is the example from the notes with our numbers. The 1400 bytes of data reach a network with MTU 620: taking away the 20-byte header, 600 bytes of data fit per fragment. Three fragments come out: 600 + 600 + 200 = 1400. Notice that each fragment starts exactly where its offset says: the first at 0, the second at 600 (what the first one took) and the third at 600 + 600 = 1200.
So that the destination can join them, all three carry the same identification (4711), and the flags say which one is last:
| Fragment | Data | Offset | MF |
|---|---|---|---|
| 1 | 600 bytes | 0 | 1 (more to come) |
| 2 | 600 bytes | 600 | 1 (more to come) |
| 3 | 200 bytes | 1200 | 0 (last) |
The two flags you have to know:
- DF (Don’t Fragment): 0 = it can be fragmented; 1 = do not fragment. If a datagram with DF = 1 does not fit, the router cannot split it: it discards it and tells the source with ICMP.
- MF (More Fragments): 0 = last fragment; 1 = more fragments follow.
And where are they put back together? In a TCP/IP network, reassembly happens at the destination device, not at the routers.
| Reassembling at the destination | |
|---|---|
| Advantages | Each fragment can be routed separately, even through different networks, and it does not overload the gateways |
| Disadvantages | Inefficiency (every fragment carries a header) and, if a fragment is lost, the reassembly timer runs out and it is impossible to rebuild the datagram |
In the notes the offset is counted in bytes (0, 600, 1200), and that is how you answer in the exam. In the real header it is stored in 8-byte units (0, 75 and 150), which is why fragments always carry a number of data bytes that is a multiple of 8, like 600.
Routing: how a router decides
Routing is the network-layer function that decides the path packets follow between networks. There are two cases:
- Direct: the destination is on the same network. It is delivered without a router: you find out its MAC and send it the frame.
- Indirect: the destination is on another network. The datagram is handed to the next router, which decides again. That is what routing tables are for.
A table has at least two columns: the destination network (a default route is allowed) and the address of the next router (if the router is already on that network, the IP of its interface, or “direct”). Fuller tables add the mask and a cost. Depending on how they are built:
| Tables | How they are built | Do they adapt to changes? |
|---|---|---|
| Static | By hand, taking the network topology into account | No |
| Dynamic | Automatically, with routers exchanging information periodically (routing algorithms) | Yes |
ANDing with the mask
To compare an IP with a row of the table, the router needs to know which network the IP belongs to. The network prefix is obtained with a bitwise AND between the destination address and the mask. AND gives 1 only when both bits are 1:
See how it works column by column: where the mask has a 1, the IP bit goes through as it is; where it has a 0, the result is 0. With 255.255.255.0 that means the first three bytes are copied and the last one is set to zero. 10.200.1.80 AND 255.255.255.0 = 10.200.1.0. It is the same calculation as the example in the notes: 172.30.3.5 AND 255.255.255.0 = 172.30.3.0.
The algorithm, row by row
Now the faculty router receives our datagram for 10.200.1.80. Its table and the algorithm it follows:
It goes through the rows in order. Row 1: 10.200.1.80 AND 255.255.255.0 = 10.200.1.0, which is not 10.110.7.0. Row 2: not 10.110.12.0 either. Row 3: 10.200.1.0 = 10.200.1.0, it matches, so it sends it to the next hop, the data centre router (10.110.1.2). That router will do the same with its own table and see that 10.200.1.0 is its own network: direct delivery to the server.
And what if the destination were www.ulpgc.es (193.145.138.32)? It does not match the first three rows, but it does match the last: 0.0.0.0 with mask 0.0.0.0 is the default route. Any IP AND 0.0.0.0 gives 0.0.0.0, so that row matches everything and takes whatever has no route of its own, in our case towards the Internet exit (10.110.1.1). If there were no default route and no row matched, the datagram would be discarded.
Putting the default route first. Since it matches everything, no other row would ever be used. It always goes last.
The laptop does the same calculation with its own mask before sending anything. If destination AND mask gives its own network (10.110.7.0), direct delivery; if not, it goes to the gateway. That is why a wrong mask breaks the network without a single faulty cable.
Subnets and the subnet mask
A faculty with 40 classrooms could ask for 40 different networks, but it would be a waste and the rest of the Internet would have to know them all. The idea of subnets is to use a single network identifier for several networks: some of the most significant bits of the station (host) part identify the subnet.
The tool is the subnet mask. It has 32 bits, like an IP, and it is coded like this: 1 if that bit identifies the network (subnet included) and 0 if that bit identifies the station.
The picture shows both sides. At the top, 10.110.7.24 split into three parts: 10.110 is the faculty network, 7 is the subnet (the classroom) and 24 is the host. The mask 255.255.255.0 has ones in the first three bytes, so the network reaches as far as the classroom. At the bottom, the tree: from outside only 10.110.0.0 exists (all traffic for 10.110.x.x reaches the faculty router), and inside the router shares it out between the backbone, classroom 7 and classroom 12.
How many hosts fit
In every network or subnet there are two addresses that are not given to any device:
- The network address: all host bits set to 0 (10.110.7.0).
- The broadcast address: all host bits set to 1 (10.110.7.255). A datagram sent to it reaches every device on the network.
If there are h host bits left, there are 2^h addresses and 2^h − 2 hosts. With 255.255.255.0 there are 8 bits left: 2⁸ − 2 = 254 hosts per classroom.
And what if classroom 12 is split into smaller pieces? With the mask 255.255.255.224 the last byte is 11100000: three more bits for the subnet and 5 for the host. Each subnet has 2⁵ = 32 addresses (30 hosts), and they go up in steps of 32:
| Subnet | Network | First host | Last host | Broadcast |
|---|---|---|---|---|
| 1st | 10.110.12.0 | 10.110.12.1 | 10.110.12.30 | 10.110.12.31 |
| 2nd | 10.110.12.32 | 10.110.12.33 | 10.110.12.62 | 10.110.12.63 |
| 3rd | 10.110.12.64 | 10.110.12.65 | 10.110.12.94 | 10.110.12.95 |
| 4th | 10.110.12.96 | 10.110.12.97 | 10.110.12.126 | 10.110.12.127 |
| … | … | … | … | … |
| 8th | 10.110.12.224 | 10.110.12.225 | 10.110.12.254 | 10.110.12.255 |
Check one by hand: which subnet is 10.110.12.70 in? 70 = 01000110 and 224 = 11100000; the AND gives 01000000 = 64. It is in the third one, 10.110.12.64, between .65 and .94.
Answering 2^h instead of 2^h − 2 when they ask for hosts. There are 2^h addresses, but the network and broadcast addresses cannot be assigned.
To get the size of each subnet without binary, subtract the last non-zero byte of the mask from 256: 256 − 224 = 32, 256 − 192 = 64, 256 − 240 = 16. The networks go up in steps of that size.
Support protocols: ARP, RARP, ICMP and DHCP
IP does not work alone. Next to it, in the Internet layer, there are four protocols that always come up together in the exam:
| Protocol | What it does | How to remember it |
|---|---|---|
| ARP | Converts IP addresses into physical (MAC) addresses on the network | Address Resolution: it “resolves” the MAC |
| RARP | Lets a computer that knows its physical address obtain an IP | Reverse: the opposite of ARP |
| ICMP | Lets gateways send error or control messages to other gateways or hosts | Control Message: the warnings |
| DHCP | Dynamic configuration protocol for computers | Dynamic Host Configuration |
ARP: from IP to MAC
When the laptop sends its datagram to the campus server, it already knows from the AND that it has to hand it to the gateway 10.110.7.1. But to put it inside an Ethernet frame it needs the gateway’s MAC, and no routing table says that. This is where ARP comes in:
Follow the numbers in the picture:
- The ARP process on the laptop (A) sends a broadcast (to the MAC ff:ff:ff:ff:ff:ff) with an ARP request carrying the IP it is looking for, 10.110.7.1. The sender includes its own IP-physical address pair in the request.
- Every ARP process on the network receives it. The printer and the classmate see it is not their IP and ignore it.
- The router (B) recognises its IP and sends an ARP response to A with its physical address, no broadcast this time.
- A stores the address pair in its ARP cache (on your computer you can see it with
arp -a), so it does not ask again for every datagram. - The IP process on A can now deliver the datagrams in frames addressed to that MAC.
Now back to my story: with the mask 255.255.0.0, the laptop believed 10.110.12.5 was on its network, so it did not hand the datagram to the gateway. It sent an ARP request for 10.110.12.5 inside classroom 7, and since that device is on another network, nobody answered. Hence the “Destination Host Unreachable”.
ARP also has to deal with physical and internetwork addresses of different lengths. The solutions are direct mapping (a fixed relation, when you want to keep two devices connected) and dynamic binding (the cache one, which is deleted when not used).
RARP: from MAC to IP
RARP (Reverse ARP) does the opposite: a device that only knows its MAC asks for its IP. For that, a RARP server is needed on the physical network: the client requests an address, the server keeps a table relating physical and IP addresses and, when a request arrives, it looks it up and replies. It is hardly used today, because DHCP does the same and much more.
ICMP: the network’s warnings
ICMP lets error or control messages be sent. Two details that come up: it only reports errors to the original source of the data (not to the routers along the way) and its messages are encapsulated in the data field of IP datagrams. Each message starts with a type and a code:
| Type | Meaning | Example code |
|---|---|---|
| 0 | Echo reply | 0 |
| 3 | Destination unreachable | 0 network, 1 host, 3 port, 4 fragmentation needed |
| 5 | Redirect | — |
| 8 | Echo request | 0 |
| 11 | Time exceeded (TTL reached 0) | — |
The ping we used in the network lab is exactly ICMP’s echo request (type 8) and echo reply (type 0).
DHCP: automatic configuration
When you open your laptop at the faculty, nobody types in your IP: DHCP gives it to you, automatically assigning the network configuration to a device when it connects. It has two components: a protocol for delivering configuration parameters to a device from a server and a mechanism for assigning network addresses. There are two allocation mechanisms:
| Mechanism | What the address is like |
|---|---|
| Automatic | Permanent allocation when the station connects for the first time |
| Dynamic | An address lent for a period of time |
This is how a new address is obtained when there are two DHCP servers on the network:
The client sends a DHCPDISCOVER by broadcast, each server answers with a DHCPOFFER, the client picks one offer and asks for it with a DHCPREQUEST (also by broadcast, so the other server knows it was not chosen) and the chosen server confirms with a DHCPACK. Discover, Offer, Request, Ack: DORA. Other messages in the notes:
- DHCPNACK: the server rejects the request (for example, when renewing an address that is no longer valid) and the client starts again.
- DHCPDECLINE: the client checks with ARP that the address is already in use, rejects it and starts again.
- DHCPRELEASE: the client gives the address back.
- To renew the lease, the client sends another DHCPREQUEST to its server and waits for a DHCPACK.
More details: the server listens on UDP port 67 and the client on 68, and a device with several interfaces uses DHCP for each of them.
Saying automatic allocation is the one that “expires”. It is the other way round: automatic is permanent and dynamic is a loan. Both are done by the server on its own, without anybody typing anything.
And DNS, which is not in the Internet layer
The same part of the notes mentions DNS: devices on the Internet are addressed by their IP, but users know them by a name. DNS is an application that provides the destination IP address from the name the user gives: www.ulpgc.es → 193.145.138.32. Careful, it belongs to the application layer: by the time IP comes into play, the name has already been translated.
Common mistakes
Thinking the mask only matters in routers. The laptop itself uses it to decide whether a destination is on its network. A mask that is too short (255.255.0.0 instead of 255.255.255.0) makes it treat devices behind the router as neighbours.
Mixing up ARP and RARP in short-answer questions. ARP: I have the IP, I want the MAC. RARP: I have the MAC, I want the IP.
Saying routers reassemble fragments. Fragments travel separately and are joined at the destination.
Thinking IP reorders or resends. IP does no sequence control, no flow control and no error recovery.
Counting the hosts in a subnet as 2^h. Always subtract the network and broadcast addresses.
Check it with Python
Let’s do in Python what the laptop and the router do: turn the IPs into 32-bit numbers, AND them with the mask, decide whether delivery is direct or goes to the gateway and, if it goes to the router, walk through its table row by row. The data are the article’s. If you want to try it, paste the program into any Python 3 interpreter (it needs nothing installed):
# Check it with Python: direct delivery or to the router? (IC2, topic 3)
# Fixed data: the classroom 7 laptop and the faculty router's table.
def to_bits(ip): # "10.110.7.24" -> one 32-bit integer
a, b, c, d = (int(x) for x in ip.split("."))
return a << 24 | b << 16 | c << 8 | d # each byte takes its own 8-bit slot
def to_text(n): # the way back: integer -> "a.b.c.d"
return ".".join(str(n >> s & 255) for s in (24, 16, 8, 0))
def network(ip, mask): # the network comes from a bitwise AND
return to_text(to_bits(ip) & to_bits(mask))
def ip_class(ip): # only the first bits of the first byte count
b = to_bits(ip) >> 24
return "A" if b < 128 else "B" if b < 192 else "C" if b < 224 else "D"
LAPTOP, MASK, GATEWAY = "10.110.7.24", "255.255.255.0", "10.110.7.1"
TABLE = [ # faculty router: network, mask, next hop
("10.110.7.0", "255.255.255.0", "direct"),
("10.110.12.0", "255.255.255.0", "direct"),
("10.200.1.0", "255.255.255.0", "10.110.1.2"),
("0.0.0.0", "0.0.0.0", "10.110.1.1"), # default: everything else
]
def route(ip): # rows in order, like the algorithm in the notes
for destination, mask, next_hop in TABLE:
if network(ip, mask) == destination: # N = ID AND mask; does it match the row?
return next_hop
return "discard" # with no default row, the datagram is dropped
bits = lambda ip: ".".join(f"{int(x):08b}" for x in ip.split("."))
for label, ip in (("dest. IP", "10.200.1.80"), ("mask", MASK), ("AND", network("10.200.1.80", MASK))):
print(f"{label:>8} {bits(ip)} {ip}")
print(f"\n{'Destination':<16}{'Class':<7}{'Network /24':<15}{'Laptop':<17}Router")
for d in ("10.110.7.200", "10.110.12.5", "10.200.1.80", "193.145.138.32"):
same = network(d, MASK) == network(LAPTOP, MASK) # same network as the laptop?
p, r = ("direct", "-") if same else ("to " + GATEWAY, route(d))
print(f"{d:<16}{ip_class(d):<7}{network(d, MASK):<15}{p:<17}{r}")
The key is in the first two functions. to_bits puts each byte in its place with shifts: the first one moves 24 positions to the left (a << 24), the second 16, the third 8 and the fourth stays where it is; the | joins them into a single number. to_text goes the other way: it shifts right and keeps 8 bits with & 255 (255 = 11111111). With that, network is literally the definition in the notes: a bitwise AND (&) between the IP and the mask.
This is the real output:
dest. IP 00001010.11001000.00000001.01010000 10.200.1.80
mask 11111111.11111111.11111111.00000000 255.255.255.0
AND 00001010.11001000.00000001.00000000 10.200.1.0
Destination Class Network /24 Laptop Router
10.110.7.200 A 10.110.7.0 direct -
10.110.12.5 A 10.110.12.0 to 10.110.7.1 direct
10.200.1.80 A 10.200.1.0 to 10.110.7.1 10.110.1.2
193.145.138.32 C 193.145.138.0 to 10.110.7.1 10.110.1.1
The first three lines are the AND picture with the same bits: the last byte of 10.200.1.80 (01010000) becomes 00000000 because the mask has zeros there. Below, the table of decisions. Now the function that plays the router:
def route(ip): # rows in order, like the algorithm in the notes
for destination, mask, next_hop in TABLE:
if network(ip, mask) == destination: # N = ID AND mask; does it match the row?
return next_hop
return "discard" # with no default row, the datagram is dropped
It walks through TABLE in order and, for each row, computes network(ip, mask), which is the algorithm’s “N = ID AND mask”. If it matches the row’s network, it returns its next hop and stops looking; if none matches, it returns "discard". With our table that never happens, because the last row is the default route.
And my story? It is the same program with just one line changed, MASK = 255.255.0.0, run separately:
dest. IP 00001010.11001000.00000001.01010000 10.200.1.80
mask 11111111.11111111.00000000.00000000 255.255.0.0
AND 00001010.11001000.00000000.00000000 10.200.0.0
Destination Class Network /16 Laptop Router
10.110.7.200 A 10.110.0.0 direct -
10.110.12.5 A 10.110.0.0 direct -
10.200.1.80 A 10.200.0.0 to 10.110.7.1 10.110.1.2
193.145.138.32 C 193.145.0.0 to 10.110.7.1 10.110.1.1
There is my mistake in one row: with /16, 10.110.12.5 gives the network 10.110.0.0, the same as the laptop, and the laptop column says “direct”. The laptop does not hand it to the gateway: it looks for it with ARP in classroom 7 and nobody answers.
What to look for:
- In the first table, 10.110.7.200 is the only direct delivery: its network (10.110.7.0) is the laptop’s, so the router does not even appear (“-”).
- 10.110.12.5 goes to the gateway, but the faculty router delivers it directly: classroom 12 is one of its connected networks (row 2).
- 10.200.1.80 matches row 3 and leaves for 10.110.1.2, the data centre router, just like in the algorithm diagram.
- 193.145.138.32 is class C (193 starts with 110) and has no row of its own: the default route, 10.110.1.1, picks it up.
- With the wrong mask the laptop column changes, but the router column does not: the router uses its own table, not the laptop’s mask.
In the program, replace the default route with any other row (or delete it) and run it again: you will see “discard” appear for www.ulpgc.es. It is the best way to convince yourself of what that last row is for.
Summary
| Concept | What you need to know |
|---|---|
| Internetwork | Different networks joined by routers that look like one; premises: hide the interconnection, no imposed topology, independent of the user interface |
| IP address | 32 bits (IPv6: 128), each byte in decimal with dots; it identifies the connection and is not the MAC |
| Classes | A starts with 0, B with 10, C with 110, D (multicast) with 1110; first-byte cut-offs: 128, 192, 224 |
| IP protocol | Independent datagrams, connectionless, no sequence, flow or error control |
| IPv4 header | IHL in 32-bit words (minimum 5 = 20 bytes), total length, identification, DF/MF flags, offset, TTL |
| Fragmentation | Because of the MTU; same identification, offset, MF = 0 on the last one; reassembly at the destination |
| Routing | Direct (same network) or indirect (table: destination network → next hop); static or dynamic tables; default route last |
| Subnets | Bits from the host part for the subnet; mask 1 = network, 0 = host; network = IP AND mask; 2^h − 2 hosts |
| Support protocols | ARP IP → MAC, RARP MAC → IP (with a server), ICMP errors to the source, DHCP configuration (DORA, UDP 67/68) |
Three ideas to take away:
- The mask decides: IP AND mask gives the network, and if it matches yours delivery is direct; if not, it goes to the router.
- Routers do not know devices, they know networks: they try their table row by row and the default route takes the rest.
- IP does just enough (carrying loose datagrams) and relies on others: ARP for the MAC, ICMP for warnings, DHCP for configuration and TCP, further up, for reliability.
Now it is time to prove it: in the exam-style IP addressing and subnets exercises there is an interactive quiz with every exam format, subnet and fragment calculations, and four open questions with their model answers. This topic closes the networks part; in the next one we start with operating systems: what an operating system is.
Next step: exercisesIP addressing and subnets — exam-style exercises with masks, classes, fragments and ARP (and the DHCP ports I got the wrong way round)Did this article help you? Here is how you can support SergioLearns →




What is an operating system — theory with your laptop on a study afternoon, a write() call and a CPU that never rests (and the three programs that weren’t running at the same time)