TCP & UDP

Done
💡
Session: exchange of data between two or more communicating devices
💡
IMPORTANT: The Destination Port identifies the Application Layer Protocol
💡
IMPORTANT: The reply reverses the Source and Destination ports of the request. This makes the requester able to identify which session a segment belongs to.
Type RangeDescription
Well-known0 - 1023Highly regulated ports, used by major protocols
Registered1024 - 49151Less regulated, but still need registration with IANA (Internet Assignment Numbers Authority)
Ephemeral/private/dynamic49152 - 65535These are the ports used randomly to populate the source ports

TCP (Transmission Control Protocol)

Important fields in the TCP Header

Three-Way Handshake (Initiate connection)

Four-Way Handshake (Terminate Connection)

Sequence Number and Acknowledgment number

💡
REMEMBER: The Sequence number, except the SYN and the SYN/ACK ones, is ALWAYS equal to the Acknowledgment number of the previous segment (Forward acknowledgment = indicates the sequence number of the next number it expects to receive). The Acknowledgment number is ALWAYS one number greater than the sequence of the previous segment.

UDP (User Datagram Protocol)

Although it also has error-detection (NOT error-recovery), it doesn`t have any of the features that TCP has. However, since it is less complex and doesn`t rely on acknowledgment, it has a greater performance, usually crucial for real-time applications.

Comparing TCP vs UDP

TCP UDP
Connection-oriented (3-Way Handshake)Connectionless
ReliableNon-Reliable
SequencingNO sequencing
Flow ControlNO Flow Control
High overheadLow overhead
File transfer, downloads, etc.VoIP, live video, etc.

Major Port Numbers

TCPUDPTCP & UDP
FTP data (20)DHCP server (67)DNS (53)
FTP control (21)DHCP client (68)
SSH (22)TFTP (69)
Telnet (23)SNMP agent (161)
SMTP (25)SNMP manager (162)
HTTP (80)Syslog (514)
POP3 (110)
HTTPS (443)