Why does a message need more than its text?
A delivery service can read a loose page that says “Meeting at 10:00”, but the message does not name its destination. An addressed envelope adds information the service can use to deliver it. The content and the delivery details do different jobs.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Now use a network example. A laptop at 192.168.1.20 requests a page from a lab server at 203.0.113.20. The request needs more than its text: TCP identifies application endpoints with ports, IP identifies the communicating interfaces, and Ethernet identifies the next recipient on the local link. The server address is reserved for documentation; it is not a live website to test.
Encapsulation means adding the protocol information needed to carry data. A header comes before the data it describes; a trailer comes after it. Ethernet, for example, adds an error-check trailer. The receiver processes the corresponding information to recover the application data.
Data: The application produces data, such as an HTTPS request.A complete Ethernet frame
- Data · application
- Segment · transport
- Packet · network
- Frame · data link
Data: The application produces data, such as an HTTPS request. Segment: TCP adds a header with the source and destination ports. Packet: IP adds a header with the source and destination IP addresses. Frame: Ethernet adds MAC addresses in front and an error check (FCS) at the end.
The OSI model names seven networking responsibilities; it does not require seven separate headers in every packet. The strip shows a simplified TCP/IP-over-Ethernet example. We will use OSI to explain what each job contributes.
Opening a website involves several separate jobs: requesting the page, protecting the connection, delivering the data, choosing a route and transmitting signals. Layers organise those jobs, and each layer uses the service of the layer below it. By the end of this lesson, you should be able to answer four questions:
- What does each of the seven layers do, and what is its unit of data (PDU)?
- Which protocols and devices work at each layer?
- Where do MAC addresses, IP addresses and ports fit?
- What happens, layer by layer, when a laptop opens a website?
Why networking was split into layers
Early networking included incompatible vendor systems, which made connecting different products difficult. The OSI (Open Systems Interconnection) model was published by the ISO in 1984 as a common, vendor-neutral way to describe networking. Splitting the work into layers solves several problems:
OSI is a reference model: a way to describe and discuss networking. The protocols that actually run the internet come from the TCP/IP suite.
Learn more: The TCP/IP Model
The seven layers at a glance
OSI is numbered from Physical (1) at the bottom to Application (7) at the top. Data goes down the layers on the sender and up the layers on the receiver.
- 7ApplicationData
Gives programs a way onto the network: the requests and replies they send.
e.g. HTTP, HTTPS, DNS, DHCP, SSH, SMTP
- 6PresentationData
Agrees how data is written: character sets, compression and encryption.
e.g. UTF-8, JPEG, MP4, TLS encryption
- 5SessionData
Opens, keeps track of and closes conversations between programs.
e.g. RPC, NetBIOS, SOCKS
- 4TransportSegment (TCP) / Datagram (UDP)
Gets data to the right program (port) on the other device; TCP adds reliability.
e.g. TCP, UDP
- 3NetworkPacket
Logical (IP) addresses, and choosing a path from one network to another.
e.g. IPv4, IPv6, ICMP, OSPF
- 2Data LinkFrame
Moves frames across one local link using MAC addresses, and checks for errors.
e.g. Ethernet (802.3), Wi-Fi (802.11), PPP
- 1PhysicalBits
Turns bits into signals and back: voltage on copper, light in fibre, radio waves.
e.g. Copper (1000BASE-T), fibre, Wi-Fi radio, connectors
A PDU (protocol data unit) is the name for a unit of data at a given layer. Using the right name tells people which layer you mean: a frame is layer 2, a packet is layer 3.
Memory aid: from layer 7 down, "All People Seem To Need Data Processing". From layer 1 up: "Please Do Not Throw Sausage Pizza Away".
The layers are functional categories. Real protocols don't always fit neatly into one layer, especially at layers 5 to 7.
What each layer contributes
Keep the laptop and lab server in mind. Each section explains one job, how that job works and what it contributes to the same request.
7Layer 7: Application
Gives applications access to network services: asking for a web page, looking up a name, sending an email.
A network service needs rules for requests and replies. HTTP defines how a browser requests a page and how the server replies. DNS defines how to ask for the address of a name. These are application-layer protocols. Your browser uses those protocols; a browser window, a document editor or every other piece of software is not automatically a layer 7 protocol.
In this example: Your browser sends the HTTP request “GET /index.html” to the web server.
Application means the network service and its messages, not everything the user sees on the screen.
6Layer 6: Presentation
Makes sure both sides understand the data: character encoding, data formats, compression and encryption.
Receiving bytes is not enough if the receiver interprets them differently. Character encoding tells software how bytes represent letters. An agreed image format tells it how to read a picture. Compression can reduce the amount of data sent, while encryption protects information from being read in transit. These are different jobs: compressing a file does not make it private.
In this example: The page is encoded as UTF-8 text and encrypted with TLS before it leaves the server.
Presentation describes how information is represented; modern TCP/IP applications and libraries perform these functions.
5Layer 5: Session
Organises a conversation between applications: starting it, coordinating the exchange and ending it.
A conversation may need rules for who sends next or a shared checkpoint from which work can resume. A checkpoint is an agreed record of completed work. Recovery needs support at both ends; naming a session does not make a file transfer resumable. In modern networks, applications often manage their own conversation state instead of using a separate OSI session protocol.
In this example: A resumable transfer application can record completed chunks and request the remaining chunks after reconnecting. The application must implement that behaviour.
A session is a managed conversation; a web login is not proof of a separate layer 5 protocol.
4Layer 4: Transport
Delivers data between the right applications on two hosts, using port numbers. TCP adds reliability and ordering.
An IP address gets traffic to a host interface; a port helps the host give it to the right application endpoint. TCP establishes a connection, numbers the bytes, acknowledges received data and retransmits missing data. Its sliding window lets it send multiple segments before an acknowledgement arrives. Receive flow control limits data to what the receiver can accept; congestion control responds to network conditions. UDP sends separate datagrams without built-in acknowledgements, ordering or retransmission.
In this example: For this TCP-based HTTPS example, your PC uses source port 51524 and destination port 443. TCP recovers missing bytes, but a long outage can still make the connection fail.
TCP provides a reliable, ordered byte stream while the connection works; UDP itself does not guarantee delivery or order.
3Layer 3: Network
Moves packets between different networks using logical (IP) addresses, choosing a route hop by hop.
IPv4 addresses have 32 bits; IPv6 addresses have 128 bits. A prefix length identifies the network portion: with 192.168.1.20/24, the subnet is 192.168.1.0/24. The address alone does not tell you that subnet. A router compares the packet's destination address with its routes and normally chooses the matching route with the longest prefix. A route may come from a connected interface, a static setting or a routing protocol. It is not necessarily the path with the fewest routers or the lowest delay.
In this example: Your packet carries source 192.168.1.20 and destination 203.0.113.20, and each router picks the next hop.
IP addressing and routing choose where a packet goes next; they do not guarantee that it arrives.
2Layer 2: Data Link
Carries data as frames across a link. Ethernet uses MAC addresses for local delivery and an error check to detect damaged frames.
An Ethernet MAC address has 48 bits, usually written as six pairs of hexadecimal digits, such as 02:00:00:00:00:20. Hexadecimal uses 0–9 and A–F. MAC addresses can be locally assigned or changed; they are not guaranteed permanent, globally unique device identities. A switch learns source MAC addresses on incoming ports and looks up destination MAC addresses to forward frames. An unknown unicast destination is normally flooded within its VLAN through eligible ports except the incoming port. The frame check sequence (FCS) detects corruption; Ethernet does not repair the damaged payload.
In this example: Your laptop puts the remote-server packet in a frame addressed to the lab gateway’s MAC address 02:00:00:00:00:01. The local switch carries that frame towards the gateway.
A switch forwards within the local network using MAC addresses; it does not choose the IP route to a remote network.
1Layer 1: Physical
Turns bits into signals and back: voltages on copper, light in fibre, radio waves in the air. Defines cables, connectors and speeds.
A bit is a binary value, 0 or 1. Physical signalling rules describe how those values travel and how a receiver recognises them. Both ends need compatible media and signalling. Full duplex means both ends can send and receive at the same time; half duplex means they take turns. Legacy shared, half-duplex Ethernet used CSMA/CD to handle collisions. Modern full-duplex Ethernet does not use that collision-detection method. A hub repeats signals rather than choosing a destination from a MAC address table.
In this example: On the wired Ethernet link used in this example, the laptop's network interface sends signals along the cable to the switch. A broken cable prevents that first hop.
A working physical link is necessary, but its link light does not prove that IP settings or the application are correct.
Learn more: HTTP: How the Web TalksDNSDHCP
Why layers 5 to 7 do not have neat boundaries in TCP/IP
The Presentation and Session layers deal with how information is represented or protected, and how a conversation is managed. In TCP/IP, applications and supporting protocols do these jobs, so don't expect a separate layer 5 or layer 6 header in every packet. TLS, for example, protects many connections, but calling it “only layer 6” oversimplifies its role.
Learn more: HTTPS and TLS
Layer 4: TCP and UDP
The transport layer delivers data between applications on two hosts:
| TCP | UDP | |
|---|---|---|
| Style | Connection-oriented byte stream | Connectionless datagrams |
| Delivery & order | Reliable and in order | Not guaranteed by UDP itself |
| Lost data | Retransmitted | No built-in retransmission |
| Ports | Yes | Yes |
Applications can add their own reliability on top of UDP, so “uses UDP” doesn't always mean “unreliable”.
Learn more: What the Transport Layer Does
How layers 3, 2 and 1 work together on the first hop
The laptop compares the server address with its own subnet. The server is remote, so the laptop sends through its default gateway at 192.168.1.1. If the gateway MAC address is missing from its cache, the laptop uses ARP (Address Resolution Protocol) to ask which local interface has that IPv4 address.
The IP packet still names 203.0.113.20 as its destination. The first Ethernet frame names the gateway MAC as its destination. The switch forwards that frame towards the gateway; the cable carries the signals. At the router, a route lookup selects the next hop and the outgoing link gets its own frame. ARP does not discover the remote server MAC across the router.
Which devices work at which layer?
A device is usually described by the highest layer it reads to make its forwarding decision. Watch how far “up” each device looks:
Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.
- 1. Switch: layer 2. It learns the source MAC address, looks up the destination MAC address and forwards the frame out of the right port.
- 2. Router: layer 3. It removes the frame, reads the destination IP address, chooses the next hop and builds a new frame.
- 3. Firewall: layers 3 to 7. It checks the IP addresses and the TCP port. A modern firewall may also inspect the application data.
- 4. Hosts: all seven. The web server unwraps every layer to reach the HTTP request itself.
| Layer | Devices |
|---|---|
| 1 Physical | Cables, connectors, hubs, repeaters, media converters, modems |
| 2 Data Link | Switches, access points, NICs |
| 3 Network | Routers, Layer 3 switches |
| 4 to 7 | Firewalls, load balancers, proxies, and every host |
Real devices often work at several layers at once. A home router, for example, is a switch (L2), a router (L3) and a firewall with NAT (L3/L4) in one box.
Learn more: Comparing Network Devices
MAC address, IP address and port: different jobs
| Identifier | Layer | What it identifies |
|---|---|---|
| MAC address | 2 | The sender or next recipient on one local link |
| IP address | 3 | A network interface across an IP network |
| TCP/UDP port | 4 | An application endpoint or service |
An HTTPS connection might look like this:
| Field | Example |
|---|---|
| Client IP | 192.168.1.20 |
| Server IP | 203.0.113.20 |
| Client source port | 51524 (temporary) |
| Server destination port | 443 |
| Transport | TCP |
The reply reverses the ports: source port 443, destination port 51524. (203.0.113.20 is a documentation address, not a live server.)
Common protocols and ports
Port numbers belong to the transport protocols (TCP and UDP), not to the OSI layers in general.
| Service | Transport | Port |
|---|---|---|
| HTTP | TCP | 80 |
| HTTPS (HTTP/1.1, HTTP/2) | TCP | 443 |
| HTTPS (HTTP/3) | QUIC over UDP | 443 |
| DNS | UDP and TCP | 53 |
| SSH | TCP | 22 |
| DHCPv4 server / client | UDP | 67 / 68 |
These are common defaults, not proof of which application sent a packet, because services can run on other ports. ICMP (used by ping) has no ports at all: it is carried directly inside IP.
Learn more: Common Ports to Know
Encapsulation: wrapping data for delivery
On the way down the sender's stack, each protocol adds its own control information, usually a header. This is called encapsulation. On the way up, the receiver removes the relevant protocol information again. This is de-encapsulation(also called decapsulation). Corresponding protocols interpret their fields; a router can also inspect other fields for filtering or policy.
You type a message. The chat app hands it to the network stack.
The names of the data units follow the encapsulation shown at the start:
| Stage | Unit | What's added |
|---|---|---|
| Application | Data | The request or response content |
| TCP | Segment (UDP: datagram) | Ports, sequence numbers and other TCP fields |
| IP | Packet | Source and destination IP addresses |
| Ethernet | Frame | MAC addresses, EtherType and an error-check trailer |
| Physical | Bits | Link-specific signalling |
Here's what the finished Ethernet frame looks like:
This is simplified: HTTPS also adds TLS protection, and a large message is split across many packets. The encapsulation lesson follows every header as it is added and removed, with real addresses, and shows what changes at a router.
Learn more: Encapsulation and De-encapsulation
OSI compared with TCP/IP
TCP/IP is the protocol suite the internet actually runs on. Its common model has four layers. You can switch the diagram to the five-layer view that many courses use:
| OSI layers | TCP/IP layer | Examples |
|---|---|---|
| 7, 6, 5 | Application | HTTP, DNS, DHCP, SSH, plus security and session functions |
| 4 | Transport | TCP, UDP |
| 3 | Internet | IPv4, IPv6, ICMP |
| 2, 1 | Link / Network Access | Ethernet, Wi-Fi, physical transmission |
Use OSI numbers to talk about problems, and TCP/IP to understand what actually runs.
Learn more: The TCP/IP Model
A laptop opens a website
Assume the laptop already has working IP settings and the site uses HTTPS over TCP. Select any step to see which layers are involved.
1. DNS query · Application · UDP 53
What's the address of example.com?
Tap this step's arrow for the details.
Device key: Gateway (router)
Arrows run from each message's sender to its receiver. Rows show message order, not separate cables or elapsed time to scale. Port numbers identify services or conversations, not physical switch sockets.
Logical view: DNS traffic to a remote resolver also passes through the gateway. HTTP/3 replaces the TCP and TLS steps with QUIC over UDP, which builds in TLS.
In order, the important steps are:
- Name resolution: get the server's IP address, unless it is already cached.
- Next-hop choice: is the destination local, or does it need the gateway?
- Local delivery: find the next hop's MAC address with ARP if needed.
- Transport setup: open the TCP connection.
- Security and application: negotiate TLS and send the HTTP request.
A later lesson follows the same request packet by packet.
Learn more: What Happens When You Open a Website?
What a failure looks like at each layer
Each layer depends on the one below it, so a failure at a low layer breaks everything above it. A failure at a high layer leaves the lower layers working:
| Layer | Example symptom | Check |
|---|---|---|
| Physical | No link light | Cable, power, fibre, transceiver, interface status |
| Data link | Link up, but local devices unreachable | Wi-Fi association, switch port, MAC learning, interface errors |
| Network | Other networks unreachable | IP address, mask, gateway, routes |
| Transport | Host reachable, service isn't | Is the service listening? Is the port filtered? |
| Application | Connects, but the request fails | DNS, certificates, authentication, application logs |
Try it: where does it break?
A laptop opens https://example.com. Pick a fault and watch how far the request gets. The lowest layer that fails stops everything above it.
Device key: example.com (server)
Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.
Reading the addresses
IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.
An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.
MAC addresses identify link-layer interfaces or destination groups. They are not IP addresses or website URLs.
- Laptop: IP 192.168.1.20
- Router: IP 192.168.1.1
- example.com: IP 203.0.113.20
Frame 02:00:00:00:00:20 to 02:00:00:00:00:01. Packet 192.168.1.20 to 203.0.113.20.
Tip: click or tap a device to see its details.
- 1. Layers 1–3 on the first link: the frame goes to the router's MAC address; the packet is addressed to 203.0.113.20.
- 2. New frame, same packet: the router strips the frame, routes the packet and builds a new frame for the next link.
- 3. Layer 4 allowed: the firewall permits TCP port 443 and NAT gives the packet a public source address. The server receives the request.
- 4. Reply: the page comes back the same way. Every layer worked.
Working up the stack from a Windows PC
Many engineers check from the bottom up: they prove that each layer works before moving to the next one. Useful commands on a Windows PC:
| Layer | Command | What to inspect |
|---|---|---|
| 1–2 | ipconfig /all, netsh wlan show interfaces | Adapter configuration and reported link/association state; not proof of end-to-end delivery |
| 2–3 | arp -a | The local ARP cache; an entry can be stale and does not prove the gateway is currently reachable |
| 3 | ping 192.168.1.1, tracert 203.0.113.20 | Echo replies and route-hop responses when permitted; missing replies can also be filtering |
| 4 | Test-NetConnection host -Port 443 | A TCP connection to the service opens |
| 7 | nslookup example.com, the browser | DNS replies and application behaviour are separate checks |
PowerShell's Test-NetConnection tests DNS (layer 7), IP (layer 3) and TCP (layer 4) in one command:
PS C:\> Test-NetConnection example.com -Port 443 ComputerName : example.com RemoteAddress : 203.0.113.20 RemotePort : 443 InterfaceAlias : Wi-Fi SourceAddress : 192.168.1.20 TcpTestSucceeded : True
False only says the handshake didn't complete: nothing may be listening, a firewall may be dropping or rejecting it, the host may be down, or the path or a policy may differ for TCP. If the connection opens and the website still fails, look at TLS or the application itself.A successful ping shows that ICMP echo got there and back: layers 1 to 3 work for that traffic, at that moment. It doesn't prove that HTTPS on port 443 works, because firewalls and policies can treat TCP differently from ICMP. “Ping works but the site doesn't load” is one of the most common help-desk reports, and the answer is often at layer 4 or above: a blocked port, a stopped service or a certificate problem.
Learn more: Bottom-Up, Top-Down, Divide and ConquerA Troubleshooting Method
Ways the model gets misapplied
- Thinking every packet has seven headers. Real traffic uses TCP/IP, and layers 5 and 6 rarely have a header of their own.
- Calling everything a “packet”. A frame is layer 2, a packet is layer 3 and a segment is layer 4. Using the right word shows which layer you mean.
- Saying a switch works at layer 3. A normal switch forwards frames using MAC addresses (layer 2). Only a Layer 3 (multilayer) switch can also route.
- Placing ports at layer 3. Ports belong to TCP and UDP at layer 4; IP addresses are layer 3.
- Treating the browser as “the application layer”. The browser is an application that uses layer 7 protocols such as HTTP and DNS.
- Forcing every protocol into one layer. ARP sits between layers 2 and 3, and TLS spans layers 5 to 7. The model is a guide, not a strict rule.
- PDUs: bits (1), frame (2), packet (3), segment or datagram (4), data (5–7).
- Switches work at layer 2, routers at layer 3, firewalls at layers 3 to 7; hosts use all seven.
- MAC addresses, IP addresses and ports do different jobs at layers 2, 3 and 4.
- The sender wraps data in headers; the receiver removes them in reverse order.
- OSI is the shared vocabulary; TCP/IP (taught with four or five layers) is what actually runs.
Which layer is failing? Six scenarios
Test-NetConnection example.com -Port 443 shows RemoteAddress : 203.0.113.20 and TcpTestSucceeded : False. Ping to 203.0.113.20 works. Which layer is failing?
A laptop's Ethernet port shows no link light at all. At which layer should you start looking?
A PC can ping the web server's IP, but the website won't load in the browser.
A router receives data from one network and must forward it to another. What is the layer 3 PDU it works with, and which addresses does it read?
A frame arrives on one port and must be forwarded out of the correct port inside the same LAN, using the destination MAC address. Which device does this?
Users can reach websites by IP address but not by name. Which layer and service is the most likely cause?
From OSI to the TCP/IP model
Continue with The TCP/IP model to see the four layers that really run the internet, then Encapsulation and de-encapsulation to watch each header being added and removed. For layer 2 details, read Ethernet fundamentals and MAC addresses.
Technical references
- ITU-T X.200: OSI basic reference model
- RFC 1122: Internet host communication layers
- RFC 9293: TCP reliability, acknowledgements and flow control
- RFC 768: UDP services and limitations
- RFC 826: resolving local Ethernet addresses with ARP
- RFC 1812: IPv4 routing and longest-prefix matching
- Cisco: Ethernet operation and troubleshooting
Layer mappings describe functions; real implementations do not need a separate module or header for each OSI layer.