Protocols and the TCP/IP stack

A2 · 17 min

Two computers made by different manufacturers, running different operating systems and connected through dozens of networks, can exchange a web page in a fraction of a second. That only works because every device follows the same protocols, and because the protocols are organised as a stack of layers, each with one job. Paper 3 asks you to explain why protocols are essential, to describe the four layers of the TCP/IP suite and what each does, and to describe what happens at each layer when a message is sent from one host to another across the internet.

What a protocol is and why it is essential

Definition

A protocol is a set of rules that govern how data is transmitted between devices: the format of the data, how it is addressed, the order and timing of messages, and how errors are detected and dealt with.

Think of a phone call between two people who share no language and have never agreed who speaks first. Each can make sounds, but nothing is communicated. Computers are in the same position: one sends a stream of bits, and the other can only make sense of them if both agree exactly what every bit means.

A protocol fixes, among other things:

  • the format of messages: which bits are the header, which are the data, how long each field is
  • addressing: how the sender and the receiver are identified
  • timing and sequencing: who sends first, how long to wait for a reply, how to put pieces back in order
  • error detection and correction: checksums, acknowledgements, what to do if data is lost or corrupted
  • flow control: how to stop a fast sender overwhelming a slow receiver
  • the transmission medium and signalling at the lowest level
Key result

Protocols are essential because they allow devices from different manufacturers, running different software on different networks, to communicate: both ends agree on the same rules, so data sent by one can be correctly interpreted by the other.

Why protocols are arranged in a stack

Getting a file from one computer to another involves many separate problems: what the application wants, splitting it into pieces, finding a route across the internet, and physically sending bits along a cable or radio link. Rather than one huge protocol that does everything, the work is divided into layers. Each layer has its own protocols and its own function.

Definition

A protocol stack is a set of protocol layers in which each layer performs a specific function, provides services to the layer above it and uses the services of the layer below it.

The layered approach has clear benefits:

  • Each layer can be designed, understood and tested separately. A complex problem is decomposed into smaller ones.
  • Layers are independent. A protocol at one layer can be changed or replaced without changing the others, as long as the interface between layers stays the same. Replacing Ethernet with Wi-Fi at the bottom layer does not require any change to a web browser.
  • Different manufacturers can make products for different layers (network cards, routers, browsers) that work together.
  • Each layer on the sender talks logically to the same layer on the receiver, so a programmer at one layer need not know the details of the others.

The four layers of TCP/IP

The internet uses the TCP/IP protocol suite, named after its two most important protocols, TCP and IP. It has four layers.

Key result
LayerFunctionExample protocolsUnit of data
ApplicationProvides network services to applications; defines the format and meaning of the messages applications exchangeHTTP, HTTPS, FTP, SMTP, POP3, IMAP, DNS, BitTorrentmessage / data
TransportSets up end-to-end communication between processes on the two hosts; splits data into segments, numbers them, uses port numbers, checks for errors, acknowledges and retransmits lost data, controls flow, reassembles at the destinationTCP, UDPsegment (TCP) / datagram (UDP)
Internet (network)Adds source and destination IP addresses; forms packets; routes each packet across networks from host to host via routersIP (IPv4, IPv6), ICMPpacket
Link (network access)Transmits data across one physical link between directly connected devices; adds MAC addresses; converts data into signals on the medium; detects transmission errors on that linkEthernet, Wi-Fi (802.11)frame

Application layer

The application layer is where programs that use the network (browsers, email clients, file-transfer programs) hand their data to the stack. Its protocols define what the messages mean: an HTTP request asks for a web page; an SMTP command sends an email. The application layer does not care how the data gets there. The individual protocols are covered in application-layer protocols.

Transport layer

The transport layer gets data from a process on one host to the correct process on the other. Two hosts may have many network programs running at once, so each is identified by a port number (for example 80 for HTTP, 443 for HTTPS, 25 for SMTP).

TCP (Transmission Control Protocol) provides reliable, connection-oriented delivery:

  • it establishes a connection before data is sent (the three-way handshake: SYN, SYN-ACK, ACK)
  • it splits the application's data into segments and gives each a sequence number
  • the receiver sends acknowledgements; any segment that is not acknowledged in time is retransmitted
  • a checksum in each segment lets the receiver detect corruption
  • the receiver uses the sequence numbers to reassemble the data in the right order, whatever order the segments arrived in
  • flow control stops the sender sending faster than the receiver can cope

UDP (User Datagram Protocol) is connectionless and unreliable: no handshake, no acknowledgements, no retransmission. It is faster and has less overhead, which suits live audio and video, online games and DNS look-ups, where a late packet is useless anyway.

TCPUDP
Connectionset up before data is sentnone
Reliabilityacknowledgements and retransmission guarantee deliveryno guarantee of delivery
Orderreassembled in order using sequence numbersmay arrive out of order
Overheadlarger header, slowersmall header, faster
Used forweb pages, email, file transferstreaming, voice calls, games, DNS

Internet layer

The internet layer moves packets from the source host to the destination host, possibly across many networks. The Internet Protocol (IP) adds a header containing the source and destination IP addresses, and the resulting packet is passed from router to router until it reaches the destination network. Each router uses only the internet layer (and below): it reads the destination IP address and decides where to send the packet next. IP itself is a "best effort" protocol: it does not guarantee delivery or order. That is why TCP is needed above it.

The link layer moves data across one physical link, such as the Ethernet cable from a computer to a switch, or the Wi-Fi connection from a laptop to an access point. It wraps the packet in a frame whose header contains the MAC addresses of the two devices at each end of that link, converts the bits into electrical, light or radio signals, and checks each frame for transmission errors. At every router the frame is removed and a new one is built for the next link, so MAC addresses change hop by hop while IP addresses stay the same end to end.

Encapsulation: what each layer adds

As data passes down the stack at the sender, each layer adds its own header (and the link layer often a trailer too) in front of the data it receives from the layer above. This is encapsulation. At the receiver, data passes up the stack and each layer removes its own header, reads it, and passes the remaining data up.

Application   [ HTTP request: GET /index.html ... ]
Transport     [ TCP header | HTTP request              ]            -> segment
Internet      [ IP header  | TCP header | HTTP request ]            -> packet
Link          [ Frame hdr  | IP header  | TCP header | HTTP request | trailer ]  -> frame
Header added byContains (main fields)
Transport (TCP)source and destination port numbers, sequence number, acknowledgement number, checksum
Internet (IP)source and destination IP addresses, time to live (hop limit), protocol, header checksum
Link (Ethernet)source and destination MAC addresses; the trailer holds a frame check sequence

Sending a message from one host to another

This is the sequence the syllabus asks for. Suppose a browser on host A requests a web page from server B.

What happens at each layer when a message is sent across the internet
  1. Application layer (A). The browser creates an HTTP request for the page and passes it to the transport layer, specifying the destination port (80 for HTTP, 443 for HTTPS).
  2. Transport layer (A). TCP sets up a connection with B (three-way handshake). It splits the request into segments if necessary, and adds a header with source and destination port numbers, sequence numbers and a checksum to each.
  3. Internet layer (A). IP adds a header with A's and B's IP addresses to each segment, forming packets, and decides the next hop (usually A's default gateway router).
  4. Link layer (A). Each packet is placed in a frame addressed to the MAC address of the next hop and transmitted as signals over the physical medium.
  5. Routers along the way. Each router receives the frame, removes the link-layer header, reads the destination IP address, consults its routing table, and forwards the packet in a new frame on the next link. Different packets may take different routes.
  6. Link layer (B). B's network interface receives the frames, checks them for errors, removes the frame headers and passes the packets up.
  7. Internet layer (B). IP checks the destination address is B's, removes the IP header and passes the segments up.
  8. Transport layer (B). TCP checks each segment's checksum, acknowledges segments received, requests retransmission of any missing or corrupted, reorders them using sequence numbers, removes the TCP headers and passes the complete request to the process listening on the destination port.
  9. Application layer (B). The web server reads the HTTP request and sends back the page, which travels down B's stack and up A's in exactly the same way.

Worked examples

Why a protocol is needed

Explain why protocols are essential for communication between computers. [3]

Solution
  • Computers on a network may be made by different manufacturers and use different hardware, operating systems and software.
  • A protocol is a set of agreed rules for transmitting data, covering for example the format of the data, addressing, the order of messages and error checking.
  • If both devices follow the same protocol, the receiver can correctly interpret the data the sender transmits, so communication is possible; without it the bits would be meaningless.

Three points, each a separate idea, for three marks.

Benefits of a layered stack

Explain two benefits of implementing network protocols as a stack of layers.

Solution
  1. Each layer is independent and self-contained, so a protocol at one layer can be changed or replaced (for example a new Wi-Fi standard at the link layer) without needing changes to the other layers, provided the interface between layers is unchanged.
  2. The problem is broken down into smaller, simpler parts, so each layer can be designed, programmed and tested separately, possibly by different organisations or manufacturers whose products then work together.
Identifying the layer

State the TCP/IP layer responsible for each task.

(a) Adding the destination IP address to a packet. (b) Retransmitting a segment that was not acknowledged. (c) Formatting an email message to be sent. (d) Converting data into radio signals for a Wi-Fi network. (e) Directing a received segment to the web server process rather than the email server process.

Solution

(a) Internet layer. (b) Transport layer (TCP). (c) Application layer (SMTP). (d) Link layer. (e) Transport layer: the destination port number identifies the process.

Exam-style: the journey of an email

A user sends an email from a laptop connected by Wi-Fi to a home router. Describe the role of each layer of the TCP/IP protocol suite on the laptop as the email is sent. [8]

Solution
  • Application layer: the email client uses SMTP to format the message (headers such as To, From, Subject, and body) and to issue the commands needed to send it to the user's mail server. It passes the data to the transport layer, addressed to port 25 (or 587).
  • Transport layer: TCP establishes a connection with the mail server. It splits the data into segments, adds a header to each containing the source and destination port numbers, a sequence number and a checksum. It waits for acknowledgements and retransmits any segment not acknowledged, and controls the flow of data.
  • Internet layer: IP adds a header to each segment containing the source IP address of the laptop and the destination IP address of the mail server, forming packets. It determines that packets should be sent to the home router (the default gateway) as the first hop.
  • Link layer: each packet is placed in a frame with the MAC addresses of the laptop and the router, and is transmitted as radio signals using the Wi-Fi protocol; the frame includes an error check for the wireless link.

Marks are given for a correct function of each layer and for naming the protocol and the data added (ports, sequence numbers, IP addresses, MAC addresses).

TCP or UDP

A company runs a video-conferencing service and a document-download service. State, with a reason, which transport protocol each should use.

Solution

Video conferencing: UDP. Speed and low delay matter more than completeness. A lost packet of video should simply be skipped; waiting for TCP to retransmit it would make the picture freeze, and the retransmitted data would arrive too late to be useful. UDP's lower overhead also reduces latency.

Document download: TCP. Every byte of the document must arrive, uncorrupted and in order, or the file is useless. TCP's acknowledgements, retransmission and sequence numbers guarantee this; a small delay does not matter.

Watch out
  • The transport layer does not route packets; that is the internet layer. The transport layer deals with the end-to-end conversation between processes (ports, reliability, ordering).
  • The link layer does not send data "across the internet". It sends it across one link between directly connected devices; a new frame is made at every router.
  • IP addresses identify hosts; port numbers identify processes or services on a host; MAC addresses identify network interfaces on a link.
  • The syllabus model has four layers: Application, Transport, Internet, Link. Do not answer with the seven-layer OSI model unless asked.
Exam tip
  • For "describe the function of a layer" give two or three specific actions, with the protocol and the header fields added, rather than one vague sentence.
  • A sequence-of-events question (sending a message from one host to another) is marked on order: application → transport → internet → link at the sender, routers in between, then link → internet → transport → application at the receiver. Say what is added going down and what is removed and checked going up.
  • Learn the protocol-to-layer mapping cold: HTTP/FTP/SMTP/POP3/IMAP/BitTorrent at the application layer; TCP/UDP at transport; IP at internet; Ethernet/Wi-Fi at link.
Beyond the syllabus

The OSI model splits networking into seven layers (physical, data link, network, transport, session, presentation, application). TCP/IP's application layer roughly covers OSI's top three, and its link layer covers OSI's bottom two. It is useful background, but Paper 3 asks about the four-layer TCP/IP model.

Summary
  • A protocol is a set of rules for data transmission (format, addressing, timing, error handling); protocols let different devices and software communicate.
  • Protocols form a stack: each layer has one function, serves the layer above and uses the layer below; layers can be changed independently.
  • TCP/IP layers: Application (HTTP, FTP, SMTP, POP3, IMAP, BitTorrent), Transport (TCP, UDP: ports, segments, sequence numbers, acknowledgements), Internet (IP: addresses, packets, routing), Link (Ethernet, Wi-Fi: frames, MAC addresses, physical transmission).
  • Going down the stack each layer adds a header (encapsulation); going up each layer removes and acts on its header.
  • TCP is reliable and connection-oriented; UDP is fast and connectionless.

Practice questions

Question
  1. Define the term protocol.
  2. Give three things that a protocol must define.
  3. Explain what is meant by a protocol stack.
  4. Name the four layers of the TCP/IP protocol suite, from top to bottom, and give one protocol used at each.
  5. Describe two functions of the transport layer.
  6. Explain the difference between the role of an IP address and the role of a port number.
  7. Explain why TCP is needed even though IP is used to deliver packets.
  8. A router receives a packet. State which layers of the TCP/IP stack the router uses and explain why it does not need the higher layers.
  9. Describe what happens at each layer of the TCP/IP stack of the receiving host when a web server receives a request for a page.
  10. A school replaces its wired Ethernet network with Wi-Fi. Explain, with reference to the TCP/IP stack, why the web browsers and email software on its computers do not need to be changed.
Answers
  1. A set of rules governing the transmission of data between devices, including the format of the data, addressing, timing/sequencing and error handling.

  2. Any three of: the format of the data and headers; how devices are addressed; the order and timing of messages; error detection and correction; flow control; how a connection is set up and ended; the signalling/transmission medium.

  3. A set of protocols organised into layers, where each layer has a specific function, provides services to the layer above and uses the services of the layer below; each layer communicates logically with the corresponding layer on the other device.

  4. Application (HTTP, FTP, SMTP, POP3, IMAP, BitTorrent); Transport (TCP or UDP); Internet (IP); Link (Ethernet or Wi-Fi).

  5. Any two of: splits data into segments and adds sequence numbers; adds source and destination port numbers so data reaches the correct process; establishes a connection (TCP); acknowledges received segments and retransmits lost ones; checks each segment for errors with a checksum; reassembles segments in the correct order; controls the flow of data.

  6. An IP address identifies the host (device) on the internet that the packet must reach, and is used by routers to deliver the packet across networks. A port number identifies the process or service on that host (for example a web server on port 80) that should receive the data.

  7. IP is a best-effort protocol: packets may be lost, duplicated, corrupted or arrive out of order, and IP does nothing about it. TCP provides the reliability on top: it numbers segments, checks them, acknowledges them, retransmits any that are lost and reorders them, so the application receives exactly the data that was sent.

  8. The link layer (to receive and send frames on each network it connects to) and the internet layer (to read the destination IP address and decide, using its routing table, where to forward the packet). It does not need the transport or application layers because it does not need to know which process the data is for or what the data means; it only moves packets towards their destination host.

  9. Link layer: receives the signals, rebuilds the frames, checks them for errors, checks the destination MAC address, removes the frame header and passes the packet up. Internet layer: checks the destination IP address is this host, removes the IP header and passes the segment up. Transport layer: checks each segment's checksum, sends acknowledgements, asks for retransmission of missing segments, puts the segments in order using sequence numbers, removes the TCP headers and delivers the data to the process listening on the destination port (80/443). Application layer: the web server software reads the HTTP request and acts on it.

  10. Ethernet and Wi-Fi are both link-layer protocols. Because the layers are independent and communicate through fixed interfaces, changing the link layer does not affect the internet, transport or application layers above it. Browsers (HTTP) and email software (SMTP, IMAP) are application-layer programs, which hand data to TCP exactly as before; only the network interface hardware and its link-layer drivers change.

How well do you know this?

Where this leads

Console

Search notes, courses and tools, or run an action