Beginner · How networks work · topic 4 of 57 · 30 min
The TCP/IP model and encapsulation
Explanation
Why another model?
The OSI model is a teaching and talking tool. The protocols that actually run the internet, TCP, UDP and IP, were designed around a simpler model, the TCP/IP model (also called the internet protocol suite). Engineers use both: TCP/IP to describe real protocols and OSI layer numbers in everyday speech.
Four layers or five
The original TCP/IP model (described in RFC 1122) has 4 layers. Many books, including Cisco CCNA material, use a 5-layer version that splits the bottom layer into data link and physical, because those jobs are so different.
| OSI layers | TCP/IP 4-layer | TCP/IP 5-layer | Examples |
|---|---|---|---|
| 7 Application, 6 Presentation, 5 Session | Application | Application | HTTP, HTTPS, DNS, DHCP, SSH, SMTP |
| 4 Transport | Transport | Transport | TCP, UDP |
| 3 Network | Internet | Network | IPv4, IPv6, ICMP |
| 2 Data link | Link (network access) | Data link | Ethernet, Wi-Fi, ARP |
| 1 Physical | Link (network access) | Physical | Cables, fibre, radio |
Encapsulation: going down the stack
Encapsulation means wrapping. Each layer takes what the layer above gives it and adds its own header (control information) in front. Ethernet also adds a trailer at the end. Here is what happens when your browser asks a server for a web page:
- Application: the browser creates an HTTP request, for example GET /index.html. This is the data.
- Transport: TCP adds a header with the source port (a random high number such as 51514) and destination port 443 or 80. Now it is a segment.
- Network: IP adds a header with the source IP address (your PC) and destination IP address (the server). Now it is a packet.
- Data link: Ethernet adds a header with source and destination MAC addresses and a trailer with the FCS checksum. Now it is a frame.
- Physical: the NIC turns the frame into bits: electrical signals, light or radio waves.
Data: [ HTTP request ]
Segment: [ TCP header | HTTP request ]
Packet: [ IP header | TCP header | HTTP request ]
Frame: [ Eth header | IP header | TCP header | HTTP request | FCS ]
Bits: 0101100101110...De-encapsulation: going up the stack
At the receiver, the NIC turns bits back into a frame. The data link layer checks the FCS and the destination MAC address, removes the Ethernet header and passes the packet up. The network layer checks the destination IP, removes the IP header and passes the segment up. The transport layer reads the destination port to find the right program (the web server), removes the TCP header, and hands the data to the application.
Routers in the middle only de-encapsulate up to Layer 3. They remove the old frame, read the IP header to choose the path, and build a brand new frame for the next link. The IP addresses stay the same end to end, while the MAC addresses change at every hop (router).
Same-layer and adjacent-layer interaction
- Same-layer interaction: a layer on one machine talks to the same layer on the other machine through its header. The TCP header written by your PC is read only by the TCP layer on the server.
- Adjacent-layer interaction: on one machine, a layer gives a service to the layer above it. TCP gives reliable delivery to HTTP; IP gives routing to TCP.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
The TCP/IP model and encapsulation · 1/7
The internet runs on the TCP slash IP model. It has four layers, or five when you split the bottom layer into data link and physical.
Prefer a video by a teacher? Find free videos on “TCP/IP model encapsulation de-encapsulation explained CCNA” on YouTube ↗
In real life: Opening a Flipkart product page
When you tap a product, the app builds an HTTPS request (application). TCP wraps it with destination port 443 (transport). IP adds Flipkart's server address (network). Your phone wraps the packet in a Wi-Fi frame addressed to your home router (data link) and sends radio waves (physical). Your router removes the Wi-Fi frame, chooses the path and builds a new frame for the fibre link to the ISP. This repeats at every router until the server unwraps it all and reads your request. The reply is wrapped the same way in the opposite direction.
Practice (0/3 done)
Write layer_of(protocol) that returns the TCP/IP 5-layer name for a protocol. Use: "Application" for HTTP, HTTPS, DNS, DHCP, SSH, FTP, SMTP; "Transport" for TCP and UDP; "Network" for IP, IPv4, IPv6, ICMP; "Data link" for Ethernet, ARP, 802.11. Ignore upper or lower case. Unknown names return "Unknown".
Write encapsulate(data, headers) where headers is a list in the order the layers add them, for example ["TCP", "IP", "ETH"]. Each layer wraps what it got from the layer above, so the result for encapsulate("GET /", ["TCP", "IP", "ETH"]) is "ETH|IP|TCP|GET /". Then write decapsulate(frame) that removes the outermost header and returns the rest: decapsulate("ETH|IP|TCP|GET /") returns "IP|TCP|GET /".
A packet crosses three routers from a PC in Kochi to a server in Bengaluru. What happens to the addresses?
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- TCP, UDP and port numbersHow networks work · same module
- TCP/IP and the network layersCyber Security: from zero to SOC analyst · Networking for security
- Inter-VLAN routingSwitching and VLANs
- Access modifiers, static members and encapsulationC# and .NET · Classes and objects
- What full-stack meansFull-Stack Development · What full-stack development is
- Ethernet frames and MAC addressesEthernet, MAC addresses and the Cisco CLI
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which layer of the 4-layer TCP/IP model matches OSI Layer 3?
Answer: Internet
The Internet layer, where IP lives, matches the OSI network layer.
Which OSI layers are combined into the TCP/IP application layer?
Answer: Layers 5, 6 and 7
Session, presentation and application become one application layer.
What does a segment become after the network layer adds its header?
Answer: A packet
Segment plus IP header is a packet.
Which part is added at the end (a trailer) rather than at the front?
Answer: The Ethernet FCS
Ethernet adds the Frame Check Sequence as a trailer to detect errors.
The TCP header on a PC is read only by the TCP layer on the server. What is this called?
Answer: Same-layer interaction
Peer layers on two devices communicate through their headers: same-layer interaction.
How many layers does the OSI model have?Related
In the OSI model, which layer handles encryption and data formats such as JPEG?Related
Answer: Presentation
Layer 6, presentation, deals with formats, encryption and compression.
From The OSI model
What does a TCP receiver use the window size for?Related
Answer: To tell the sender how much data it can send before waiting for an ACK
Windowing is TCP flow control.
What does no switchport do on a layer 3 switch port?Related
Answer: Makes it a routed port that can take an IP address
no switchport turns the port into a layer 3 routed port, like a router interface.
From Inter-VLAN routing
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 1 more topic in “How networks work” before its exam: TCP, UDP and port numbers.
- Module 1 exam: How networks work · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Ethernet, MAC addresses and the Cisco CLI. 57 topics left in the course before the final exam.