TCP vs UDP: the transport layer explained, with the exam angle

TCP vs UDP explained: the transport layer's job, connection-oriented vs connectionless, reliability, congestion control, headers, and when to use each.

Prashant Jain

KnowledgeGate AI educator

10 Jul 20265 min read

The transport layer is the layer that turns host-to-host delivery into process-to-process delivery, so the right data reaches the right application on the right machine. Two protocols share this job and make opposite trade-offs: TCP buys reliability at the cost of overhead, and UDP buys speed at the cost of guarantees. Knowing exactly where each fits is one of the most reliably tested ideas in Computer Networks.

Let us build it up from what the layer is actually responsible for.

What the transport layer does

The network layer, using IP, gets a packet from one host to another. It does not know or care which program on that host should receive it. The transport layer closes that gap with four responsibilities:

  • Multiplexing and demultiplexing using port numbers. A port identifies a process, so a browser on port-something and an email client can share one IP address without their data getting mixed up.

  • Segmentation and reassembly of the application's byte stream into transport units.

  • Error detection through a checksum.

  • Optionally, reliability, ordering, flow control, and congestion control, which is exactly the set of features that separates TCP from UDP.

An address at this layer is really a pair: the IP address picks the host, the port picks the process.

TCP: connection-oriented and reliable

TCP (Transmission Control Protocol) is connection-oriented. Before any data flows, the two ends establish a connection with a three-way handshake (SYN, then SYN-ACK, then ACK). Only then does data move, and at the end the connection is torn down cleanly. On top of that connection TCP layers four guarantees:

  • Reliability. Every byte is acknowledged. If an acknowledgement does not arrive within a timeout, the sender retransmits, so lost data is recovered automatically.

  • In-order delivery. Each byte carries a sequence number, so the receiver reassembles the stream in the exact order it was sent even if packets arrive scrambled.

  • Flow control. A sliding window advertised by the receiver stops a fast sender from overwhelming a slow receiver's buffer.

  • Congestion control. Algorithms such as slow start and congestion avoidance make TCP back off when the network is congested, protecting the whole path, not just the receiver.

All of this costs round trips, state, and header bytes, but it means the application receives a clean, complete, ordered byte stream.

UDP: connectionless and lightweight

UDP (User Datagram Protocol) is connectionless. There is no handshake, no sequence numbers, no acknowledgements, and no congestion control. A UDP sender simply wraps the data in a datagram and sends it. If it is lost, duplicated, or reordered, UDP does not notice or care; recovery, if any, is the application's problem.

That sounds worse until you remember the payoff: almost no overhead and no waiting. For a live voice call, a packet that arrives late is useless anyway, so retransmitting it would only add delay. UDP is the right tool precisely when speed and low latency matter more than perfect delivery.

The segment headers at a concept level

The header sizes tell the whole story. A TCP header is at least 20 bytes and carries source and destination ports, a 32-bit sequence number, a 32-bit acknowledgement number, control flags (SYN, ACK, FIN, RST, PSH, URG), a receive-window size for flow control, and a checksum. Every one of those fields exists to support a guarantee.

A UDP header is just 8 bytes: source port, destination port, length, and checksum. That is all it needs, because it makes no promises. The header comparison is itself an exam favourite: TCP's fat header is the price of reliability, UDP's thin header is the reward for going without.

TCP vs UDP at a glance

Feature

TCP

UDP

Connection

Connection-oriented (handshake)

Connectionless

Reliability

Guaranteed, with retransmission

Best-effort, no guarantee

Ordering

In-order via sequence numbers

No ordering

Flow control

Yes, sliding window

No

Congestion control

Yes

No

Header size

20 bytes minimum

8 bytes

Speed and overhead

Slower, more overhead

Faster, minimal overhead

Typical use

Web, email, file transfer

DNS, VoIP, streaming, gaming

When each is used

Reach for TCP whenever correctness beats speed: web pages over HTTP and HTTPS, email (SMTP), and file transfer all demand that every byte arrive intact and in order. Reach for UDP whenever timeliness beats completeness: DNS lookups (one small quick query), voice and video calls, live streaming, online gaming, and DHCP. The one-line rule examiners want: TCP when you cannot afford to lose data, UDP when you cannot afford to wait.

TCP and UDP questions in GATE, UGC NET and placements

GATE CS tests this both conceptually and numerically. Expect header-field questions, three-way-handshake sequencing, sliding-window and throughput numericals, and direct TCP-versus-UDP comparisons. The transport layer sits on top of the addressing covered in IP addressing and subnetting, and our GATE CS exam category sequences the two together.

UGC NET Computer Science favours the comparison table and definitions: connection-oriented versus connectionless, which protocol carries DNS, what each header field means. Crisp recall scores.

Placement and company tests ask the applied version, "difference between TCP and UDP", "why does video streaming use UDP", and "walk me through the three-way handshake". These are near-guaranteed in networking rounds.

KnowledgeGate's published question bank carries over two thousand Computer Networks questions, and the transport layer is one of its densest sub-areas, so there is ample drill on exactly these patterns.

Practise it, do not just read it

The comparison sticks once you can justify every row of that table from first principles.

Learn the four transport-layer jobs, read the two headers as a story about guarantees, and be able to place any application on the TCP or UDP side and say why. Do that, and this comparison becomes marks you can count on.

Ready to test yourself? Work through our solved TCP and UDP transport layer MCQs, each answered in a couple of lines, to see exactly how these ideas are examined.