Chapter 2: The OSI Model and TCP/IP Model
2.2 The seven layers
Now let's look at the seven layers one by one. When Mauli Dairy's order page reaches your browser, the data goes from top to bottom on the sender's side and comes back from bottom to top on the receiver's side – this is called encapsulation and decapsulation.
आता सात लेयर्स एक एक करून बघूया. Mauli Dairy चं ऑर्डर पेज तुमच्या ब्राउझरपर्यंत येतं, तेव्हा डेटा सेंडरकडे वरून खाली जातो आणि रिसीव्हरकडे परत खालून वर येतो – यालाच encapsulation आणि decapsulation म्हणतात.
अब सात लेयर्स एक-एक करके देखते हैं. Mauli Dairy का ऑर्डर पेज आपके ब्राउज़र तक आता है, तब डेटा सेंडर की तरफ़ ऊपर से नीचे जाता है और रिसीवर की तरफ़ वापस नीचे से ऊपर आता है – इसी को encapsulation और decapsulation कहते हैं.
Sender Receiver
+------------------+ (logical communication) +------------------+
| 7 Application | <---------------------------------> | 7 Application |
| 6 Presentation | <---------------------------------> | 6 Presentation |
| 5 Session | <---------------------------------> | 5 Session |
| 4 Transport | <------------ segments -----------> | 4 Transport |
| 3 Network | <------------ packets ------------> | 3 Network |
| 2 Data Link | <------------ frames -------------> | 2 Data Link |
| 1 Physical | ============== bits ============== | 1 Physical |
+------------------+ cable / fibre / radio +------------------+
Data goes DOWN the stack (encapsulation) and UP at the receiver (decapsulation)
| # | Layer | Main function | Protocols / standards | Devices | Data unit (PDU) |
|---|---|---|---|---|---|
| 7 | Application | Interface for user applications; network services | HTTP, HTTPS, FTP, SMTP, DNS, SSH, DHCP, SNMP | Gateways, L7 load balancers (AWS ALB), WAF | Data / message |
| 6 | Presentation | Translation, encryption, compression, data format | JPEG, PNG, ASCII, UTF-8, MPEG | — | Data |
| 5 | Session | Establish, maintain, terminate sessions; checkpoints | NetBIOS, RPC, SQL session, PPTP | — | Data |
| 4 | Transport | End-to-end delivery, ports, segmentation, flow & error control | TCP, UDP | L4 load balancers (AWS NLB), firewalls | Segment (TCP) / Datagram (UDP) |
| 3 | Network | Logical addressing (IP), routing between networks | IPv4, IPv6, ICMP, ARP*, OSPF, BGP | Router, L3 switch | Packet |
| 2 | Data Link | Physical (MAC) addressing, framing, error detection on a link | Ethernet (802.3), Wi-Fi (802.11), PPP, VLAN (802.1Q) | Switch, bridge, NIC | Frame |
| 1 | Physical | Transmission of raw bits over the medium; voltages, connectors | RJ-45, fibre, DSL, Bluetooth radio, 802.11 PHY | Hub, repeater, cables, modem | Bit |
* ARP resolves a local IPv4 next hop to a link address on Ethernet. It operates at the local-link boundary. IPv6 uses Neighbor Discovery instead.
Layer-by-layer in simple words
- Layer 7 – Application: What the user's program speaks. The browser speaks HTTP;
sshspeaks the SSH protocol. Not the application itself (Chrome), but the protocol it uses. - Layer 6 – Presentation: Makes data understandable to both sides — character encoding such as UTF-8 and content compression such as gzip. Describe HTTPS by its actual security and transport protocols.
- Layer 5 – Session: Describes managing a conversation. Modern software may implement login and resumed download behavior as application-layer features.
- Layer 4 – Transport: Adds source and destination port numbers. TCP is reliable (3-way handshake, acknowledgements, retransmission, ordering) — used by HTTP, SSH, MySQL. UDP is connectionless and preserves datagram boundaries. DNS and some media applications can use it. Performance depends on the complete protocol stack and path.
- Layer 3 – Network: Adds source and destination IP addresses and chooses the path (routing). Routers work here.
ping(ICMP) tests this layer. - Layer 2 – Data Link: Adds MAC addresses (48-bit hardware address like
0a:1b:2c:3d:4e:5f) to move frames within one local network. Switches work here. - Layer 1 – Physical: Converts frames into electrical signals, light pulses or radio waves.
TCP vs UDP
Students in my class ask: "If TCP is reliable, why isn't it used everywhere?" Look – reliability has a cost (handshakes, acknowledgements, retransmissions). For a small DNS query or a live video call, speed matters more than perfection.
माझ्या क्लासमध्ये स्टुडंट्स विचारतात: "TCP reliable आहे तर सगळीकडे तेच का वापरत नाहीत?" बघा – reliability ला किंमत आहे (handshakes, acknowledgements, retransmissions). छोट्या DNS query साठी किंवा लाइव्ह व्हिडिओ कॉलसाठी स्पीड परफेक्शनपेक्षा जास्त महत्त्वाचा आहे.
मेरी क्लास में स्टूडेंट्स पूछते हैं: "TCP reliable है तो हर जगह वही क्यों नहीं इस्तेमाल करते?" देखो – reliability की कीमत है (handshakes, acknowledgements, retransmissions). छोटी DNS query के लिए या लाइव वीडियो कॉल के लिए स्पीड परफ़ेक्शन से ज़्यादा ज़रूरी है.
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (3-way handshake SYN, SYN-ACK, ACK) | Connectionless |
| Reliability | Ordered byte stream with acknowledgement and retransmission. A failing connection can still prevent delivery. | Best effort; may lose packets |
| Speed / overhead | Minimum TCP header is 20 bytes. Connection and recovery behavior can add exchanges. | UDP header is 8 bytes. Application behavior determines any additional exchanges. |
| Uses | Web (HTTP/1.1, HTTP/2), SSH, e-mail, databases | DNS, DHCP, VoIP, streaming, gaming, HTTP/3 (QUIC) |
Encapsulation
The example shows a simplified TCP/IPv4 exchange on Ethernet. TCP and IP have headers, and this Ethernet frame includes a frame check sequence.
L7-5 [ HTTP data ]
L4 [TCP hdr: ports ][ HTTP data ] = Segment
L3 [IP hdr: IPs][TCP hdr][ HTTP data ] = Packet
L2 [Eth hdr: MACs][IP][TCP][ HTTP data ][FCS] = Frame
L1 0101100101110100101010010101001010101010101... = Bits
Think of encapsulation as a box inside a box: the HTTP data goes into a TCP header box, that goes into an IP header box, and that goes into an Ethernet header box. The receiver opens the boxes one by one in reverse order – this is called decapsulation.
Encapsulation ला डब्यात डबा समजा: HTTP डेटाला TCP हेडरचा डबा, त्यावर IP हेडरचा, आणि त्यावर Ethernet हेडरचा. रिसीव्हर उलट क्रमाने एक एक डबा उघडतो – यालाच decapsulation म्हणतात.
Encapsulation को डिब्बे में डिब्बा समझो: HTTP डेटा को TCP हेडर का डिब्बा, उस पर IP हेडर का, और उस पर Ethernet हेडर का. रिसीवर उल्टे क्रम में एक-एक डिब्बा खोलता है – इसी को decapsulation कहते हैं.
Ravindra Bagale's Tip
In interviews many students say "a switch works at Layer 3". Remember: a normal switch works at Layer 2 (MAC addresses), a router at Layer 3 (IP). Describe HTTPS using its actual protocol stack. HTTP can run over TLS and TCP, while HTTP/3 uses QUIC with TLS security.
Ravindra Bagale's Tip – मराठी
Interview मध्ये बरेच students "switch Layer 3 वर काम करतो" असं सांगतात. लक्षात ठेवा: normal switch Layer 2 (MAC addresses), router Layer 3 (IP). HTTPS मध्ये HTTP आणि त्याचे security व transport protocols वेगळे ओळखा. HTTP/3 साठी QUIC मध्ये TLS सुरक्षा वापरली जाते.
Ravindra Bagale's Tip – हिंदी
Interview में बहुत से students "switch Layer 3 पर काम करता है" बोलते हैं. याद रखो: normal switch Layer 2 (MAC addresses), router Layer 3 (IP). HTTPS में HTTP और उसके security व transport protocols अलग पहचानें. HTTP/3 के लिए QUIC में TLS सुरक्षा इस्तेमाल होती है.
Lab
Tumchya Linux machine var ip addr chalva aani link/ether samor MAC address (L2) aani inet samor IP address (L3) shodha. Mag ek chhota table banva: layer, address cha prakar aani tumcha value.
Read the stack from both ends
The seven-layer table above helps you remember the responsibilities. To use it on a real incident, practise reading the same exchange from two directions. A reporting application starts at the top, where it decides what result to send. Its host prepares information suitable for transport, routing and local delivery. The receiving host starts with the information that arrives on its link and works back upward. Each part makes a specific decision. You can observe that decision without seeing the entire conversation at once.
In this companion walkthrough, a training centre publishes one text file containing the words “Morning workshop” and a short greeting in Marathi. A client requests the file, receives it and displays the greeting. Later a second client receives the file but displays broken characters. A third client cannot connect at all. Keep these outcomes distinct. Good layer reasoning means you can give the next engineer a meaningful check for each client, even when all three reports originally said “the page has a problem.”
Follow the operating system's path when it matters and the model's terms when they help your explanation. Downward arrows describe how protocol information is added or data is prepared. Upward arrows describe interpretation and delivery to the next consumer. Real implementations can group operations or perform work in different places. For example, a virtual network interface behaves like a network attachment from the guest's perspective while the physical transmission is handled by underlying infrastructure. Your choice of observation point matters as much as the name of the layer.
Physical layer and the condition of the local medium
A bit is a logical zero or one. A communication medium carries physical changes used to represent information. Ethernet over copper uses electrical signalling, fibre uses light, and Wi-Fi uses radio. A radio link uses more than a simple blink for each bit; the physical standard defines how symbols and timing work. For the first layer, the practical question is whether the signal can be sent and received over the selected medium well enough for the data-link equipment to interpret it.
On a desk computer, check what the system actually reports for the relevant interface. A disconnected wired interface may report no carrier. A Wi-Fi device may be on another network or disconnected. Identifying a cable plugged into the wrong port can be useful when there is no link. If a browser page and other services work on the same interface, begin with the specific failing service rather than testing the cable as your only theory. An intermittent wireless issue can still appear later, so save the test time and interface evidence if several unrelated requests fail.
Connect this to the workshop clients. Client A downloads the file through Wi-Fi. Client B downloads it through Ethernet and sees broken characters. Networking carried enough data to show the file content on both. The difference reported by B concerns how bytes are displayed. Client C lost its local network connection and cannot reach several approved local services. Here the local link is a better starting point. The name of the layer should follow the evidence rather than determine it in advance.
On an EC2 instance, a guest operating system sees attached virtual network interfaces. Checking the name, state and address of an interface is useful. Seeing no literal cable in the console is normal. If the AWS network interface is missing or attached to a different subnet, compare your network configuration and the guest view. Do not invent a physical-cable diagnosis when your evidence is about a virtual attachment. You can still describe where the responsibility sits conceptually.
Data-link delivery and changing frames
A frame is a unit used for delivery on a particular data link. In an Ethernet example, the frame contains source and destination link addresses, information that indicates what it carries, the carried bytes and error detection information. The frame structure supports delivery on that local link. A physical representation conveys it across the medium. Different link technologies can carry related network-layer traffic while having different addressing and framing arrangements.
Use made-up link labels so you can focus on the path. Laptop A is on the same local link as gateway G, and the server is behind G on another link. The first frame is from A's local interface to G's local interface. The IP packet inside names the remote server. G receives the frame, examines the packet and can forward that packet within a new frame on its outgoing link. The two links can have different kinds of framing. The remote server does not need to receive a frame carrying the same local MAC addresses that appeared at A.
Draw a second case with a local printer on the same Ethernet segment. The workstation's route can classify that printer as on-link. In that case the workstation needs the printer's link information, rather than that of a remote gateway, for the first delivery. In a familiar IPv4 Ethernet arrangement, the host may use ARP and cache the result. IPv6 Neighbor Discovery uses a different protocol and includes more than address resolution. A route lookup and a neighbour lookup answer related but different questions.
An ordinary switch forwards Ethernet frames based on link addresses it learns and where it saw them. Imagine a classroom switch attached to workstation A, peer B and router G. After learning that B's link address appears on B's port, it can send suitable frames for B toward that port. A switch can also broadcast or flood certain traffic according to its behavior. Some equipment takes on network-layer routing as well. Identify whether the feature in question forwards a frame within a link or forwards an IP packet between networks.
When you examine a Linux ip addr result, the Ethernet link line can report an address such as 02:00:00:00:00:01. A line containing inet reports an IPv4 address and prefix. A corresponding inet6 describes IPv6. These values are not interchangeable. On an unfamiliar machine, several interfaces may have addresses. Identify the one chosen for the intended route before copying a random address into a troubleshooting report. Do not use another student's interface values as local lab inputs.
Network layer and packets across a route
The network layer carries packets across interconnected networks. A packet has an IP source and destination that relate to its forwarding. The destination helps each router select a path. Routers look at the address and configured routes, and select an outgoing interface and sometimes a next hop. A subnet prefix describes a set of addresses. In an IPv4 example, 192.0.2.0/24 groups all documentation addresses with the same first three octets. A more specific route such as 192.0.2.0/25 covers a smaller part of that range.
Work out a route decision on paper. In this sample, a router can send 192.0.2.0/24 through link East and 192.0.2.0/25 through link North. The address 192.0.2.40 matches both routes, so the more specific prefix takes priority when these are otherwise eligible alternatives. The address 192.0.2.180 is above the first half of the block, so the broader range through East is the relevant match. An unrelated address can match a configured default route if no more specific route applies. None of these choices creates a listening web service.
An IPv4 packet has a Time to Live field that limits forwarding; in ordinary operation a router decrements the value as part of forwarding. IPv6 uses a Hop Limit. This prevents a routing loop from forwarding a packet forever. In a classroom drawing with three routing hops, begin with a toy hop limit of four and mark how it changes at each forwarding step. The packets that reach the later link still carry the necessary IP address information, but the hop field is changed by routing. Do not confuse the hop field with the lifetime of cached DNS data, even though both use a term associated with lifetime.
ICMP provides network-layer control and diagnostic messages. A ping request can establish that a particular probe received a reply from its peer under the current policy. A missing reply can result from several factors, including packet handling or policy. It does not say whether TCP port 443 is open or the application can serve the workshop file. If a web page works when ping does not, you already have useful evidence about the TCP and HTTP path. Check ICMP separately only if its behavior matters to the assignment.
Network address translators deliberately change some address or port information while forwarding a flow. If you use a capture or log from behind a translator, say which side it came from. The destination that matters to the browser's request and the fields another device logs may be related by a mapping. This matters when correlating an external connection with an internal one. It does not make IP routing and port selection the same job. Mark both sets of values and the point where they changed.
Transport endpoints, TCP streams and UDP datagrams
At the transport layer the host needs a way to deliver data to a particular communication endpoint. A local program can ask the operating system to accept connections on a port. Other programs may use different ports or share an application endpoint through configured behavior. An outgoing client often chooses a temporary source port. The source and destination addresses, ports and protocol help identify which exchange a packet belongs to. When you write a test result, state the transport and port instead of saying only that an address responded.
TCP establishes state between peers. Its ordinary three-way handshake starts with a synchronisation message, then an acknowledgement and synchronisation response, then the initiating peer's acknowledgement. A listening process can accept the connection and start reading the ordered stream of bytes. The TCP specification defines checks, acknowledgement behavior, retransmission and ordered delivery while the connection functions. The program still needs to handle errors. A disconnected path, reset or exhausted retry can cause a TCP exchange to fail before the intended business action finishes.
Draw a toy byte exchange without inventing packet sizes for the real server. Put the text fragments “morning” and “classes” in adjacent sections of a sequence. The receiver tracks which bytes it has and which it still needs. If bytes corresponding to the first fragment were lost but a later section arrived, the application can wait for the missing bytes before reading the full prefix in order. Timing may change without altering the final text once recovery succeeds. The operating system or application does not receive a promise that every network attempt will finish.
TCP also regulates how much data peers send. A receiver has finite buffer space, and the path can be congested. Flow control helps avoid sending data faster than the peer can receive it. Congestion control adjusts use of the path under the relevant algorithms and conditions. These concerns can affect throughput while the connection still works. They explain why a timed web request might be slow even with a reachable IP and a working server. Diagnose speed using measurements before changing protocol settings.
UDP supplies datagrams, which carry a message boundary along with source and destination ports. It does not set up a TCP connection or give the application TCP's ordered byte stream. The program can decide whether one missing message can be ignored or whether to add recovery and sequencing. Streaming applications make different design choices depending on latency, quality and loss tolerance. A simple DNS request often uses UDP, while DNS also uses TCP and can be carried in other protocols. The DNS application goal stays a name lookup in all of those cases.
Comparisons of header sizes can be useful when they are precise. The basic UDP header is eight bytes. A TCP header without options is at least twenty bytes. Some connection behavior adds exchanges before application data. That does not make every UDP-based application faster than every TCP-based application. Network conditions and the protocol above the transport influence observed performance. QUIC uses UDP as its substrate and defines its own transport features such as reliable streams. An HTTP/3 browser uses that combined stack for an HTTP exchange.
Session responsibilities and the application's idea of a conversation
The OSI session layer names responsibilities for establishing and managing a conversation between communicating applications. Real web applications often use their application protocols, security libraries and local storage to achieve the behavior users call a session. A browser that remains signed in while navigating between course pages is keeping application context. For example, the server can associate a session identifier with a sign-in, and the browser can send a matching cookie with eligible requests. The browser could open another TCP connection while the login context continues.
Try reversing the conditions. The browser keeps a usable TCP connection to the schedule host, but the logged-in session has expired according to the application. The web server can accept the request and reply that the learner needs to sign in again. Reusing TCP does not keep identity valid by itself. Closing TCP also does not automatically end every authentication session. Use the proper application or server behavior to end the session. Record transport context and authentication context as two different observations.
The term session has more than one meaning in software. A TLS session or resumed connection describes state used by a security protocol, while an application session refers to work such as identifying a logged-in user. Some download mechanisms allow resuming at an offset, which is an application decision in ordinary HTTP. Each example shows a conversation concern, but they do not prove every implementation contains a separate OSI Layer 5 protocol. In notes, qualify the type, for example “the browser's login session expired” or “the TLS library resumed an earlier association.”
To investigate a session report, use an approved disposable account. Compare the same safe page request immediately after signing in and after intentionally ending the test session. Record the expected redirect or denial after logout. Keep session cookies and tokens out of the class report. A stable page and host help you isolate the changed application state. This test can reveal a real authorization difference without inspecting other users' traffic or changing an infrastructure firewall.
Represent the same text consistently
The presentation layer describes responsibilities for representing information so communicating programs can interpret it. A character encoding maps characters to bytes. A structured format defines how values such as rows and dates are represented. Compression changes the way data is encoded for efficient transfer. A program that parses a compressed response without handling the specified encoding can reject it even when the bytes arrived correctly. These examples explain the type of work captured by the model.
Go back to the workshop greeting. The training site saves the text in UTF-8. Someone reads the bytes as a different encoding and sees the wrong character. This is compatible with a fully working route and transport connection. You can check the response content type and its encoding information where present, then compare how your local tool reads the same bytes. This question is different from whether the intended file exists. Changing the browser's interpretation can change display without changing a single transport byte.
Encryption has its own purpose and does not fit one universal OSI layer number in real systems. In a common HTTPS deployment on TCP, TLS protects the communication between the client and a TLS endpoint. A reverse proxy may receive the client's encrypted connection, then open a separate exchange to a backend. In HTTP/3, QUIC integrates the TLS handshake into its transport. A VPN can apply protection at another place in the path. State what traffic is protected, who can read it and where protection ends instead of expecting one layer label to describe the range.
To describe a web troubleshooting observation, separate syntax from identity and privacy. A certificate validation problem concerns whether the HTTPS client accepts the peer. An unreadable JSON file can concern the payload's encoding or structure. An encrypted capture that hides the visible text can be entirely correct. These concerns depend on different evidence, even if a mnemonic teaches all of them near the presentation layer. Model names help start the conversation. Use protocol names and endpoints when making a precise claim.
Application messages and what an HTTP response proves
The application layer lets peers exchange service-specific messages. An HTTP client can request a resource or perform another operation expressed by a method and target. A DNS client can look up information using a name and record type. An SSH client can negotiate an authenticated protected session for authorised operations. Classify the protocol by the kind of message or service it provides. The browser program itself contains many responsibilities and cannot be assigned one layer as a physical component.
Follow the request GET /schedule.txt on the training site. The receiving service interprets the method and path. One response contains the file, and another path might return a missing-resource status. HTTP can also return a redirect, which gives the client another target to request. The client can display an error page while the HTTP exchange successfully reached a server and returned the response the protocol describes. Ask whether the problem is missing transport, a peer identity failure, or an application result before changing settings.
For a useful application trace, write down the expected responder and the actual responder as far as your evidence allows. An intermediary can return a response without contacting the backend. A cached copy can appear after the origin changed. A public load balancer can apply an HTTP rule that selected a different target group from the one you expected. Record the exact path, status, relevant harmless response fields and the request's time or marker. Ask the approved backend owner to correlate the server log where appropriate.
Several application protocols use the same transport capabilities. A known port such as 443 is a convention under the URL scheme and deployment, and there can be legitimate exceptions. Reading a port alone cannot tell you whether the payload contains HTTP, whether the destination would accept a browser certificate check, or whether packet contents are encrypted. Check what your own service is configured to speak on that listener. This is especially important when a router, proxy or load balancer sends a request toward a different backend port.
Calculate units in a simple, declared example
Use a simple paper example for header accounting. Suppose the application has twelve data bytes and writes them to an already established TCP exchange, with no encryption in this toy drawing. Assume one TCP segment with a header of twenty bytes and no options. Draw a thirty-two-byte segment with the data inside it. Then add a twenty-byte IPv4 header with no options. The fifty-two-byte result represents the IP packet in this drawing. The application writes twelve data bytes even though lower layers carry additional information.
Now put that packet in a plain Ethernet frame with an ordinary header and frame check sequence. Excluding any link preamble or inter-frame spacing, this example uses fourteen header bytes, fifty-two bytes of carried IP packet and four bytes for the frame check sequence. The seventy-byte total is an illustration under those assumptions. Other cases can have padding, tags, options or other link formats. Captures may omit some link details depending on the interface and tool. Do not assume a measured byte count is wrong until you know what the measurement includes.
The file size, port and packet sizes answer different questions. The original text might contain characters that use more than one byte in the encoding. One logical application message can span several transport segments, and a TCP receive operation may return only part of the available message. A sender might retransmit part of the exchange. An Ethernet frame on the second network link can be different from the frame at the first. Use the simple arithmetic to learn encapsulation, then state assumptions when comparing it with an actual capture.
Decapsulation follows the receiver's need to interpret its own protocol information before exposing the carried data. A local interface and network stack inspect the relevant frame and packet fields. The transport delivers appropriate data to an endpoint. The application applies the agreed representation and service semantics. A router on an intermediate network can make a forwarding decision without being the ultimate application reader. Mark which device terminates each protocol when drawing a complete path.
Follow a packet size limit across layers
A local link can carry a limited amount of network-layer data in one frame. The maximum transmission unit, or MTU, describes a size limit for a given interface or path context. Several links can appear between two endpoints. The largest IP packet a path can forward without needing fragmentation is constrained by the smallest suitable link along it. A client can connect and exchange short messages even if a larger transfer later runs into a path limit.
Work a classroom example with two differently configured Ethernet links. The first allows an IP packet of up to 1500 bytes and the second allows 1400 bytes of IP. Assume basic IPv4 and TCP headers of twenty bytes each for the classroom calculation. On the first link, 1500 leaves up to 1460 bytes for TCP data if those assumptions hold. The smaller limit on the second leaves 1360 bytes. The two limits can both be correct for their own links. If a protected tunnel adds headers, its interior traffic can have a different effective limit again.
Path MTU discovery uses relevant protocol signals and behavior to help an endpoint account for such limits. For IPv6, routers do not fragment the packets they are forwarding. The source needs to adapt when the path reports or otherwise reveals a size constraint. IPv4 fragmentation behavior depends on packet settings and forwarding conditions. The beginner lesson here is to record the observation and compare controlled sizes. Avoid changing the host's network configuration simply because a large request was once slow.
Suppose a lab correctly returns a short status line followed by a timeout during a larger response. A size problem is one hypothesis. Server load, backend delays and other failures are also possible. First verify the exact resource and method, compare a known small and large response under the same approved path, and inspect the observed timing. Ask the network operator for appropriate measurements if the size threshold is consistent. This is one example of why the layered model does not make the layers independent of performance and resource limits.
Name the endpoint responsible for the next action
Before you forward a problem report, sketch where each protocol terminates. A switch can forward a frame locally. A router can examine a packet and choose a next path. A TLS endpoint can verify authentication information and read its protected data. A backend application can inspect the method and requested resource. Several of these jobs can live on the same machine. A useful request for help names the next decision and the evidence you need, such as the backend’s request record when the front listener has already sent an HTTP error.
Local lab for bytes, streams and datagrams
Use Python 3 in a local Linux or macOS shell, or a Linux classroom environment on Windows. This exercise creates short-lived sockets only on 127.0.0.1. The operating system assigns unused ports. It needs no administrative access, internet routes or AWS resources. It does not capture packets from any other program. Read the steps first and predict which parts of the result measure representation and which parts measure transport.
Convert one character to bytes
Begin with one familiar accented letter, represented by its Unicode code point. Encoding it as UTF-8 produces bytes. Print the length as a Python string and as encoded bytes. Hexadecimal output is a readable way to show their values. A valid TCP or UDP exchange can carry those bytes, but the recipient still needs the right representation to interpret them as the intended letter.
python3 - <<'PY'
text = "\N{LATIN SMALL LETTER E WITH ACUTE}"
encoded = text.encode("utf-8")
print("characters:", len(text))
print("bytes:", len(encoded), encoded.hex())
print("correct decoding:", encoded.decode("utf-8") == text)
try:
encoded.decode("ascii")
except UnicodeDecodeError:
print("ASCII cannot decode this sample")
PY
Expect one character and two bytes, followed by the paired hexadecimal value c3a9. The equality after UTF-8 decoding should be true. The last line shows that a different interpretation can fail even while the bytes are unchanged. This is a representation problem that requires no network fault at all. If you see a syntax error about the quote marks, compare your pasted command with the example and ensure the shell did not replace the ordinary quotes.
Read a local TCP stream in short chunks
The next program sets up a local listener, then opens the client side and accepts it. Both socket objects are part of the same demonstration program. The sender writes two separate pieces and signals that it has finished sending. The receiver reads up to four bytes at a time until the stream ends. Read and compare the parts in order, then join them into one final value.
python3 - <<'PY'
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as listener:
listener.settimeout(2)
listener.bind(("127.0.0.1", 0))
listener.listen(1)
with socket.create_connection(listener.getsockname(), timeout=2) as client:
outgoing, _ = listener.accept()
with outgoing as peer:
peer.settimeout(2)
client.sendall(b"morning")
client.sendall(b"class")
client.shutdown(socket.SHUT_WR)
pieces = []
while True:
block = peer.recv(4)
if not block:
break
pieces.append(block)
print("read lengths:", [len(piece) for piece in pieces])
print("full stream:", b"".join(pieces).decode("ascii"))
PY
Expect the final text morningclass. The printed lengths can vary, while each is at most four and the combined length is twelve. The two original writes were lengths seven and five. Those lengths cannot describe the calls that read at most four bytes. The receiver uses the byte stream and a suitable ending signal in this simple demonstration. Real applications normally define how to identify a complete message, such as an explicit length or a delimiter, when more communication follows.
On this isolated machine, a failure before listen or connect points to lab environment or resource setup rather than a remote router. After accept, a reader timeout can mean it is waiting for more data or the ending signal. Check the close or shutdown sequence before increasing timeouts. Do not use an unbounded loop or a public bind to hide the problem. The small time limits are intended to make a failed fixture stop predictably.
Compare two UDP messages
Use a datagram socket on the same host. Each send supplies one message, and each successful receive returns one available datagram for this exercise. The buffer is large enough to read either small message intact. The program waits for at most two seconds per receive, so the test also shows that UDP may leave an application to decide what to do when no datagram appears.
python3 - <<'PY'
import socket
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as destination:
destination.bind(("127.0.0.1", 0))
destination.settimeout(2)
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sender:
for message in (b"morning", b"class"):
sender.sendto(message, destination.getsockname())
received = [destination.recvfrom(64)[0] for _ in range(2)]
print("message lengths:", sorted(map(len, received)))
print("messages:", sorted(value.decode("ascii") for value in received))
PY
When both messages arrive, the output shows message lengths five and seven. It keeps the input message boundaries. The sorted display avoids treating observed ordering on this small local run as a protocol guarantee. Compare with TCP's read lengths and final assembled sequence. Receiving both UDP datagrams on one host is evidence for this run only. It does not promise delivery on a wider network or demonstrate congestion, loss or retransmission behavior.
All three programs close their sockets automatically on completion and leave no files. If a run stalls while experimenting, Ctrl+C exits the sample and its loopback sockets close with the process. Save one line explaining the prediction, one line of observed output and one line about the limitation. You have examined representation and transport locally. You have not measured an Ethernet frame crossing a wire, a router's decision or a cloud load balancer.
Explain three workshop incidents
Read the first incident as two independent tests. The Windows browser shows replacement symbols in the workshop greeting. A second authorised client obtains the same bytes and displays the greeting correctly. Ask for the declared content type and encoding plus a harmless sample that reproduces the display difference. If the encoding declared by the service disagrees with the bytes it sends, correct that response in the lab and compare the display again. There is no useful reason to open a port for a browser that already downloaded the full sample file.
In the second incident, a TCP test to the authorised service address succeeds, but the expected encrypted web request fails before an HTTP status appears. Ask which name the client uses and where TLS terminates. Compare host name and certificate validity through the approved configuration. If a proxy can end the connection and begin another, describe where the error is observed. The lower layer check has ruled in a usable transport connection, but the application is still waiting for a peer it accepts.
In the third incident, the user on the same Wi-Fi as a working test client cannot reach any of the assigned lab destinations. Start from this user's local connection, IP configuration and route. Compare one known destination with the successful learner's observations while respecting the network rules. The user might have selected a guest network, obtained a different default route or encountered a local issue. Record which result you verify rather than using a device label to guess how the path behaves.
Explain the boundary you are testing
Which headers can change when the router moves an IP packet to another link?
The new link can have different source and destination link addresses and its own framing. At the IP layer the router can change forwarding-related fields such as hop count or lifetime. The destination IP normally continues to describe the original network destination unless there is a deliberate transformation such as address translation. The Ethernet example helps explain why the remote server's MAC address need not appear on a client's local link.
Does TCP deliver each call to send as a separately readable message?
TCP delivers an ordered byte stream while communication succeeds. A reader can get a shorter read or receive bytes from successive writes together. The application decides how to recognise a complete message. Our lab reads at most four bytes while the sender writes seven and five, so the same total sequence is read with different boundaries.
What does HTTPS add to the HTTP exchange?
HTTPS indicates an HTTP exchange through a protected connection. The client checks conditions such as acceptable peer identity and establishes cryptographic protection with its endpoint. Some implementations run TLS over TCP. HTTP/3 uses QUIC with TLS 1.3 integrated into the security establishment. A diagram that marks the TLS endpoints and names both protocols communicates more than one fixed layer label.
Is 404 a symptom of a UDP failure?
404 is an HTTP response. It tells us a responder interpreted the request and reported that the resource was unavailable under that request. We still need to verify whether the responder was the expected origin or an intermediary. If a lower-level failure prevented the browser from receiving any HTTP response, the client would have different evidence.
Quiz and prediction
Your local program prints one character and two encoded bytes. Which concern explains the difference: character representation, an IP address translation, or changing the transport port?
Check your answer
Character representation. A Unicode character can take multiple bytes in UTF-8. The same bytes can cross different transports without changing the representation intentionally chosen by the application.
A client on a local Ethernet link sends an IP packet toward a remote server through its router. Where is the remote destination represented on the first hop?
Check your answer
The IP packet identifies the remote destination. The frame has the local next hop as its link destination. This makes it possible for two different local links to carry packets for the same end-to-end IP exchange.
One experiment sends two pieces over TCP and receives three short reads. Should you preserve the reads as the original three application records, accumulate bytes according to an application message format, or change the server's DNS record?
Check your answer
Accumulate and interpret bytes using the application message format. Reading a stream does not preserve calls to write. The three pieces can be convenient for local buffering without being the application’s intended records.
Revision cards
Signal and frame
A medium carries a physical representation. A data link interprets frame information for local delivery. Trace what each node can see on its attached link.
Packet and port
IP forwarding selects a next path. Transport ports identify communication endpoints. Preserve the address and port together in a test record.
Stream and datagram
TCP exposes an ordered stream and hides write boundaries. UDP preserves a datagram boundary on receive when the message arrives. Successful delivery properties differ.
Conversation and representation
Ask whether the problem is continued application state, byte interpretation or protection. Use the actual protocol and endpoint to describe the cause.
Primary references
- ITU X.200 Open Systems Interconnection model and RFC 1122 Internet host communication layers
- RFC 826 address resolution, RFC 894 IP datagrams on Ethernet and RFC 4861 IPv6 Neighbor Discovery
- RFC 791 IPv4 header and RFC 8200 IPv6 header
- RFC 1191 IPv4 path MTU discovery and RFC 8201 IPv6 path MTU discovery
- RFC 9293 TCP, RFC 768 UDP and RFC 9000 QUIC
- RFC 3629 UTF-8, RFC 6265 HTTP state management and RFC 9001 TLS in QUIC
- RFC 9110 HTTP semantics, Python socket module and Amazon EC2 network interfaces