what happens at each layer of OSI?

The 7 Layers of the OSI Model

#LayerFunctionCommon Protocols / Tools
7ApplicationWhere users and software interactHTTP, HTTPS, DNS, SSH, SMTP, FTP, SNMP, etc.
6PresentationTranslates, encrypts, and formats dataSSL/TLS, MIME, JSON, ASCII, JPEG
5SessionStarts, manages, and ends sessionsTCP session, NetBIOS, RPC
4TransportEnsures data delivery (error checking, retransmission)TCP, UDP, SCTP
3NetworkHandles routing and addressing between networksIP, ICMP, ARP, BGP, OSPF
2Data LinkTransfers frames between devices on same networkEthernet, Wi-Fi (802.11), PPP, MAC addresses
1PhysicalPhysical transmission of bitsCables, fiber, voltage, NIC, switches

Quick Mental Model

Let’s take curl https://ashwiniag.com . what happens at each layer?

LayerWhat’s happening
7 - ApplicationBrowser sends HTTP GET request
6 - PresentationTLS encrypts request (HTTPS)
5 - SessionSession established via TCP handshake
4 - TransportTCP breaks data into segments, tracks ACKs
3 - NetworkIP routes packets to destination (public IP of server)
2 - Data LinkEthernet/Wi-Fi frames sent to next hop router
1 - PhysicalBits flow through fiber/electric signals

When debugging:

  • Layer 1-2: cable unplugged, NIC down, bad Wi-Fi, ARP issue.
    → Tools: I don't know yet...
  • Layer 3: can’t reach IP → routing issue.
    → Tools: ping, traceroute, ip route
  • Layer 4: packets reach, but port closed.
    → Tools: nc, ss, telnet
  • Layer 7: DNS, HTTP issues.
    → Tools: curl, dig, logs.

Mnemonic to Remember

All People Seem To Need Data Processing
→ Application, Presentation, Session, Transport, Network, Data Link, Physical.

random notes
  • Ports only exist in the Transport Layer (Layer 4),
    • TCP: 80 (HTTP), 443 (HTTPS), 22 (SSH)
    • UDP: 53 (DNS), ? (DHCP)
  • ICMP lives in the Network Layer (Layer 3). operates directly on top of IP, not TCP or UDP