multiplexing and demultiplexing
Picture one front door for a whole office building. Every outgoing letter from every department goes out that one door, and every incoming letter arrives there too. To make this work, an outgoing letter gets a return address with a department number, and an arriving letter is sorted by the department number written on it. Multiplexing is the gathering side — collecting data from many application processes and pushing it out through one network connection. Demultiplexing is the sorting side — taking each arriving segment and delivering it to the right process.
The transport layer does this using the four-tuple in each segment plus the IP addresses below it. For UDP, demultiplexing uses just the destination IP address and destination port: all segments with the same (destination IP, destination port) go to the same socket, no matter who sent them. For TCP, the socket is identified by the full four-tuple — source IP, source port, destination IP, destination port — so a busy web server on TCP port 443 can keep thousands of simultaneous client connections separate, because each client's (IP, port) pair is different. Multiplexing on the send side simply means writing the correct source and destination ports into the header before handing the segment down.
Why it matters: this is the transport layer's most basic service, and it is what makes a single host able to run many network programs at once. Without it, your machine could hold only one conversation at a time. It also explains a lot of everyday behavior: why your laptop can download a file, video-call, and load a page simultaneously over one Wi-Fi link, and why a NAT box (which rewrites ports) can let a whole household share one public IP address.
A server at 203.0.113.5:443 sees two arriving TCP segments, both with destination port 443. One has source (198.51.100.7, 51000), the other (198.51.100.8, 49152). The full four-tuples differ, so TCP demultiplexes them into two separate sockets — two clients, cleanly kept apart.
TCP sorts by the full four-tuple; UDP only by destination IP+port.
A common confusion: UDP and TCP demultiplex differently. Two UDP senders writing to the same (dest IP, dest port) land in the same socket; two TCP clients with different source ports land in different sockets.