The TCP and UDP segment format

Putting this here just for reference as repeating Stanford Networking course.

Some of important fields in TCP Segment :

Destination port – tells the TCP layer which application should get the bytes on ether end.

Source port Says where the data should get back, when app starts sending the data it generates unique source port number – to be able to receive the data back. (to differentiate the connection between host A and B)

Sequence number Indicates the position of the byte stream in TCP Data field.

Acknowledgment Sequence Tells the other end which byte we are expecting next, also says that until now we have received all data correctly.

16 Bit Checksum – To detect corrupt data, bit errors on the wire for example.

Header length Tells how long the header is, also shows how many options are present.

Flags : ack, urg, push bit, reset flag, syn, fin 

Window Size – Could be 1 – means stop and wait, could be 0 means connection will be closed, could be 1500 or other value means that much of bytes we can send without the acknowledge.

The unique id of a TCP connection.

In IPv4 Header we have IP Dest. A.; IP Source A., Protocol ID=TCP = 104-bit globally unique ID.

As the first steps host a increments source port for every new connection.

Then TCP picks ISN (initial sequence number) to avoid overlap with previous connection with same ID.


UDP has only 4 header fields unlike TCP which as 10.

Fields :

Source port, Destination PortLength, Checksum(Optional field) if it’s used then it’s calculated with UDP header and data otherwise it’s filled with 0 fields.

In a nutshell UDP is unreliable delivery – no acks, no way to detect missing datagrams, no flow control, packets may show up in any order, TCP has all those function and the issue of TCP is that TCP datagram is much bigger than UDP and carries a lot of features which might be not needed for apps like video streaming or DNS or features like flow control might be already implemented in APP itself. For example right now we are observing more and more intensive usage of protocol QUIC in network.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s