Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Networking 2: TCP, UDP and Ports

    UDP: Fast Postcards, No Guarantees

    A postcard: you write it, drop it in the box, done. No envelope, no tracking, no confirmation. Usually

    Chapter 3 of 122 min read

    The Plain Picture#

    A postcard: you write it, drop it in the box, done. No envelope, no tracking, no confirmation. Usually it arrives. Sometimes it doesn't, or two sent days apart arrive in the wrong order. Nobody tells you.

    It's cheap and instant, which is perfect for a quick "wish you were here". It's terrible for sending a contract.

    The Real Name#

    UDP (User Datagram Protocol) is a transport protocol that adds just ports (and a checksum to detect corrupted data) on top of IP. Each message is a datagram. No connection, no delivery guarantee, no ordering, no slowing down.

    The UDP header is only 8 bytes:

      ┌──────────────┬──────────────────┐
      │ source port  │ destination port │
      │ length       │ checksum         │
      └──────────────┴──────────────────┘

    Under the Hood#

    When "no guarantees" is exactly right:

    UseWhy UDP fits
    DNS lookupsone small question, one small answer; if lost, just ask again
    Video calls, voicea late packet is useless — better to skip it than wait for a resend
    Online gamesonly the latest position matters
    Streaming metricslosing a few samples is fine; speed matters
    QUIC / HTTP/3builds its own reliability on top of UDP (Ch 9)

    Any reliability a UDP application needs, it must build itself.

    Check yourself

    3 questions
    1

    What does UDP add on top of IP?

    Show answer

    Ports and a checksum — almost nothing else.

    2

    Why do video calls prefer UDP?

    Show answer

    A late (resent) audio or video packet is useless; skipping it is better than waiting.

    3

    Is a UDP datagram guaranteed to arrive? In order?

    Show answer

    Neither.