# Basic Question in networking - why max data size of ip datagram 65535 BYTES and not 65535 bits?

I recently started computer networks with some understanding of algorithms and discrete mathematics. I am completely new. Kindly elaborate following -

data size of ip datagram = 16bits. So with this $$2^{16} -1 = 65536$$ 16 bit patterns can be generated. My doubt:

1. Do we say each 16 bit pattern is 1 IP datagram or all those 65536 patterns as 1 IP Datagram?
2. If i consider all 65536 patterns as max data size, then max ip datagram size $$= 65536$$ patterns size$$= 65536*16$$ bits $$= 65536*16/8$$ bytes $$= 65536*2$$ bytes

16 bits is not the size of the IP datagram; it is the amount of bits required to encode its length. Hence, you can have datagrams of length up to 65536 octets (i.e., bytes), as described in RFC 760:

Total Length: 16 bits

Total Length is the length of the datagram, measured in octets, including internet header and data. This field allows the length of a datagram to be up to 65,535 octets.

Notice 65536 is not a prescribed length, that is, the length of the datagram is (or can be) variable.