Computer Networks

From the wire to the browser: the layered models, subnetting arithmetic, TCP's reliability machinery, routing, DNS and HTTPS — with the numbers examiners ask you to compute.

If you remember nothing else

  • OSI has seven layers and is a reference model; TCP/IP has four (or five) and is what actually runs.
  • TCP is connection-oriented, reliable, ordered and flow-controlled; UDP is none of those, which is exactly why it is faster.
  • The three-way handshake is SYN, SYN-ACK, ACK — it exists to synchronise sequence numbers in both directions, not merely to say hello.
  • A /24 network has 256 addresses but only 254 usable hosts — the first is the network address and the last is broadcast.
  • ARP maps an IP address to a MAC address within one broadcast domain; DNS maps a name to an IP address across the internet.
  • Congestion control responds to the state of the network; flow control responds to the state of the receiver. Different problems, different mechanisms.

The layered models

Layering exists so that each level solves one problem and depends only on the service beneath it. A change of physical medium does not disturb TCP; a change of application protocol does not disturb routing.

OSI layerJobData unitTCP/IP layerExamples
7 ApplicationNetwork services to the userDataApplicationHTTP, FTP, SMTP, DNS
6 PresentationTranslation, encryption, compressionDataApplicationTLS, JPEG, ASCII
5 SessionEstablish, manage and end sessionsDataApplicationNetBIOS, RPC
4 TransportEnd-to-end delivery, reliability, portsSegment (TCP) / Datagram (UDP)TransportTCP, UDP
3 NetworkLogical addressing and routing between networksPacketInternetIP, ICMP, OSPF
2 Data LinkFraming and hop-to-hop delivery on one linkFrameNetwork AccessEthernet, PPP, ARP*
1 PhysicalBits onto a mediumBitNetwork AccessCables, hubs, repeaters

*ARP straddles layers 2 and 3 — it carries an IP address inside a link-layer frame. Examiners accept either placement if you explain why.

IP addressing and subnetting

ClassFirst octetDefault maskNetworksHosts per network
A1–126/8 (255.0.0.0)12616,777,214
B128–191/16 (255.255.0.0)16,38465,534
C192–223/24 (255.255.255.0)2,097,152254
D224–239Multicast
E240–255Reserved / experimental

127.x.x.x is loopback and is why class A stops at 126. Classful addressing is obsolete — CIDR replaced it — but it remains examinable.

Plain textWorked subnetting — the standard exam question
Given: 192.168.10.0/24, split into 4 equal subnets. Need 4 subnets -> borrow 2 host bits (2^2 = 4). New prefix: /26 Block size = 256 - 192 = 64 (mask 255.255.255.192) Subnet Network Usable range Broadcast 1 192.168.10.0 192.168.10.1 - 192.168.10.62 192.168.10.63 2 192.168.10.64 192.168.10.65 - 192.168.10.126 192.168.10.127 3 192.168.10.128 192.168.10.129 - 192.168.10.190 192.168.10.191 4 192.168.10.192 192.168.10.193 - 192.168.10.254 192.168.10.255 Each: 64 total addresses, 62 usable hosts (64 - 2). Reverse question - which subnet is 192.168.10.100 in? 100 / 64 = 1 remainder 36 -> subnet starting at 64 -> subnet 2.
Private rangePrefixSize
10.0.0.0 – 10.255.255.25510.0.0.0/8One class A
172.16.0.0 – 172.31.255.255172.16.0.0/1216 class B blocks
192.168.0.0 – 192.168.255.255192.168.0.0/16256 class C blocks
IPv4IPv6
Address size32 bits128 bits
NotationDotted decimal, 192.168.1.1Hex colon groups, 2001:db8::1
HeaderVariable length, 20–60 bytesFixed 40 bytes — faster to process
Checksum in headerYesNo — left to layers 2 and 4
FragmentationRouters or senderSender only
ConfigurationManual or DHCPAlso stateless autoconfiguration (SLAAC)
BroadcastYesNo — replaced by multicast and anycast

Routing

Distance vectorLink state
Each router knowsDistance to every destination, via neighboursThe full topology of the network
SharesIts whole table, with neighbours onlyIts link states, flooded to everyone
AlgorithmBellman-FordDijkstra
ConvergenceSlow; count-to-infinity problemFast
Resource useLow CPU, low memoryHigher CPU and memory
ProtocolsRIP, IGRPOSPF, IS-IS
  • Interior gateway protocols (RIP, OSPF, EIGRP) route within one autonomous system and optimise for shortest path.
  • BGP is the exterior protocol routing between autonomous systems. It is a path-vector protocol and optimises for policy — business relationships between providers — rather than for hop count.
  • Longest prefix match decides forwarding: given routes for 10.0.0.0/8 and 10.1.0.0/16, a packet for 10.1.2.3 takes the /16, because the more specific route wins.
  • TTL (hop limit) decrements at every router; at zero the packet is discarded and an ICMP Time Exceeded returned. This both kills routing loops and is the mechanism traceroute exploits.
DeviceLayerForwards onCollision domainsBroadcast domains
Hub1 PhysicalNothing — repeats to all portsOne (shared)One
Switch2 Data linkMAC addressOne per portOne (unless VLANs)
Router3 NetworkIP addressOne per portOne per port
GatewayUp to 7Protocol translation

The examinable line: a switch segments collision domains, a router segments broadcast domains.

The transport layer: TCP and UDP

TCPUDP
ConnectionConnection-oriented (handshake first)Connectionless — just send
ReliabilityGuaranteed delivery, retransmits lossesBest effort; losses are not detected
OrderingReassembles in orderNone — datagrams may arrive out of order
Flow controlYes — sliding windowNo
Congestion controlYesNo
Header size20–60 bytes8 bytes
SpeedSlower — acknowledgements and handshakesFaster
TransmissionByte streamDiscrete datagrams, boundaries preserved
Used byHTTP, HTTPS, FTP, SMTP, SSHDNS, DHCP, VoIP, video streaming, online games

The three-way handshake

  1. SYN

    The client sends a segment with the SYN flag set and its initial sequence number x. The client is now in SYN-SENT.
  2. SYN-ACK

    The server replies with SYN set, its own initial sequence number y, and ACK = x+1. The server is now in SYN-RECEIVED.
  3. ACK

    The client sends ACK = y+1. Both sides are ESTABLISHED, and both now know the other's starting sequence number.

Teardown takes four messages, because TCP connections are full duplex and each direction closes independently: FIN from the initiator, ACK from the peer, FIN from the peer once it has finished sending, and a final ACK. The closer then waits in TIME_WAIT for twice the maximum segment lifetime, so that stray duplicates from this connection cannot be mistaken for data on a new connection reusing the same port pair.

Flow control and congestion control

TCP's sender is limited by the smaller of the two: .

Sliding window and ARQ

ProtocolOn a lost frameReceiver bufferEfficiency
Stop-and-waitRetransmit the one frameNoneVery poor on long links — one frame in flight
Go-Back-NRetransmit that frame and all after itNone — discards out-of-order framesSimple receiver, wasteful sender
Selective RepeatRetransmit only the lost frameBuffers out-of-order framesEfficient; more complex, needs window ≤ half the sequence space

Congestion control phases

  1. Slow start

    The congestion window starts at 1 MSS and doubles every RTT — exponential growth despite the name — until it reaches the slow-start threshold.
  2. Congestion avoidance

    Past the threshold, the window grows by roughly 1 MSS per RTT — linear (additive increase), because the network is now near capacity.
  3. Fast retransmit

    Three duplicate ACKs signal a lost segment without waiting for a timeout. Retransmit it immediately.
  4. Fast recovery

    After a fast retransmit, halve the window rather than dropping to 1 (multiplicative decrease) — three duplicate ACKs prove packets are still flowing, so the network is congested, not broken.

The application layer

DNS

DNS resolves a hostname to an IP address through a hierarchy: root servers, then top-level domain servers (.com), then the authoritative server for the domain. A recursive resolver does this walking on the client's behalf and caches the result for the record's TTL. It runs over UDP port 53 for speed, falling back to TCP when a response exceeds 512 bytes or for zone transfers.

RecordMapsExample
AName → IPv4 addressexample.com → 93.184.216.34
AAAAName → IPv6 addressexample.com → 2606:2800:220::
CNAMEName → another name (alias)www.example.com → example.com
MXDomain → mail serverexample.com → mail.example.com
NSDomain → authoritative name serverexample.com → ns1.example.com
PTRIP → name (reverse lookup)Used in spam filtering

HTTP

MethodPurposeSafe?Idempotent?
GETRetrieve a resourceYesYes
POSTSubmit data; create a subordinate resourceNoNo
PUTReplace a resource entirelyNoYes
PATCHPartially modify a resourceNoNot necessarily
DELETERemove a resourceNoYes
HEADGET without the bodyYesYes

Safe means it does not change server state. Idempotent means N identical requests have the same effect as one — which is why a failed PUT can be retried safely and a failed POST cannot.

Status classMeaningCommon codes
1xxInformational100 Continue, 101 Switching Protocols
2xxSuccess200 OK, 201 Created, 204 No Content
3xxRedirection301 Moved Permanently, 302 Found, 304 Not Modified
4xxClient error400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found
5xxServer error500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable

Self-check

12 questions on Computer Networks · nothing is stored

0/12 answered
Question 1

1.How many usable host addresses does a /27 subnet provide?

Question 2

2.The TCP three-way handshake requires three messages because:

Question 3

3.Which statement correctly distinguishes flow control from congestion control?

Question 4

4.A switch and a router differ in that a router:

Question 5

5.DNS primarily uses UDP rather than TCP because:

Question 6

6.In TCP slow start, the congestion window:

Question 7

7.Which HTTP method is idempotent but not safe?

Question 8

8.ARP is used to:

Question 9

9.Go-Back-N differs from Selective Repeat in that Go-Back-N:

Question 10

10.The key difference between HTTP 401 and 403 is:

Question 11

11.TLS uses asymmetric cryptography mainly to:

Question 12

12.Count-to-infinity is a problem in: