AQA 7517, section 4.9.4.1
TCP/IP is the set of protocols that the Internet runs on. They are organised in layers, called the TCP/IP stack. Each layer has its own job, and uses the layer below it. Splitting the job into layers makes it easier to design, change and understand each part separately.
The four layers
| Layer | Role | Examples |
|---|---|---|
| Application | The layer where programs such as a web browser, an email server or a file server run. Each program uses the protocol for its job (a browser uses HTTP or HTTPS, an email server uses SMTP), which defines the messages they exchange. The data is then passed down to the transport layer. Some protocols also encrypt the data at this layer before passing it down, such as HTTPS (using TLS) and SSH | HTTP, HTTPS, FTP, SMTP, POP3, IMAP, SSH |
| Transport | Sets up an end-to-end connection between the two programs on different hosts. It splits the data into segments, and adds sequence numbers, the source and destination port numbers and a checksum to each one. With TCP, the receiver sends acknowledgements, and lost or corrupted segments are resent. At the receiver, it reassembles the segments in order and uses the destination port to pass the data to the right application. It also handles flow control (matching the sender's speed to the receiver's) and congestion control | TCP, UDP |
| Network (Internet) | Wraps each segment in an IP packet (also called a datagram), adding the source and destination IP addresses, a time to live (hop limit, so a packet that never arrives is eventually discarded) and a header checksum. The sender uses its subnet mask to decide whether the destination is on the same local network or must go via the router (gateway). Routing: each router uses the destination IP address to choose the next hop | IP |
| Link (also called the physical or network access layer) | Wraps each packet in a frame with the source and destination MAC addresses, and delivers it over one physical link (one local network). If the destination isn't on the local network, the destination MAC address is the router's (gateway's). It is the physical interface to the network: it uses the network interface card (NIC) and its device driver to turn the frame into signals on the medium (electrical signals on a cable, light in a fibre, radio waves for WiFi) | Ethernet, WiFi |
How the layers work together
When data is sent, it passes down the stack on the sender, with each layer adding its own header (encapsulation). At the receiver it passes up, with each layer removing its header.
Sockets
A socket is one end of a two-way communication link between two programs on a network. It is the combination of an IP address and a port number:
For example 192.168.1.20:443. A connection is identified by a pair of sockets, the sender's and the receiver's. Programs use sockets to send and receive data, without worrying about the layers underneath.
MAC addresses
A MAC (Media Access Control) address is a unique hardware address assigned to a network adapter by the manufacturer, such as 3C:22:FB:4A:91:0E.
- It is 48 bits long, written as six pairs of hexadecimal digits.
- It is used at the link layer to deliver frames to the right device on the local network.
- It doesn't change as you move between networks, unlike an IP address.
- As a packet moves across the Internet, the IP addresses stay the same (source and destination), but the MAC addresses change at each hop, since they only identify the sender and receiver of one link.
| IP address | MAC address | |
|---|---|---|
| Layer | Network | Link |
| Identifies | A device's location on a network | The network adapter hardware |
| Changes? | Yes, with the network | No (fixed to the adapter) |
| Used for | Routing across networks | Delivery within one network |
Ports
An IP address gets data to the right computer. A port number gets it to the right program on that computer. A port is a number from 0 to 65 535 (16 bits).
Well-known ports
Well-known ports (0 to 1023) are reserved for standard services. A server listens on its well-known port, so a client knows where to connect.
| Port | Protocol |
|---|---|
| 20, 21 | FTP |
| 22 | SSH |
| 25 | SMTP |
| 53 | DNS |
| 80 | HTTP |
| 110 | POP3 |
| 443 | HTTPS |
Client (ephemeral) ports
A client port is a temporary port chosen by the client's operating system for each connection, from the high range (for example 49 152 to 65 535). It is used as the return address for the server's reply, and is released when the connection ends.
Example: your browser requests a page.
The server replies to port 52001. If you open two tabs, each connection uses a different client port, so replies can be matched to the right tab.
| Well-known port | Client port | |
|---|---|---|
| Range | 0 to 1023 | High numbers, such as 49 152 to 65 535 |
| Chosen by | A standard (fixed) | The client's OS (random) |
| Used by | Servers, to offer a service | Clients, for one connection |
| Lifetime | Always listening | Temporary |
Worked example
Task: you open https://www.example.com and send an email at the same time. Describe the sockets involved.
- The web connection goes from your IP and a random client port (for example 52001) to the server's IP on port 443.
- The email is sent from your IP and a different client port (for example 52002) to the mail server's IP on port 25 (SMTP).
- Because each connection has its own pair of sockets, the replies reach the correct program, even though they share the same computer and IP address.
Exam tip: name the four layers in order and give the role of each. Say a socket is an IP address plus a port number, and that well-known ports are fixed for services on servers, while client ports are temporary and chosen by the client.
Check yourself
Name the four layers of the TCP/IP stack
Application, transport, network (internet) and link.
What is a socket?
One end of a two-way communication link, made up of an IP address and a port number.
What is a MAC address used for?
It uniquely identifies a network adapter and is used at the link layer to deliver frames to the right device on the local network.
What is the difference between a well-known port and a client port?
Well-known ports are fixed numbers (0 to 1023) reserved for standard services on servers, such as 80 for HTTP. Client ports are temporary high numbers chosen by the client's operating system for each connection.