// learn Β· networking Β· 8 min

The OSI & TCP/IP layers, animated.

Two famous models describe how data turns into bits on the wire. Watch a packet get wrapped layer by layer at the sender, ride the wire, then unwrap layer by layer at the receiver β€” and see how OSI's 7 layers and TCP/IP's 4 layers describe the same thing.

OSI seven-layer model and TCP/IP four-layer model animated tutorial. Encapsulation walkthrough from application data through Ethernet frame, then decapsulation at the receiver. Covers headers for TCP, IP, and Ethernet plus port, IP-address, and MAC-address concepts.
// osi & tcp/ip layers

A packet wrapped layer by layer at the sender, transmitted, then unwrapped layer by layer at the receiver. Watch the headers stack and peel off.

// before you start
you should know
  • Β·Rough sense of what an IP address is
  • Β·Have heard of TCP and UDP, even vaguely
  • Β·Helpful: the URL flow lesson β€” it shows TCP and IP in context
by the end you'll

Name every OSI layer in order. Explain what header each layer adds, and why IP and MAC addresses serve different purposes.

pace: 8 minutes

// 7 OSI layers, top to bottom: 7 Application, 6 Presentation, 5 Session, 4 Transport, 3 Network, 2 Data Link, 1 Physical. TCP/IP groups layers 5–7 as "Application" and layers 1–2 as "Link".

osi & tcp/ip β€” step 1 / 6 Β· the layers
SENDER7ApplicationHTTP, DNS, SSHApp6PresentationTLS, encodingApp5Sessionsockets, RPCApp4TransportTCP, UDP, portsTransport3NetworkIP, routingInternet2Data LinkEthernet, MACLink1Physicalcables, signalsLinkRECEIVER7ApplicationHTTP, DNS, SSHApp6PresentationTLS, encodingApp5Sessionsockets, RPCApp4TransportTCP, UDP, portsTransport3NetworkIP, routingInternet2Data LinkEthernet, MACLink1Physicalcables, signalsLink(no packet yet)β–’β–’β–’ PHYSICAL WIRE β–’β–’β–’

Two models, same packet

Two famous models describe the same thing: how data turns into bits on the wire. OSI splits it into 7 layers (1 = Physical at the bottom, 7 = Application at the top). TCP/IP groups them into 4 (Link, Internet, Transport, Application). Same packet, different labels.

// key insight

Each layer only talks to the layers next to it. The Transport layer knows nothing about the cable or the Wi-Fi chip. The Network layer knows nothing about your TCP sequence numbers. That isolation is why you can replace one part of the stack β€” swap Ethernet for Wi-Fi, swap TCP for QUIC, swap HTTP for SSH β€” without rewriting the rest.

// exam-ready Β· what each layer adds and how to inspect it
$L7 Application
$L6 Presentation
$L5 Session
$L4 Transport
$L3 Network
$L2 Data Link
$L1 Physical
$TCP/IP : Link
$TCP/IP : Internet
$TCP/IP : Transport
$TCP/IP : Application
$tcpdump -i any -nn
$ss -tlnp
$ip route
$ip neighbor
$ip -s link
// check yourself
4 quick questions
Q1

Which OSI layer adds the source and destination IP addresses?

Q2

Why does a packet need BOTH an IP address and a MAC address?

Q3

Which best describes the difference between TCP and UDP?

Q4

At which OSI layers do switches and routers operate?

These aren't graded β€” they're just for active recall, which is what actually makes the lesson stick.

πŸ§…
// now poke at the layers

Network tools

ping (L3), traceroute (L3), DNS lookup (L7), MTU check (L2/L3), and more. Each one operates at a specific layer β€” try them while picturing where in the stack you are.

open β†’

Read this lesson as text6 chapters Β· quiz answers

  1. 01Two models, same packet

    Two famous models describe the same thing: how data turns into bits on the wire. OSI splits it into 7 layers (1 = Physical at the bottom, 7 = Application at the top). TCP/IP groups them into 4 (Link, Internet, Transport, Application). Same packet, different labels.

  2. 02Application layer β€” your data

    Whatever your program is sending β€” an HTTP request, a DNS query, an SSH packet β€” starts here. At this point it's just bytes the app decided on. No addresses yet, no ports. The kernel hasn't touched it.

  3. 03Transport (TCP) wraps with ports + sequencing

    The kernel wraps your data in a TCP header (or UDP, if your app picked that). The header carries source port (which app on YOUR side), destination port (which app on the other side), and a sequence number so the receiver can reassemble out-of-order packets.

  4. 04Network (IP) wraps with addresses

    Now we need to know how to route this thing across the internet. The IP layer adds a header with source IP, destination IP, TTL (max hops before the packet is dropped), and which protocol is inside (6 = TCP, 17 = UDP).

  5. 05Data Link (Ethernet) wraps with MAC addresses

    Addresses for the next hop on the local network. The Ethernet header adds source MAC (the NIC sending the frame) and destination MAC (usually your default gateway's NIC). A small trailer (FCS) is added at the end so the receiver can detect corruption.

  6. 06Across the wire, then peel back

    The physical layer turns the frame into actual electrical signals, light pulses, or radio waves. The receiver does the reverse β€” strip Ethernet, strip IP, strip TCP β€” and hands the original HTTP request up to its application. Six layers in, six layers out.

Quiz β€” answers

Which OSI layer adds the source and destination IP addresses?
β†’Layer 3 β€” NetworkLayer 3 (Network) is where IP lives. Layer 2 (Data Link) handles MAC addresses for the next-hop link. Layer 4 (Transport) handles port numbers. Layer 7 (Application) is your actual program data.
Why does a packet need BOTH an IP address and a MAC address?
β†’IP is the end-to-end address (doesn't change as the packet crosses routers). MAC is the next-hop address (rewritten at every hop).The IP address tells routers WHERE the packet should ultimately go β€” it stays the same across the whole journey. The MAC address only matters for the current physical link, so it gets rewritten at every router/switch hop. That's why ARP exists: to find out 'what MAC should I use for THIS next hop?'
Which best describes the difference between TCP and UDP?
β†’TCP is connection-oriented and reliable (ordered delivery, retransmission, flow control). UDP is fire-and-forget β€” fewer guarantees, less overhead.Both are Layer 4 transport protocols. TCP gives you a reliable, ordered byte stream (used by HTTP, SSH, most app traffic). UDP gives you tiny independent datagrams with no guarantees (used by DNS, NTP, real-time audio/video, QUIC). Encryption is layered on top β€” TLS over TCP, DTLS or QUIC over UDP.
At which OSI layers do switches and routers operate?
β†’Switches at Layer 2 (MAC addresses on the local link); routers at Layer 3 (IP addresses across networks).A switch forwards frames based on MAC address β€” that's Layer 2. A router forwards packets based on IP address and a routing table β€” that's Layer 3. Modern 'Layer 3 switches' and 'Layer 4-7 load balancers' blur this line, but the textbook answer is L2 / L3.
// more in networking

keep going β€” these pair well with what you just learned.

see all networking β†’

See also

all lessonstry the network tools