Layer 4 is the Transport layer. The transport layer creates virtual Transfer Control Protocol (TCP) or User Datagram Protocol (UDP) connections between network hosts.
This layer sends and receives data to and from the applications running on its host. The Transport layer assigns port numbers to the processes running in applications on the host and adds a TCP or UDP header to the messages received from the applications detailing the source and destination port numbers.
Note that some of the applications, specifically Telnet, SMTP, and HTTP require TCP as the transport protocol while the others use UDP.
Some applications require reliable ordered delivery of packets. The TCP protocol provides this capability. It uses error detection, retransmissions and acknowledgements. This protocol cares about your data.
Other applications don’t care if every packet is received. These applications can take advantage UDP’s lower overhead to enable faster transmissions.
Typical TCP applications include email and web browsing and typical UDP applications include VoIP and music streaming.
TCP is strictly used for point to point or unicast transmissions while UDP can also be used for multicast and broadcast transmissions.
TCP and UDP Headers
The header added to messages by the Transport layer includes more than just the source and destination port numbers. Here we are showing all the information included in TCP and UDP headers.
Note how the TCP protocol requires more information and overhead to guarantee data delivery.
For more information on TCP:
http://en.wikipedia.org/wiki/Transmission_Control_Protocol
For more information on UDP:
http://en.wikipedia.org/wiki/User_Datagram_Protocol