TCP/IP and OSI layers

TPC and OSI Network layers
Layer TCP OSI Data tranported Examples
1 Link Physical Bits Network card
2 Link Data Link Frames Ethernet (a MAC address, a Switch)
3 Internet Network Packets IP (a Router etc.) (1)
4 Transport Transport Segments TCP, UDP
5 Application Session Data
6 Application Presentation Data
7 Application Application Data HTTP, FTP

(1) TCP/IP model is less strict. ICMP and IGMP protocols belong to the IP layer but perform internetworking functions.

From Wikipedia

IP: is an unreliable datagram transmission protocol that facilitates transmission of datagrams between hosts potentially located in different networks by forwarding the transport layer datagrams to an appropriate next-hop router for further relaying to its destination. With this functionality, the internet layer makes possible internetworking, the interworking of different IP networks, and it essentially establishes the Internet

TCP and UDP: The transport layer establishes basic data channels that applications use for task-specific data exchange. The layer establishes process-to-process connectivity, meaning it provides end-to-end services. Its responsibility includes end-to-end message transfer independent of the underlying network, along with error control, segmentation, flow control, congestion control, and application addressing (port numbers).

End-to-end message transmission or connecting applications at the transport layer can be categorized as either connection-oriented, implemented in TCP, or connectionless, implemented in UDP.

For the purpose of providing process-specific transmission channels for applications, the layer establishes the concept of the port. This is a numbered logical construct allocated specifically for each of the communication channels an application needs. For many types of services, these port numbers have been standardized so that client computers may address specific services of a server computer without the involvement of service announcements or directory services.

IP Header

IPv4 Header Format
Offsets Octet 0 1 2 3
Octet Bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
0 0 Version IHL DSCP ECN Total Length
4 32 Identification Flags Fragment Offset
8 64 Time To Live Protocol Header Checksum
12 96 Source IP Address
16 128 Destination IP Address
20 160 Options (if IHL > 5)
24 192
28 224
32 256

TCP Header

TCP segment header
Offsets Octet 0 1 2 3
Octet Bit  7  6  5  4  3  2  1  0  7  6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
0 0 Source port Destination port
4 32 Sequence number
8 64 Acknowledgment number (if ACK set)
12 96 Data offset Reserved
0 0 0
NS
CWR
ECE
URG
ACK
PSH
RST
SYN
FIN
Window Size
16 128 Checksum Urgent pointer (if URG set)
20
160
Options (if data offset > 5. Padded at the end with “0” bytes if necessary.)