E ExamMaster

AWS Cloud Architect & Developer · Computer Networks

Layers and How a Connection Opens

OSI versus TCP/IP layering, TCP versus UDP, the three-way open and four-way close, and the header bytes that name ports.

Stay with Meera's phone fetching one URL: https://shop.rao.example/tea. This lesson is the stack that tap becomes — layers, TCP versus UDP, the three-segment open, the four-segment close, and the header bytes that name the ports. Flow and congestion — how fast those bytes may move after the connection exists — are the next lesson.

  • AWS Cloud Architect & Developer
  • Medium level
  • 6 concepts
  • 5 practice questions

1OSI and TCP/IP layering

Meera taps https://shop.rao.example/tea on her phone. That tap is not one blob on the wire. The phone builds a stack of wrappers: the HTTP request (what page she wants), a TCP segment (how those bytes will be delivered in order), an IP packet (which machine should receive them), and a Wi-Fi frame (this hop to the home router). Each wrapper is a layer — a job with its own header, the extra bytes in front that the next machine will read.

Two naming systems describe the same stack. OSI names seven jobs top-down: Application, Presentation, Session, Transport, Network, Data Link, Physical. The Internet's TCP/IP model folds those jobs into four: Application, Transport, Internet, and Link. HTTP sits at Application; TCP at Transport; IP at Internet; Wi-Fi at Link. When someone asks which layer TCP belongs to, they mean that Transport job — OSI number 4, or the TCP/IP name Transport. Same job, two labels.

Figure. OSI's seven names collapse into TCP/IP's four jobs — exam 'which layer?' usually means OSI numbering.

OSI to TCP/IP mapping
OSI layersTCP/IP layerExamples
7 Application, 6 Presentation, 5 SessionApplicationHTTP, DNS, TLS presentation jobs
4 TransportTransportTCP, UDP
3 NetworkInternetIP, ICMP, routing
2 Data Link, 1 PhysicalLinkEthernet, Wi-Fi, framing, bits on wire
In the four-layer TCP/IP model, TCP belongs at which layer?
  1. Internet
  2. Transport
  3. Link

TCP (and UDP) are transport protocols. Internet is IP/routing; Link is framing and the physical hop.

2TCP versus UDP

The tea page must arrive complete and in order. A missing byte would break the HTML. That is why the phone uses TCP: a connection-oriented transport. Connection-oriented means the two ends agree they are talking before data moves. TCP then numbers bytes, waits for acknowledgements (short 'I got that' messages), and resends what was lost.

UDP is the other transport: connectionless. Each UDP datagram — one self-contained message — stands alone. Nothing resends it. Nothing puts late pieces back in order. Use TCP when every byte matters (the web page, mail, a file). Use UDP when a late packet is worthless (a live voice sample, a game tick) or when the app will retry itself (a DNS name lookup). UDP's header is 8 bytes; TCP's is at least 20. That size gap is the concrete cost of reliability.

Figure. TCP buys reliability and ordering with a connection; UDP ships datagrams with minimal overhead.

How to pick the transport

  1. Must every byte arrive in order?If yes, TCP's reliability and sequencing are the default.
  2. Is a late packet useless?If yes — live media, games — UDP avoids retransmission delay.
  3. Header costUDP's 8-byte header is the low-overhead cue when the payload is already tiny.
TCP vs UDP
PropertyTCPUDP
ConnectionConnection-orientedConnectionless
Reliability / orderReliable, orderedBest-effort, no order
ControlsFlow + congestionNeither built-in
Min header20 bytes8 bytes
Typical useHTTP, email, filesDNS, video, VoIP, games
Live video can drop occasional frames but must stay low-latency. Which transport fits?
  1. TCP, because retransmission fills every gap
  2. UDP, because it avoids retransmission delay
  3. Neither — video must use raw IP

TCP retransmissions add delay that hurts real-time media. UDP is connectionless and low-overhead; the application tolerates some loss.

3Three-way handshake

Before any tea-page byte moves, TCP opens a connection with three segments. A segment is one TCP message. SYN means 'I want to start, and here is my starting byte number' — that number is the initial sequence number, ISN. The shop replies SYN-ACK: 'I also want to start, here is my ISN, and I heard yours.' The phone sends ACK: 'I heard yours.' After those three, both sides have agreed on sequence numbers. Data can flow.

The count is three segments to establish, not two and not four. Four is how a graceful close works, later. UDP has no handshake to count — that is what connectionless means.

Figure. Three-way handshake: client SYN, server SYN-ACK, client ACK — three segments to establish.

How the handshake runs

  1. SYNClient → server: propose connection and client ISN.
  2. SYN-ACKServer → client: accept, send server ISN, acknowledge client ISN.
  3. ACKClient → server: acknowledge server ISN; connection is established.
How many segments are exchanged to establish a TCP connection?
  1. 2
  2. 3
  3. 4

The three-way handshake is SYN, SYN-ACK, ACK — three segments. Four is the graceful close count, not the open.

4Four-way teardown

When Meera leaves the page, each direction of the byte stream shuts on its own. TCP is full-duplex: phone-to-shop and shop-to-phone are two one-way pipes sharing one connection. One side sends FIN ('I am done sending'); the other ACKs that direction. Later the other side sends its own FIN; the first ACKs. Two FIN/ACK pairs — four segments.

A single FIN does not close both pipes. That is why graceful teardown is four segments while the open was three. An RST is a different, abrupt reset, not this graceful close.

Figure. Each side closes its direction with FIN; each FIN is ACKed — four segments when close is independent each way.

How a graceful close runs

  1. FIN + ACKActive closer sends FIN; peer ACKs that direction.
  2. Other FIN + ACKPeer later sends its FIN; active closer ACKs.
  3. CountFour segments total for graceful close; remember setup was three.
Graceful TCP connection teardown exchanges how many segments?
  1. 3 (same as the handshake)
  2. 4 (two FIN/ACK pairs)
  3. 1 (a single FIN closes both directions)

Each direction needs its own FIN and ACK, so graceful close is four segments. The open is three; a single FIN does not shut both directions.

5TCP and UDP header sizes

A header is the extra bytes in front of the payload. The tea HTML is the payload; the header names the ports and options. A port is a number on one machine that says which program should receive the bytes: 443 for this HTTPS page, 53 for a DNS lookup. UDP's header is a fixed 8 bytes: source port, destination port, length, checksum. TCP's header is at least 20 bytes and grows when options (timestamps, window scale) are present.

That is why people say UDP is low-overhead: every datagram pays 8 bytes of tax; every TCP segment pays at least 20 before the first payload byte.

Figure. UDP's 8-byte header is the overhead story; TCP and IPv4 start at 20 bytes each before options.

Minimum headers
ProtocolMinimum headerNotes
UDP8 bytesFixed; no options field
TCP20 bytesGrows with options
Minimum header sizes for UDP and TCP are
  1. 20 bytes and 8 bytes
  2. 8 bytes and 20 bytes
  3. 8 bytes and 8 bytes

UDP is fixed at 8 bytes; TCP is at least 20 bytes before options.

6When the phone picks TCP or UDP

Meera's phone already made two transport choices for one tap. The name lookup for shop.rao.example is a tiny question that can be asked again if it fails — UDP. The tea page itself must be complete — TCP. The words that decide are about the job: if loss is unacceptable, pick TCP; if a late packet is useless, pick UDP.

Do not mix this choice with the three-way open or four-way close counts. Those counts describe TCP's life cycle. UDP has no handshake to count.

Read the stem for reliability, ordering, and connection setup. Words like reliable byte stream or handshake point to TCP; fire-and-forget datagram or streaming media without setup point to UDP. The cue table is the artefact — no diagram adds a third protocol.

How to read the stem

  1. Reliability wordsIf loss is unacceptable, pick TCP.
  2. Latency wordsIf late data is useless, pick UDP.
  3. Don't mix counts3-way open / 4-way close answer lifecycle questions, not "which protocol".
Stem cue → protocol
CuePick
File transfer, web, email, ordered bytesTCP
Live video, VoIP, gamingUDP
DNS query/responseUDP (typical)
Needs congestion + flow control built-inTCP
A name lookup sends one small request and needs a fast reply; the app will retry on timeout. Best default transport?
  1. TCP with a three-way handshake every time
  2. UDP
  3. TCP teardown only, no handshake

DNS-style short request/response wants low overhead; UDP is the usual choice, with the application retrying. Forcing a TCP handshake on every tiny lookup is the cost UDP avoids.

Notes

  • OSI has 7 layers (Physical, Data Link, Network, Transport, Session, Presentation, Application); TCP/IP condenses these into 4-5 layers.
  • TCP is connection-oriented, reliable, ordered, with flow and congestion control; UDP is connectionless, unreliable, but low-overhead and fast.
  • TCP establishes a connection with a 3-way handshake (SYN, SYN-ACK, ACK) and closes with a 4-way handshake using FIN/ACK.
  • Flow control uses a sliding window (receiver-driven) to avoid overwhelming the receiver; congestion control (slow start, AIMD) reacts to network load.
  • TCP congestion control: slow start grows the window exponentially until the threshold, then congestion avoidance grows it linearly (additive increase).

Formulas

  • OSI = 7 layers; TCP/IP model = 4 layers (Link, Internet, Transport, Application).
  • TCP header = 20 bytes minimum; UDP header = 8 bytes fixed.
  • 3-way handshake sequence: SYN -> SYN+ACK -> ACK.
  • Throughput (sliding window) \approx window size / RTT.
  • AIMD: on ACK increase cwnd by 1 MSS per RTT; on loss set cwnd to half (multiplicative decrease).

Exam traps & shortcuts

  • OSI layer mnemonic (top-down): 'All People Seem To Need Data Processing' (Application...Physical).
  • TCP = reliable/ordered (file transfer, web); UDP = fast/no guarantees (video, DNS, gaming).
  • Connection setup is 3-way (SYN, SYN-ACK, ACK); teardown is 4-way (two FIN/ACK pairs).

Reference tables

Lifecycle segment counts
PhaseSegmentsFlags
Establish3SYN, SYN-ACK, ACK
Graceful close4FIN/ACK, FIN/ACK

Recap

After the tap, these are the wrappers and the TCP life cycle.

Layers
HTTP / TCP / IP / Wi-Fi is Application / Transport / Internet / Link. OSI names seven jobs; TCP/IP folds them to four.
TCP vs UDP
Tea page wants every byte: TCP. A name lookup that can retry: UDP. Late voice is worthless: UDP.
Open / close
Open = 3 segments (SYN, SYN-ACK, ACK). Graceful close = 4 (two FIN/ACK pairs), because each direction shuts alone.
Headers
A header is bytes in front of the payload. UDP 8 B fixed; TCP at least 20 B. A port is the door (443, 53), not a layer number.

Practise Layers and How a Connection Opens

Reading is free and needs no account. Practice, mocks and progress live in the app.

  • 5 exam-style questions on this topic, with explanations
  • A 3-question practice set that ends the chapter
  • Timed mocks scored with the real marking scheme
  • Readiness tracked per topic, kept on your device
Continue with Google — freeNo card, no trial. Works offline once installed.