TCP/IP: what it is, protocol stack and data transmission

Author: IT Sectr Published: 2026-03-06 Reading time: 8 min

TCP/IP is a protocol stack that forms the foundation of the Internet and most computer networks. It combines the TCP protocol, responsible for reliable data delivery, and IP, which ensures packet routing between nodes. According to IETF RFC 1180 (2024), the TCP/IP stack handles over 80% of global network traffic, including mobile and web applications. The protocol stack defines how data is packaged, addressed, and transmitted between devices on a network.

Key Takeaways

  • TCP/IP — a protocol stack combining TCP (transport) and IP (routing) for data transmission in networks
  • Four layers of the model: application, transport, network, and link — each solving its own task
  • TCP guarantees delivery, packet ordering, and error control through acknowledgments and retransmissions
  • IP provides routing — selecting the packet path from sender to receiver through intermediate nodes
  • Understanding TCP/IP is essential for developing network applications, debugging connections, and optimizing performance

What is TCP/IP?

TCP/IP (Transmission Control Protocol / Internet Protocol) is a protocol stack developed in the 1970s for ARPANET and has become the de facto standard for the global Internet. It defines how data is divided into packets, addressed, transmitted, and reassembled on the receiver’s side.

The TCP/IP architecture is built on a multi-layered principle, where each layer abstracts specific functions. The application layer works with application data, the transport layer ensures reliability, the network layer handles routing, and the link layer manages physical transmission. Modularity allows replacing protocols within a layer without affecting neighboring ones.

In mobile development, TCP/IP is used by every application that makes network requests. Libraries such as URLSession, OkHttp, AFNetworking, and Alamofire work on top of this stack, hiding the details of packet packaging and routing from the developer. However, understanding TCP/IP is necessary for performance optimization: configuring TCP parameters through URLSessionConfiguration allows managing timeouts, maintaining HTTP Persistent Connections, and setting up proxies for enterprise environments.

Understanding TCP/IP is essential for diagnosing network problems: if an application cannot connect to a server, the issue may be at any layer of the stack — from the physical channel to the application protocol. Tools like tcpdump, Wireshark, and Charles Proxy allow analyzing traffic at each layer and finding bottlenecks. For mobile developers, Xcode provides a Network Debug Dashboard, and Android Studio offers a Network Inspector for analyzing TCP connections in real time.

TCP/IP Model Layers

The TCP/IP model includes four layers, each performing strictly defined functions during data transmission. Understanding this hierarchy is necessary for diagnosing network problems and optimizing applications.

Application Layer

At the application layer, protocols that applications directly interact with operate: HTTP, HTTPS, FTP, SMTP, DNS, WebSocket. This layer formats data in a way the application understands and passes it to the transport layer. Mobile application developers work at this layer through networking libraries.

Transport Layer

The transport layer ensures data transmission between applications on different devices. The main protocols are TCP (reliable transmission with acknowledgment) and UDP (fast transmission without guarantees). TCP adds sender and receiver ports to the data, manages packet ordering, and controls network congestion.

Network and Link Layers

The network layer is implemented by the IP protocol, which defines addressing (IPv4, IPv6) and packet routing. Each packet contains the sender and receiver IP addresses, and routers along the path make decisions about the next node based on routing tables. IPv4 uses 32-bit addresses (about 4.3 billion), while IPv6 uses 128-bit addresses, solving the address exhaustion problem.

The link layer works with the physical transmission medium: Ethernet, Wi-Fi, Bluetooth. This layer converts packets into signals and back, manages access to the transmission medium via MAC addresses, and detects physical layer errors using frame check sequences (FCS).

At the link layer, protocols such as ARP (Address Resolution Protocol), which converts IP addresses to MAC addresses of devices on the local network, and PPP (Point-to-Point Protocol), used in VPN connections and mobile data networks, operate.

LayerProtocolsFunction
ApplicationHTTP, HTTPS, DNS, FTP, WebSocketApplication data formatting
TransportTCP, UDPTransmission between applications, error control
NetworkIP, ICMP, ARPPacket routing and addressing
LinkEthernet, Wi-Fi, PPPPhysical medium transmission

How TCP Protocol Works

TCP (Transmission Control Protocol) is one of the main transport layer protocols. It ensures reliable, ordered, and error-checked delivery of a byte stream between applications. Before transmitting data, TCP establishes a connection through a three-way handshake.

The three-way handshake begins with the client sending a SYN packet. The server responds with a SYN-ACK packet, confirming receipt. The client completes the handshake with an ACK packet, after which data transmission begins. This process guarantees that both parties are ready for exchange and synchronized on sequence numbers.

python
import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('example.com', 80))
sock.send(b'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
response = sock.recv(4096)
print(response.decode())
sock.close()

In the example, a TCP socket is created with the SOCK_STREAM type, which automatically performs a three-way handshake when connect is called. The send method transmits an HTTP request, and recv receives the response. After completion, close sends a FIN packet to properly close the connection.

TCP Server with Client Handling

Let’s look at an example of a TCP server in Python that accepts multiple clients via threads. Each connection is handled in a separate thread, allowing multiple clients to be served simultaneously without blocking the main loop.

python
import socket
import threading

def handle_client(conn, addr):
    print(f'Client connected: {addr}')
    with conn:
        while True:
            data = conn.recv(1024)
            if not data:
                break
            conn.sendall(data.upper())
    print(f'Client {addr} disconnected')

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('0.0.0.0', 9090))
server.listen(5)
print('TCP server started on port 9090')

while True:
    conn, addr = server.accept()
    thread = threading.Thread(target=handle_client, args=(conn, addr))
    thread.start()

The TCP server handles each connection in a separate thread, calling accept in an infinite loop. The handle_client function receives data, converts it to uppercase, and sends it back via sendall. When the recv loop ends (when the client closes the connection), the thread terminates, and the socket is automatically closed. In mobile applications, such low-level socket work is not used directly — mobile HTTP libraries manage connections through thread pools and automatically reuse TCP connections.

TCP vs UDP Differences

The choice between TCP and UDP is one of the key decisions when designing network communication. TCP guarantees delivery, order, and data integrity at the cost of additional latency. UDP sacrifices reliability for minimal latency and lower channel load.

CharacteristicTCPUDP
ConnectionEstablishes (handshake)Does not establish
ReliabilityGuarantees deliveryDoes not guarantee
Packet orderOrders packetsDoes not order
SpeedLowerHigher
UsageWeb, email, filesStreaming, games, DNS

For mobile applications, the protocol choice depends on the scenario: REST APIs and data loading require TCP, while video calls and online games benefit from UDP speed. Some applications combine both protocols — TCP for control and UDP for media streaming. The modern QUIC protocol, running over UDP and used in HTTP/3, combines the advantages of both approaches and is already supported on iOS and Android through URLSession automatically.

TCP/IP Code Examples

Let’s look at an example of a TCP client in Python with error handling and timeout. This approach is used in mobile applications for reliable server connection.

python
import socket
import sys

def tcp_client(host, port):
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(10)
        sock.connect((host, port))
        print(f'Connected to {host}:{port}')
        return sock
    except socket.error as err:
        print(f'Connection error: {err}')
        sys.exit(1)

sock = tcp_client('api.example.com', 443)
sock.close()

The tcp_client function takes a host and port, creates a socket with a 10-second timeout, and attempts to connect. On connection error — for example, server unavailability or firewall blocking — an exception with a problem description is thrown. In mobile applications, connection timeout is critical: too short leads to false errors on slow networks, too long leads to interface freezing. The recommended value for mobile networks is 10–15 seconds for timeoutIntervalForRequest and 30–60 seconds for timeoutIntervalForResource in URLSession configuration.

Frequently Asked Questions

What is the difference between TCP and IP?

IP is responsible for routing — delivering a packet from sender to receiver through intermediate nodes. TCP ensures reliable data assembly: controls ordering, checks integrity, and requests retransmission of lost packets. Together they form the TCP/IP stack.

What port does TCP/IP use by default?

TCP/IP does not use a fixed port — the port is assigned by the application. Standard ports: 80 (HTTP), 443 (HTTPS), 22 (SSH), 25 (SMTP). Port 443 is the main one for secure web traffic in mobile applications.

What is a TCP connection?

A TCP connection is a logical channel between two applications, established through a three-way handshake (SYN, SYN-ACK, ACK). The connection is identified by the sender and receiver pair (IP address, port). The handshake guarantees that both parties are ready for data exchange.

Can TCP/IP be used in mobile applications without the Internet?

Yes, TCP/IP works on local networks (LAN) without Internet access. Devices connect via Wi-Fi Direct, Bluetooth PAN, or Ethernet and exchange data using local IP addresses. Local TCP/IP is used in IoT devices and peer-to-peer applications.

Why is TCP slower than UDP?

TCP is slower due to additional mechanisms: a three-way handshake before transmission, acknowledgment of each packet, retransmission of lost segments, and congestion control. UDP sends datagrams without these checks, reducing latency at the cost of potential loss.

Summary

  • TCP/IP — a fundamental protocol stack ensuring data transmission over the Internet and local networks
  • Four layers (application, transport, network, link) abstract different aspects of transmission
  • TCP guarantees reliable delivery with error control and acknowledgments
  • IP is responsible for packet routing and node addressing in the network
  • Choosing TCP or UDP depends on requirements: reliability versus speed
  • Every mobile application that makes network requests uses the TCP/IP stack

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also