Differences

Compared

TCP vs UDP

TCP sets up a connection and delivers every byte in order, resending what is lost. UDP sends separate datagrams with no connection, no acknowledgement and no resend. Use TCP when every byte must arrive, and UDP when a late packet is worth less than a lost one.

Side by side

TCPUDP
Connection Opens with a three-way handshake (SYN, SYN-ACK, ACK) and closes with FINsNone: each datagram stands alone
Delivery Every byte is numbered, acknowledged, resent when lost and delivered in orderNo acknowledgement, no resend, no ordering: success only means the datagram left
Speed control The receiver's window and congestion control slow the sender downNone: the program sets its own pace
Header 20 bytes at least8 bytes
A closed port answers With a TCP resetWith ICMP port unreachable, if at all
Used by HTTP/1.1 and HTTP/2, SSH, SMTP, BGPDNS, DHCP, NTP, VoIP, WireGuard, QUIC (HTTP/3)

Each one explained

TCP
Reliable, ordered byte streams between programs: handshake, acknowledgements, retransmission.
UDP
Independent datagrams with ports and nothing else: no connection, no acknowledgement, no retries.
Three-way handshake
SYN, SYN-ACK, ACK: how TCP opens a connection, each side agreeing on starting sequence numbers.
Port
A 16-bit number that picks the program on a device: web 80 and 443, DNS 53, SSH 22.

See the difference on real machines

Each lab is a small network of real Linux machines in your browser.

Open TCP: how a file survives a bad line

Sources

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab