The method in which data is formatted for TCP and IP is different. The main difference is that IP only stores the information about the destination, while TCP stores both recipient and sender information.
TCP Packet Format

- Source Port(16 bits): It holds the source/transmitting application’s port number and helps in determining the application where the data delivery is planned.
- Destination Port (16 bits): This field has the port number of the transmitting application and helps to send the data to the appropriate application.
- Sequence Number (32 bits): It ensures that the data is received in proper order by ordered segmenting and reassembling them at the receiving end.
- Acknowledgment Number (32 bits): This field contains the upcoming sequence number and it acknowledges the feedback up to that.
- Data Offset (4 bits): The data offset field indicates the starting point of the TCP data payload also storing the size of the TCP header.
- Control Flags (9 bits): TCP uses a few control flags to regulate communication. Some of the important flags include:
- SYN (Synchronize): Responsible for connecting the sender and receiver.
- ACK (Acknowledgment): Its purpose is transfer the acknowledgement of whether the the sender has received data.
- FIN (Finish): It informs whether the TCP connection is terminated or not.
- RST (Reset): Mainly used to reset the connection when an error occurs.
- Window Size (16 bits): The size of the sender’s receive window is specified by this property.
- Checksum (16 bits): It reveals if the header was damaged during transportation.
- Urgent Pointer (16 bits): This field points to the packet’s first byte of urgent data.
- Options (Variable length): This field represents the different TCP options.
- Data Payload: This field mainly contains the information which is the actual application data that is being transmitted.
IP Packet Format

- Version (4 bits): This field contains a value in four bits which is 0100 generally. This value is utilized in distinguishing between IPv4 and IPv6, using four bits.
- Header Length (4 bits): This value is 4 bits in size and it represents how many 32-bit words are present in the IP header. In short it is also called as HE-LEN.
- Type of Service (TOS) (8 bits): This field mainly deals with the information about how the quality of the service is being delivered. The first 3 bits provides distinction and prioritization of IP packets depending on certain service needs, such as precedence, delay, throughput, dependability, and cost.
- Total Length (16 bits): The total length of the IP packet is stored in bytes. This value and the HE-LEN sums up to the value of the Payload.
- Identification (16 bits): This field gives a specific IP packet a distinctive identity. This helps to identify the fragments of an IP Datagram uniquely.
- Flags (3 bits): Contains control flags for packet fragmentation and reassembly, such as the “Don’t Fragment” and “More Fragments” flags.
- Fragment Offset (13 bits): After a packet is fragmented and put back together, this field contains the location of it inside the original packet. It represents the number of Data Bytes ahead of the particular fragment in the specific Datagram.
- Time to Live (TTL) (8 bits): This field specifies the total lifetime of the Data packet in the internet system. This field indicates how many hops (routers) an IP packet can make before being terminated. This values goes from 0-255.
- Protocol (8 bits): This IPv4 header specifies the type of transport layer protocol, such as TCP, UDP, or ICMP, to which the IP packet will be routed. For example, TCP is indicated by number 6 and UDP protocol us denoted by number 17.
- Header Checksum (16 bits): This is an error checking layer which is added to identity errors in the header. By comparing the IP header with its checksum for error detection, it ensures the IP header’s integrity.
- Source IP Address (32 bits): The IPv4 sender’s 32-bit address is represented by this value.
- Destination IP Address (32 bits): This value represents the 32-bit IP address of the intended recipient.
- Options (variable length): This field has options and parameters for security, record route, time stamp, etc. You can see that the End of Options, or EOL, usually marks the end of the list of options component.