edubun
English

TCP, UDP and ports

A port number is 16 bits, so it runs from 0 to 65535. Web servers using HTTPS listen on port 443.

Two puzzles first. In a video call, one small piece of your friend's voice goes missing on the way. Should your app ask for it again? Now you are downloading a homework file, and one piece of the file goes missing. Same question. Decide both before reading on.

Two missing pieces, two different answers

If you said no for the call and yes for the file, you have already chosen between the two transports. A piece of sound that arrives half a second late is useless. The conversation has moved on, so it is better to skip that piece and play the next one. A file with one piece missing is broken, so that piece is worth waiting for. The internet has a transport for each case: TCP waits and resends, UDP sends and moves on. Before either can help, though, a packet has to reach the right program.

Which program gets the packet: ports

An IP address gets a packet to the right computer. But one computer runs many programs at once: a browser with several tabs, a chat app, a music app. Both TCP and UDP headers carry a source port and a destination port, each a 16-bit number from 0 to 65535, and the port says which program a packet is for. A server program listens on an agreed port: 80 for plain HTTP, 443 for HTTPS, 53 for DNS, 25 for mail between servers. RFC 6335 splits the range into system ports 0 to 1023, user ports 1024 to 49151 and dynamic ports 49152 to 65535. Your computer picks a temporary source port for each conversation, often from the dynamic range. An address and a port together, such as 198.51.100.20:443, name one end of a conversation exactly.

TCP checks off every byte

TCP (RFC 9293) turns an unreliable stream of packets into something like a phone line for bytes. First the two sides set up a connection with a three-way handshake: the client sends SYN, the server answers SYN-ACK, and the client replies ACK. From then on every byte has a sequence number. The receiver sends acknowledgements (ACKs) saying how far it has got, and puts out-of-order pieces back in place. If the sender hears no ACK within a timeout, it sends the data again. RFC 6298 sets the first timeout at 1 second and then adjusts it to the measured round-trip time. TCP also slows down when it sees loss, so one busy link is not flooded.

UDP sends and moves on

UDP (RFC 768, 1980) does much less. Its header is only 8 bytes: two ports, a length and a checksum. There is no handshake, no sequence number and no resending. For the video call in the first puzzle, that is exactly right. Short DNS questions use UDP too, because one question and one answer are quicker without a handshake. QUIC, the transport under HTTP/3, runs on UDP and builds its own resending on top.

Loading

Drag to turn. Scroll or pinch to zoom.

Loss is set to 25%. With TCP, green ACKs come back for each packet; when one is missing, the laptop waits for the timeout and sends that packet again (purple), so the server always ends with the whole message. Switch to UDP and send again: lost packets leave dots in the message. In this model ACKs are never lost and every packet gets its own ACK; real TCP sends cumulative ACKs.

Four numbers keep two tabs apart

Four numbers together identify one TCP connection: source address, source port, destination address and destination port. That is how a server on port 443 can talk to thousands of browsers at once without mixing them up, and how your laptop keeps two tabs on the same site apart, because each tab's connection uses a different source port. Tap a packet in the simulator and read its header. Before the home router the source is 192.168.0.12 port 51000. After it, NAT has changed both numbers, and the router remembers the swap so replies go back to the right tab.

TCPUDP
Set-upThree-way handshakeNone
Lost dataResent after a timeoutStays lost
OrderRestored by sequence numbersNot guaranteed
Header20 bytes or more8 bytes
Typical usesWeb pages, email, file downloadsDNS questions, voice and video calls, games, QUIC
Port 443HTTPS
Port 80HTTP without encryption
Port 53DNS
Port 25Email between mail servers (SMTP)
SYN, SYN-ACK, ACKTCP three-way handshake
ACKAcknowledgement: "I have received up to here"
  1. What is the largest port number?
  2. Which port does a web server use for HTTPS?
  3. Which port does DNS use?
  4. Your browser uses source port 50000. Which RFC 6335 range is that?
    • Dynamic (49152 to 65535)
    • System (0 to 1023)
    • User (1024 to 49151)
    • Not a valid port
  5. Put the TCP handshake in order.
  6. How many bytes long is a UDP header?
  7. Before any round trip has been measured, what first retransmission timeout does RFC 6298 set?
  8. With 25% loss, what does TCP do about a missing packet?
    • Sends it again after the timeout
    • Skips it
    • Sends the whole message again from the start
    • Closes the connection at once
  9. Why do video calls often use UDP?
    • Sound that arrives late is useless, so waiting for a resend does not help
    • UDP encrypts the call
    • UDP never loses packets
    • TCP cannot carry sound
  10. How many different port numbers are there?
Common mistakes
  • "UDP is a broken version of TCP that loses data." UDP is chosen on purpose when late data is useless or one question and one answer are enough, as in calls, games and DNS. QUIC even builds its own reliability on top of it.
  • "A port is a socket on the back of the computer." The word is shared, but a TCP or UDP port is a 16-bit number in the packet header, from 0 to 65535. It names a program, not a plug.
  • "When one packet is lost, TCP sends the whole file again." Only the missing data is sent again after the timeout. The sequence numbers and ACKs show which part has not been acknowledged; the receiver already has the rest.
Teacher's noteAsk the two puzzle questions before you say TCP or UDP. Once learners have decided for themselves that a late piece of sound is worthless, the two names become labels for a choice they already made. The handshake sticks when three people act it out: one at each end, and one in the middle carrying cards marked SYN, SYN-ACK and ACK. Where they get stuck is the four numbers that name a connection. Write the connections of two tabs side by side and let them spot that only the source port differs.
Key points
  • Ports (16 bits, 0 to 65535) pick the program: 80 HTTP, 443 HTTPS, 53 DNS.
  • TCP: handshake (SYN, SYN-ACK, ACK), sequence numbers, ACKs, resend after timeout.
  • UDP: 8-byte header, no handshake, no resend; good when late data is useless.
  • QUIC (HTTP/3) runs over UDP and adds its own reliability.
Sources for this course (28)
  • (checked 2026-10-17; reordered 2026-10-19: standards first, then official documentation, then operators and papers, history sources last)
  • IETF RFCs (rfc-editor.org): RFC 768 UDP (1980, 8-byte header)
  • RFC 791 IPv4 (1981, 32-bit addresses, "does not provide a reliable communication facility", TTL field "measured in units of seconds" but every module must decrease it by at least one, so it is only an upper bound)
  • RFC 792 ICMP (Time Exceeded)
  • RFC 801 NCP/TCP transition plan (1 January 1983)
  • RFC 894 Ethernet (1500-byte payload)
  • RFC 1034 and RFC 1035 DNS (1987, HOSTS.TXT kept by SRI-NIC, labels up to 63 octets and names up to 255, TTL in seconds)
  • RFC 1122 (127.0.0.0/8 loopback)
  • RFC 1918 private addresses (10/8, 172.16/12, 192.168/16)
  • RFC 2131 DHCP, RFC 3022 NAT, RFC 3596 AAAA records, RFC 3849 and RFC 5737 documentation addresses, RFC 4271 BGP-4, RFC 4291 IPv6 text form, RFC 6298 TCP retransmission timer (initial RTO 1 second)
  • RFC 6335 port ranges (0-1023, 1024-49151, 49152-65535)
  • RFC 7766 DNS over TCP, RFC 8200 IPv6 (128-bit addresses, Hop Limit)
  • RFC 8446 TLS 1.3 (one round-trip handshake)
  • RFC 9000 QUIC and RFC 9114 HTTP/3, RFC 9110 HTTP semantics (status code classes)
  • RFC 9293 TCP (three-way handshake, sequence numbers)
  • IANA: ip-parameters registry (recommended default TTL 64)
  • IPv4 free pool depleted 3 February 2011 (NRO and ARIN announcements)
  • Official documentation: MDN Web Docs "How does the Internet work?" (45 cables for 10 computers, switches, routers, MAC and IP addresses, internet and web)
  • "What is a URL?", "HTTP response status codes" (developer.mozilla.org)
  • Cloudflare Learning Center: "What is DNS?" (four kinds of DNS server, 8 steps of an uncached lookup, browser and OS caches, TTL)
  • "What is HTTP/3?" (cloudflare.com/learning)
  • Google Chrome Help, "Browse in Incognito mode" (support.google.com/chrome/answer/95464, checked 2026-10-19: Incognito limits what is saved to the device; websites and organisations that manage your network, like your school, employer or internet service provider, may be able to observe your activity)
  • Operators and papers: root-servers.org (13 root name servers run by 12 organisations, 2047 instances on 2026-10-17)
  • Jacobson and Karels 1988, Congestion Avoidance and Control (loss mostly congestion)
  • History blocks only: UCLA Samueli School of Engineering, Internet50 (first ARPANET message "LO", UCLA to SRI, 29 October 1969, 22:30)
  • historyofinformation.com and Wikipedia ARPANET (Kline)
  • Spiceworks/SRI history (HOSTS.TXT kept by SRI-NIC)
  • Numbers (2^32, 2^96, 45 and 6 cables, packet counts, round-trip times)

Checked: 2026-10-17