The software at each layer in the protocol stack attaches a header (and perhaps footer) to the data it receives from the layer above it. In other words, it encapsulates the message from the layer above it.
For example, in sending a page request to a Web server, the Web client composes the message, passes it to the TCP program for delivery, and waits for a reply.
The TCP software constructs a TCP segment header, filling in such fields as the port (identifying the application program that will receive the message), error check sum, etc. It also calls a domain name server (DNS) to get the destination IP address, which it passes on to the IP layer.
The TCP segment is passed to the IP program which constructs the IP header, including the source IP address and the destination IP address. Assuming the local area network is an Ethernet, the data-link layer software constructs an Ethernet frame.
At the receiving end, the headers are discarded as the message moves up the stack to the Web server.
Note that the units of information are called packets, segments, or frames depending upon the protocol layer. IP packets are also referred to as datagrams.