TCP/IP Model
What is the TCP/IP Model?
The TCP/IP model (also called the Internet model or DoD model) is the practical networking model used by the Internet. It was developed by DARPA in the 1970s. Unlike the OSI model (theoretical), TCP/IP is the actual implementation used in real networks.
The TCP/IP model has 4 layers (some sources say 5):
TCP/IP vs OSI Model
| TCP/IP Layer | OSI Equivalent | Protocols |
|---|---|---|
| Application | Application + Presentation + Session (7,6,5) | HTTP, HTTPS, FTP, SMTP, DNS, DHCP, SSH, Telnet, SNMP |
| Transport | Transport (4) | TCP, UDP |
| Internet | Network (3) | IP (IPv4/IPv6), ICMP, ARP, RARP, OSPF, BGP |
| Network Access | Data Link + Physical (2,1) | Ethernet, Wi-Fi, PPP, Frame Relay |
TCP vs UDP
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (3-way handshake) | Connectionless |
| Reliability | Reliable (guaranteed delivery) | Unreliable (best effort) |
| Ordering | Ordered delivery | No ordering guarantee |
| Error Checking | Yes (checksum + retransmission) | Checksum only (no retransmission) |
| Flow Control | Yes (sliding window) | No |
| Congestion Control | Yes | No |
| Speed | Slower (overhead) | Faster (less overhead) |
| Header Size | 20-60 bytes | 8 bytes |
| Use Cases | HTTP, FTP, SMTP, SSH (reliability needed) | DNS, DHCP, VoIP, video streaming, gaming |
TCP 3-Way Handshake
Before data transfer, TCP establishes a connection using a 3-way handshake:
- SYN (Synchronize): Client sends a SYN packet to the server with a random sequence number (ISN). "I want to connect, my sequence number is X."
- SYN-ACK (Synchronize-Acknowledge): Server responds with SYN-ACK. Acknowledges client's SYN (ACK = X+1) and sends its own SYN with sequence number Y. "I acknowledge your X, my sequence number is Y."
- ACK (Acknowledge): Client sends ACK (ACK = Y+1). "I acknowledge your Y. Connection established."
After the handshake, data transfer begins. The connection is full-duplex — both sides can send and receive simultaneously.
TCP Connection Termination (4-Way Handshake)
TCP uses a 4-way handshake to close a connection:
- FIN: Client sends FIN to server. "I'm done sending data."
- ACK: Server acknowledges the FIN. "Got it."
- FIN: Server sends its own FIN. "I'm also done sending data."
- ACK: Client acknowledges server's FIN. "Got it. Connection closed."
After the final ACK, the client waits in TIME_WAIT state (2×MSL) before fully closing, to ensure the server received the final ACK.
Port Numbers
| Range | Type | Examples |
|---|---|---|
| 0 – 1023 | Well-Known Ports | HTTP(80), HTTPS(443), FTP(21), SSH(22), SMTP(25), DNS(53) |
| 1024 – 49151 | Registered Ports | MySQL(3306), PostgreSQL(5432), MongoDB(27017), Redis(6379) |
| 49152 – 65535 | Dynamic/Ephemeral Ports | Assigned temporarily to client connections |
Ready to Level Up Your Skills?
Explore 500+ free tutorials across 20+ languages and frameworks.