This is a 16 bit field that defines the total length of the user datagram, header plus data. This 16 bit can define a total length of a 0 to 65, 535 bytes. However the total length needs to be much less because a UDP is stored in an IP datagram with a total length of 65, 535 bytes,
The length fields in a UDP user datagram is actually not necessary. A user datagram is encapsulated in an IP datagram. There is a fields in the IP datagram that defined the total length. There is another fields in the IP datagram that defines the length the header. So if we subtract the value of the second field from the first we can find the length of a UDP Dataram that is encapsulated in IP datagram.
UDP length = IP length - IP header s length
However the designers of the UDP protocols felt that it was more efficient for the destination UDP to calculate the length of the data from the information provided in the UDP user datagram rather than ask the IP software to supply this information. We should remember that when the IP software delivers the UDP user datagram to the UDP layer. It has already dropped the IP header.