I was wondering how the message changes its form or structure while passing through multiple layers.
So how it changes its form while getting through different layers and devices?
The message itself doesn't change. Generally, higher layer data is encapsulated in lower layer protocol overhead, transported along - the lower layer protocols likely change along the way - and pieced together at the end again.
For instance, an application on host A sends a UDP message to an application on host B, containing the string "Hello":
I've omitted some details for simplicity (forwarding decisions, IP senders ARPing the next hop's MAC address, different line codes/PHYs, ...).
Seven-layered approach to data transmission divides the many operations up into specific related groups of actions at each layer
The transmitting computer software gives the data to be transmitted to the applications layer, where it is processed and passed from layer to layer down the stack with each layer performing its designated functions. The data is then transmitted over the physical layer of the network until the destination computer or another device receives it.
During transmission, each layer adds a header to the data that directs and indentifies the packet. This process is called encapsulation. The header and data together form the data packet for the next layer that, in turn, adds its header and so on.
You can learn about different headers in the layer in any of the networking books.You will find this link helpful: