Networking works because nobody tries to solve the whole problem at once. Instead the job is cut into layers, each with one responsibility, each talking only to the layer above and below. The layer that puts bits on a wire does not know or care whether those bits are an email or a video call. The layer sending the email does not know or care whether the wire is copper, fibre or radio. That separation is why you can change your Wi-Fi to Ethernet mid-download and the download continues.
The seven OSI layers
| # | Layer | Responsibility | Examples |
|---|---|---|---|
| 7 | Application | The protocol the user's program speaks | HTTP, DNS, SMTP, FTP |
| 6 | Presentation | Encoding, encryption, compression | TLS, JPEG, ASCII/UTF-8 |
| 5 | Session | Opening, maintaining and closing conversations | Session cookies, RPC |
| 4 | Transport | End-to-end delivery, ports, reliability | TCP, UDP |
| 3 | Network | Logical addressing and routing between networks | IP, ICMP, routers |
| 2 | Data link | Physical addressing within one link | Ethernet, MAC, switches |
| 1 | Physical | Bits as voltages, light or radio | Cables, connectors, radio |
Encapsulation
Data travelling down the stack gets wrapped by each layer in turn, like putting a letter in an envelope, the envelope in a courier bag, and the bag in a truck. Each wrapper carries the addressing that layer needs. At the far end the process runs in reverse, each layer stripping its own header. The name of the wrapped unit changes at each layer, and examiners love to ask for those names.
| Layer | Unit is called | Addressing it adds |
|---|---|---|
| Application | Data / message | None |
| Transport | Segment (TCP) or datagram (UDP) | Source and destination port numbers |
| Network | Packet | Source and destination IP addresses |
| Data link | Frame | Source and destination MAC addresses, plus an error check |
| Physical | Bits | None — just signalling |
TCP/IP: the model actually in use
OSI is a teaching model. The internet runs on the TCP/IP model, which collapses the same work into four layers: Application (OSI 5–7), Transport (4), Internet (3) and Network Access or Link (1–2). When somebody says "layer 3 switch" or "layer 7 firewall" they are using OSI numbering, so you need both.
TCP versus UDP
- Three-way handshake establishes a connection first
- Numbers every segment and acknowledges receipt
- Retransmits anything lost; delivers in order
- Flow and congestion control slow down if the network is struggling
- Web, email, file transfer, SSH
- No handshake — just sends
- No acknowledgements, no retransmission, no ordering
- Much lower overhead and latency
- The application deals with loss, if it matters at all
- Voice and video calls, live streaming, DNS lookups, online games
The choice is not "reliable is better". In a video call, a packet that arrives late is useless — the moment it described has already passed — so retransmitting it would waste bandwidth and add delay for nothing. Dropping it and moving on gives a brief glitch instead of a growing lag. That is why real-time media uses UDP and a file download uses TCP: a file with one missing byte is corrupt, but a video with one missing frame is still a video.
| Port | Protocol | Purpose |
|---|---|---|
| 20 / 21 | FTP | File transfer (data / control) |
| 22 | SSH | Secure remote shell |
| 25 | SMTP | Sending email |
| 53 | DNS | Name resolution (mostly UDP) |
| 67 / 68 | DHCP | Automatic IP configuration |
| 80 | HTTP | Unencrypted web |
| 443 | HTTPS | Encrypted web (TLS) |
| 3389 | RDP | Windows remote desktop |