The transport layer provides end-to-end communication between application processes on different hosts, built on the network layer’s delivery of packets between hosts. In terms of encapsulation, application data is carried in segments, segments in packets, and packets in frames.
flowchart LR A[Application data] --> S[Segment, transport layer] S --> P[Packet, network layer] P --> F[Frame, link layer] style S fill:#e3f2fd
The layer exposes two service models. Messages, also called datagrams, are discrete units of data delivered independently, and UDP provides them with no delivery guarantees. Bytestreams are continuous ordered streams of bytes, and TCP provides them with reliability, flow control, and congestion control layered on top of the network’s best-effort delivery.
The choice between them depends on whether an application requires delivery guarantees more than low overhead. TCP and UDP treat the two protocols in detail.