5 Transport Protocols: TCP and UDP

Learn how ports direct network traffic to applications and how TCP and UDP differ in delivery, ordering, overhead, and control.

The transport layer

The transport layer enables programs on different hosts to communicate. It uses network-layer delivery, typically IP, and adds services that help applications send data to the appropriate program and, depending on the protocol, manage delivery.

The two widely used Internet transport protocols are and . Both use ports, but TCP provides a reliable, ordered byte stream, whereas UDP provides lightweight, message-based datagrams without built-in delivery guarantees.

Ports and application delivery

An IP address identifies a network interface or host for delivery. A helps identify an application endpoint on that host. TCP and UDP have separate 16-bit port spaces, each ranging from 00 to 65,53565{,}535.

A connection or exchange is identified by the transport protocol together with the source and destination addresses and ports. This allows one host to run many networked applications and one application to communicate with multiple peers at once.

The operating system uses to send data from different applications onto the network, and demultiplexing to deliver incoming data to the appropriate application. For example, a client may contact a service at a known destination port while using a temporary source port for its own endpoint.

IANA divides ports into three ranges:

  • System Ports: 00–10231023.

  • User Ports: 10241024–49,15149{,}151.

  • Dynamic Ports: 49,15249{,}152–65,53565{,}535.

Dynamic ports are commonly used for temporary local endpoints.

Transport services

Transport protocols can provide application addressing through ports, data delivery, error detection, and management of traffic between endpoints. means more than detecting corruption: it can include detecting missing data, retransmitting it, and delivering data in order.

helps prevent a sender from overwhelming a receiver. helps limit traffic when the network path is overloaded. TCP provides these controls as part of its transport service. UDP does not provide them inherently, so an application using UDP must add any mechanisms it needs.

TCP: a reliable byte stream

is connection-oriented: endpoints establish a connection before exchanging data and close it when finished. TCP presents applications with a continuous byte stream rather than separate messages. If an application makes two writes, TCP may deliver their bytes together or in pieces, so the application protocol must define how to recognize message boundaries.

TCP numbers bytes with sequence numbers and uses acknowledgments to track received data. It detects transmission errors with checksums and recovers from loss by retransmitting data. These mechanisms provide reliable, in-order delivery to the application. TCP also uses receiver and network .

A file-transfer application commonly benefits from TCP because missing bytes are retransmitted and the application receives the file’s bytes in order. The trade-off is additional protocol state and possible delay while lost data is recovered.

UDP: lightweight datagrams

sends independent datagrams and preserves their message boundaries. It does not establish a connection or guarantee that a datagram will arrive, arrive only once, or arrive in order. Its checksum can detect certain errors, but UDP itself does not repair them.

UDP’s smaller set of built-in mechanisms can suit applications that value low overhead or need to control delivery behavior themselves. A real-time voice application may use UDP because a late audio packet can be less useful than the next packet; the application can choose to tolerate occasional loss rather than wait for retransmission.

If an application requires reliable delivery over UDP, it must implement that behavior itself and also provide appropriate .

Choosing between TCP and UDP

Neither protocol is universally better. Choose TCP when an application needs a reliable, ordered stream. Choose UDP when datagram boundaries, low overhead, or application-specific handling of delay and loss are important, while ensuring that the application handles congestion responsibly.

  • Communication model: TCP is connection-oriented; UDP is datagram-based and has no transport connection setup.

  • Data presented to the application: TCP provides an ordered byte stream; UDP provides separate messages, or datagrams.

  • Delivery and ordering: TCP includes delivery and ordering mechanisms, including retransmission. UDP provides no such guarantees, though an application may add mechanisms.

  • Flow and : TCP has these controls built in. They are not inherent in UDP, so UDP applications must account for congestion.

  • Typical trade-off: TCP offers more built-in guarantees with additional overhead. UDP has less built-in overhead and gives applications more control.