Networking basics, What is TCP vs UDP

TCP and UDP are the two primary transport layer protocols used in IP networking. They determine how data is transmitted between devices. This tutorial compares Transmission Control Protocol (TCP) and User Datagram Protocol (UDP), explaining their differences and when to use each.

Step 1: What is TCP?

TCP is a connection-oriented protocol that ensures reliable and ordered delivery of data. It is like sending a certified letter — the sender and receiver both keep track of delivery.

  • Features:
    • Reliable (guaranteed delivery)
    • Ordered (data arrives in sequence)
    • Error checking and correction
    • Slower due to overhead

Common uses: web browsing (HTTP/HTTPS), email (SMTP), file transfers (FTP)

Step 2: What is UDP?

UDP is a connectionless protocol that sends data without establishing a connection or guaranteeing delivery. It's like sending a postcard — no confirmation if it arrives.

  • Features:
    • Unreliable (no delivery guarantee)
    • No ordering of packets
    • Low latency and overhead

Common uses: streaming (video/audio), online gaming, DNS lookups, VoIP

Step 3: Comparison Table

FeatureTCPUDP
ConnectionYesNo
ReliabilityReliableUnreliable
SpeedSlowerFaster
Use CasesWeb, EmailStreaming, Gaming

Step 4: Example Ports

  • TCP: 80 (HTTP), 443 (HTTPS), 22 (SSH)
  • UDP: 53 (DNS), 123 (NTP), 161 (SNMP)

Step 5: Packet Structure Differences

TCP headers are larger due to extra fields like sequence numbers and acknowledgments. UDP headers are minimal for faster performance.

Next Steps

Try using netstat -an to see open TCP and UDP ports on your system. Understanding when to use TCP vs UDP helps you optimize performance and reliability in your applications.