OSI and TCP/IP Models: Layers, PDUs, Protocols, Devices and Ports

Almost every computer paper for PPSC, FPSC, NTS, SSC and bank IT posts has at least one question on network layers. The OSI model splits the job of sending data into seven layers, and the TCP/IP model used on the real Internet groups the same work into four. Once you know what each layer does, what its unit of data is called and which devices and protocols belong to it, most of these questions take seconds. This lesson also lists the port numbers that examiners ask about again and again.

Asked in: PPSC, FPSC, NTS, ETEA, KPPSC, SSC, IBPS and ICS/ECAT computer

The seven OSI layers at a glance

OSI stands for Open Systems Interconnection. It is a reference model published by the International Organization for Standardization (ISO) to describe how two systems communicate. The layers are numbered from the bottom: 1 Physical, 2 Data Link, 3 Network, 4 Transport, 5 Session, 6 Presentation and 7 Application.

Each layer serves the layer above it and uses the layer below it. On the sender, data travels down from layer 7 to layer 1 and onto the cable or radio link; on the receiver it travels back up from layer 1 to layer 7. Layers 5 to 7 deal with the user’s data and applications, while layers 1 to 4 deal with moving that data across the network.

Two memory aids are popular. From layer 7 down: All People Seem To Need Data Processing (Application, Presentation, Session, Transport, Network, Data Link, Physical). From layer 1 up: Please Do Not Throw Sausage Pizza Away.

What each layer does

Physical layer: sends raw bits as electrical, light or radio signals; it defines cables, connectors, voltages and bit timing. Data Link layer: groups bits into frames, adds physical (MAC) addresses, and detects errors on a single link; it has two sublayers, Logical Link Control (LLC) and Media Access Control (MAC). Network layer: gives each device a logical (IP) address and chooses a route for packets across many networks.

Transport layer: provides end-to-end, process-to-process delivery using port numbers; it breaks data into segments, puts them back in order, and can provide flow control and retransmission. Session layer: sets up, manages and ends sessions between applications, controls whose turn it is to talk (dialog control) and inserts checkpoints so that a long transfer can resume after a failure. Presentation layer: translates data formats, and handles encryption and compression. Application layer: offers network services directly to user programs such as browsers and email clients.

PDUs and encapsulation

The unit of data handled at a layer is called its protocol data unit (PDU). At the Application, Presentation and Session layers it is simply called data or a message. The Transport layer calls it a segment (for UDP the name datagram is also used), the Network layer calls it a packet, the Data Link layer a frame and the Physical layer bits.

As data moves down on the sender, each layer adds its own header in front of what it received; the Data Link layer also adds a trailer that carries an error-check value. This wrapping is called encapsulation. The receiver removes the headers layer by layer on the way up, which is called decapsulation.

The TCP/IP model and how it maps to OSI

The TCP/IP model, the one the Internet actually runs on, is usually taught with four layers: Application, Transport, Internet and Network Access (also called Link). Its Application layer covers the work of OSI layers 5, 6 and 7; its Transport layer matches OSI layer 4; its Internet layer matches OSI layer 3; and its Network Access layer covers OSI layers 1 and 2.

Transport layer protocols: TCP (Transmission Control Protocol) is connection-oriented and reliable. It starts a connection with a three-way handshake (SYN, then SYN-ACK, then ACK), numbers its segments, acknowledges them and resends any that are lost. UDP (User Datagram Protocol) is connectionless: it sends datagrams without a handshake or acknowledgements, so it is lighter and faster but does not guarantee delivery. Live video, online games and short DNS queries commonly use UDP. Internet layer protocols include IP and ICMP; the ping command uses ICMP echo messages.

Which device works at which layer

A repeater regenerates a weakened signal and a hub repeats every incoming signal out of all its other ports; neither understands addresses, so both are Physical layer devices. A network interface card, a bridge and an ordinary (layer 2) switch read MAC addresses inside frames, so they are Data Link layer devices. A switch learns which MAC address is on which port and forwards a frame only to the right port, while a hub floods every port.

A router reads the IP address in each packet and picks the best path between networks, so it is a Network layer device. Cables, connectors and signals are Physical layer matters. Many exam questions simply give a device and ask its layer, or give a layer and ask which device belongs there.

Port numbers of common services

A port number tells the Transport layer which program on a computer should receive the data. It is a 16-bit number, so ports run from 0 to 65535. Ports 0 to 1023 are the well-known ports reserved for standard services, and a server listens on its well-known port while the client picks a temporary high-numbered port.

The ports asked most often are: FTP 20 (data) and 21 (control), SSH 22, Telnet 23, SMTP 25, DNS 53, HTTP 80, POP3 110, IMAP 143 and HTTPS 443. SSH is the encrypted replacement for Telnet for remote login. POP3 usually downloads mail to one device, while IMAP keeps mail on the server and keeps every device in sync.

Solved examples

  1. Which OSI layer is responsible for choosing the path a packet takes from Lahore to a server in Mumbai through several networks?
    1. Moving data across many separate networks and picking a route is called routing.
    2. Routing uses logical (IP) addresses, which belong to the Network layer.
    3. The Data Link layer only moves frames across one link, and the Transport layer works end to end between processes, not hop by hop.
    Answer: The Network layer (layer 3)
  2. Ravi’s laptop sends a web page request. Name the PDU at the Transport, Network and Data Link layers as the request moves down the stack.
    1. The Transport layer splits the data and adds a header with port numbers: the PDU is a segment.
    2. The Network layer adds a header with the source and destination IP addresses: the PDU is a packet.
    3. The Data Link layer adds MAC addresses in a header and an error check in a trailer: the PDU is a frame.
    Answer: Segment, packet, frame
  3. An office replaces its hub with a switch. Which layer did the device move up to, and why does traffic become quieter?
    1. A hub is a Physical layer device: it copies every signal to every port without reading any address.
    2. A switch is a Data Link layer device: it reads the destination MAC address of each frame and learns which port leads to it.
    3. So a frame goes only to the port it is meant for, instead of being flooded to all ports.
    Answer: From layer 1 to layer 2; the switch forwards frames only to the correct port
  4. Match the services to their default ports: SSH, DNS, SMTP, HTTP.
    1. SSH, the secure remote login service, uses port 22 (Telnet, its insecure older form, uses 23).
    2. DNS uses port 53. SMTP, which sends and relays email, uses port 25.
    3. Plain HTTP uses port 80, and HTTPS uses 443.
    Answer: SSH 22, DNS 53, SMTP 25, HTTP 80
  5. Ayesha is building a live cricket score app that streams video, and also a banking app that transfers money. Which transport protocol suits each?
    1. Live video can tolerate a few lost pieces but cannot wait for resends, so the lighter, connectionless UDP is preferred.
    2. A money transfer must arrive complete and in order, so the connection-oriented TCP, with acknowledgements and retransmission, is required.
    3. Speed matters most in the first case and reliability matters most in the second.
    Answer: UDP for live video, TCP for the banking transfer
  6. Hamza types an https address into his browser. Trace which protocol or job is involved at each TCP/IP layer before the request leaves his computer.
    1. Application layer: the browser uses HTTP, protected by TLS encryption, so the server is contacted on port 443. A DNS lookup on port 53 first finds the server’s IP address.
    2. Transport layer: TCP opens a connection with the three-way handshake SYN, SYN-ACK, ACK and carries the request in segments.
    3. Internet layer: IP puts the source and destination IP addresses in each packet. Network Access layer: the packet is placed in a frame with MAC addresses and sent as bits over Wi-Fi or cable.
    Answer: HTTPS on port 443 over TCP, carried in IP packets inside frames

Exam shortcuts

Common mistakes

Practice MCQs

  1. Which OSI layer is concerned with sending raw bits as electrical, light or radio signals over the medium?
    A) Physical layer
    B) Data Link layer
    C) Network layer
    D) Transport layer
    Answer: A) Physical layer — The Physical layer, layer 1, defines cables, connectors, voltages and bit timing and moves raw bits. The Data Link layer works with frames, the Network layer with packets and IP addresses, and the Transport layer with segments and ports; none of them deals with the signal itself.
  2. What is the protocol data unit (PDU) at the Data Link layer called?
    A) Segment
    B) Packet
    C) Frame
    D) Bit
    Answer: C) Frame — The Data Link layer wraps a packet with a header holding MAC addresses and a trailer holding an error check, producing a frame. A segment belongs to the Transport layer, a packet to the Network layer and bits to the Physical layer.
  3. Which of these devices works at the Physical layer of the OSI model?
    A) Switch
    B) Hub
    C) Router
    D) Bridge
    Answer: B) Hub — A hub simply repeats every incoming signal out of all its other ports and never reads an address, so it is a layer 1 device. A switch and a bridge read MAC addresses (layer 2), and a router reads IP addresses (layer 3).
  4. Encryption, data compression and translation between different character codes are functions of which OSI layer?
    A) Session layer
    B) Application layer
    C) Data Link layer
    D) Presentation layer
    Answer: D) Presentation layer — The Presentation layer, layer 6, decides how data is represented: it translates formats, encrypts and compresses. The Session layer manages dialogues and checkpoints, the Application layer offers services to user programs, and the Data Link layer handles frames on a single link.
  5. What is the default port number for SSH, used for secure remote login?
    A) 21
    B) 22
    C) 23
    D) 25
    Answer: B) 22 — SSH listens on port 22. Port 21 is FTP control, port 23 is Telnet, the older unencrypted remote login service that SSH replaced, and port 25 is SMTP for sending email.
  6. A server listening on port 53 is most likely providing which service?
    A) DNS
    B) HTTP
    C) POP3
    D) SMTP
    Answer: A) DNS — Port 53 is reserved for DNS, which turns domain names into IP addresses. HTTP uses port 80, POP3 uses port 110 and SMTP uses port 25.
  7. Which transport layer protocol sends data without first setting up a connection and does not acknowledge what it receives?
    A) TCP
    B) IP
    C) UDP
    D) FTP
    Answer: C) UDP — UDP is connectionless: it sends datagrams with no handshake, no acknowledgements and no retransmission. TCP is connection-oriented and reliable, IP works at the Network (Internet) layer rather than the Transport layer, and FTP is an application protocol that itself runs over TCP.
  8. In what order are the messages of the TCP three-way handshake sent when a client opens a connection?
    A) ACK, SYN, SYN-ACK
    B) SYN, ACK, FIN
    C) SYN-ACK, SYN, ACK
    D) SYN, SYN-ACK, ACK
    Answer: D) SYN, SYN-ACK, ACK — The client first sends SYN, the server replies with SYN-ACK, and the client confirms with ACK; only then does data flow. FIN is used to close a connection, not to open one, and the handshake always starts with the client’s SYN.
  9. Which OSI layer controls whose turn it is to send in a conversation and inserts checkpoints so that a long transfer can resume after a failure?
    A) Session layer
    B) Transport layer
    C) Presentation layer
    D) Physical layer
    Answer: A) Session layer — Dialog control and synchronisation with checkpoints are the classic jobs of the Session layer, layer 5. The Transport layer gives end-to-end delivery using ports, the Presentation layer handles formats and encryption, and the Physical layer moves bits.
  10. In the four-layer TCP/IP model, which layer corresponds to the Network layer of the OSI model?
    A) Transport layer
    B) Internet layer
    C) Network Access layer
    D) Application layer
    Answer: B) Internet layer — The Internet layer of TCP/IP does the OSI Network layer’s job: IP addressing and routing of packets. The TCP/IP Transport layer matches OSI layer 4, the Network Access layer covers OSI layers 1 and 2, and the Application layer covers OSI layers 5 to 7.
  11. As Priya’s email travels down the sender’s protocol stack, in which order is it packaged?
    A) Data, packet, segment, frame, bits
    B) Bits, frame, packet, segment, data
    C) Data, frame, segment, packet, bits
    D) Data, segment, packet, frame, bits
    Answer: D) Data, segment, packet, frame, bits — Going down, the Transport layer makes segments, the Network layer turns them into packets, the Data Link layer makes frames and the Physical layer sends bits. Putting packet before segment swaps layers 3 and 4, and the order starting with bits is the receiver’s direction, not the sender’s.
  12. The Data Link layer is divided into which two sublayers?
    A) Session Control and Dialog Control
    B) Transmission Control and Internet Protocol
    C) Logical Link Control and Media Access Control
    D) Error Control and Flow Control
    Answer: C) Logical Link Control and Media Access Control — IEEE divides the Data Link layer into the LLC sublayer, which talks to the Network layer, and the MAC sublayer, which controls access to the medium and uses MAC addresses. TCP and IP are protocols of other layers, dialog control is a Session layer job, and error and flow control are functions rather than named sublayers.
  13. Ayesha reads her email on her phone and her laptop and wants messages to stay on the server so that both devices show the same folders. Which protocol is designed for this?
    A) IMAP
    B) POP3
    C) SMTP
    D) FTP
    Answer: A) IMAP — IMAP (port 143) keeps mail on the server and synchronises folders and read status across devices. POP3 normally downloads mail to one device, SMTP is for sending and relaying mail rather than reading it, and FTP transfers files.
  14. What is the largest port number a TCP or UDP service can use?
    A) 1023
    B) 255
    C) 65536
    D) 65535
    Answer: D) 65535 — A port number is a 16-bit field, so it runs from 0 to 2¹⁶ − 1 = 65535. 1023 is only the top of the well-known range, 255 is the largest 8-bit value, and 65536 does not fit in 16 bits.
  15. Neha types an address beginning with http:// (not https). By default, her browser connects to the web server using:
    A) UDP on port 80
    B) TCP on port 443
    C) TCP on port 80
    D) UDP on port 53
    Answer: C) TCP on port 80 — Plain HTTP runs over TCP, because a web page must arrive complete and in order, and its default port is 80. Port 443 is used for HTTPS, port 53 is DNS, and HTTP does not normally run over UDP.

Questions

Why do we still study the OSI model if the Internet uses TCP/IP?

OSI gives a clear seven-step vocabulary for describing network jobs, so engineers and examiners still say things like a layer 2 switch or a layer 3 device. TCP/IP is the protocol suite that actually runs, and its four layers map neatly onto OSI.

Is the TCP/IP model four layers or five?

Most textbooks and exams use four layers: Application, Transport, Internet and Network Access. Some books split Network Access into Data Link and Physical, giving five. Read the question carefully, and if it says four-layer, use the four names.

What is the difference between a MAC address and an IP address?

A MAC address is a 48-bit hardware address burned into a network card and used within one local network at the Data Link layer. An IP address is a logical address assigned by the network and used at the Network layer to route packets between networks.

Which ports should I memorise first?

Start with 80 HTTP, 443 HTTPS, 21 FTP, 22 SSH, 23 Telnet, 25 SMTP and 53 DNS, then add 110 POP3 and 143 IMAP. These cover nearly all port questions in Pakistani and Indian computer papers.