Bird
Raised Fist0
Computer Networksknowledge~6 mins

UDP datagram structure in Computer Networks - Full Explanation

Choose your learning style10 modes available
Introduction
Imagine sending a quick message to a friend without waiting for a reply or confirmation. This is the problem UDP solves by providing a simple way to send data quickly over a network without extra checks.
Explanation
Source Port
This field holds the number of the sending application’s port. It tells the receiver where the message came from so it can reply if needed. If the sender does not expect a reply, this field can be zero.
The source port identifies the sender’s application endpoint.
Destination Port
This field contains the port number of the receiving application. It directs the incoming message to the correct program on the receiving device, like an address on a mailbox.
The destination port directs the datagram to the right application.
Length
This field shows the total size of the UDP datagram, including both header and data. It helps the receiver know where the message ends, ensuring the entire message is read.
Length tells how big the entire UDP datagram is.
Checksum
This is a simple error-checking code that helps detect if the data was corrupted during transmission. If the checksum does not match, the receiver knows the message may be damaged and can discard it.
Checksum helps detect errors in the datagram.
Data
This is the actual information or message being sent. It can be anything from a small command to a chunk of a file. UDP does not change or check this data beyond the checksum.
Data is the message content carried by the UDP datagram.
Real World Analogy

Imagine sending a postcard through the mail. The postcard has a return address, a destination address, a note about the size of the message, a stamp to check if it’s valid, and the message itself written on it.

Source Port → Return address on the postcard showing who sent it
Destination Port → Destination address on the postcard showing where it should go
Length → Note about how big the message is to ensure the whole postcard is received
Checksum → Stamp or mark that helps verify the postcard wasn’t damaged
Data → The written message on the postcard
Diagram
Diagram
┌───────────────┬───────────────┬───────────────┬───────────────┐
│ Source Port   │ Destination   │ Length        │ Checksum      │
│ (16 bits)     │ Port (16 bits)│ (16 bits)     │ (16 bits)     │
├───────────────────────────────────────────────────────────────┤
│ Data (variable length)                                         │
└───────────────────────────────────────────────────────────────┘
This diagram shows the UDP datagram header fields and the data section layout.
Key Facts
UDP Source Port → A 16-bit number identifying the sender’s application port.
UDP Destination Port → A 16-bit number identifying the receiver’s application port.
UDP Length → A 16-bit field indicating the total size of the UDP datagram.
UDP Checksum → A 16-bit error-checking code for the header and data.
UDP Data → The payload or message carried by the UDP datagram.
Common Confusions
Believing UDP guarantees message delivery like TCP.
Believing UDP guarantees message delivery like TCP. UDP does not guarantee delivery or order; it simply sends datagrams without confirmation.
Thinking the checksum fixes errors automatically.
Thinking the checksum fixes errors automatically. The checksum only detects errors; it does not correct them.
Assuming the source port is always set.
Assuming the source port is always set. The source port can be zero if the sender does not expect a reply.
Summary
UDP datagrams have a simple header with source port, destination port, length, and checksum fields.
The data section carries the actual message without extra delivery guarantees.
UDP is fast and lightweight but does not ensure messages arrive or are error-free.

Practice

(1/5)
1. Which of the following is NOT a field in the UDP datagram header?
easy
A. Sequence Number
B. Destination Port
C. Source Port
D. Checksum

Solution

  1. Step 1: Recall UDP header fields

    The UDP header contains Source Port, Destination Port, Length, and Checksum fields.
  2. Step 2: Identify the incorrect field

    Sequence Number is a field in TCP, not UDP.
  3. Final Answer:

    Sequence Number -> Option A
  4. Quick Check:

    UDP header fields exclude Sequence Number [OK]
Hint: Remember UDP header has no sequence number, unlike TCP [OK]
Common Mistakes:
  • Confusing UDP with TCP header fields
  • Thinking UDP has sequence numbers
  • Mixing checksum with sequence number
2. What is the total size in bytes of the UDP header?
easy
A. 8 bytes
B. 4 bytes
C. 12 bytes
D. 16 bytes

Solution

  1. Step 1: Recall UDP header size

    The UDP header consists of four fields, each 2 bytes long: Source Port, Destination Port, Length, and Checksum.
  2. Step 2: Calculate total size

    4 fields x 2 bytes each = 8 bytes total.
  3. Final Answer:

    8 bytes -> Option A
  4. Quick Check:

    4 fields x 2 bytes = 8 bytes [OK]
Hint: UDP header always 8 bytes, fixed size [OK]
Common Mistakes:
  • Confusing with IP or TCP header size
  • Assuming variable header size
  • Counting data length as header size
3. Given a UDP datagram with Source Port = 1234, Destination Port = 80, Length = 20, and Checksum = 0x1A2B, which field indicates the size of the entire UDP datagram including header and data?
medium
A. Source Port
B. Checksum
C. Destination Port
D. Length

Solution

  1. Step 1: Understand UDP Length field meaning

    The Length field specifies the total length of the UDP datagram, including header and data, in bytes.
  2. Step 2: Identify the field indicating size

    Among the given fields, only Length represents the size of the entire UDP datagram.
  3. Final Answer:

    Length -> Option D
  4. Quick Check:

    Length field = total UDP datagram size [OK]
Hint: Length field shows total UDP datagram size [OK]
Common Mistakes:
  • Confusing port numbers with size
  • Thinking checksum indicates size
  • Ignoring header size in length
4. A programmer wrote code to parse a UDP datagram but forgot to read the Checksum field. What is the likely consequence?
medium
A. The datagram will be rejected by the receiver
B. The length field will be misinterpreted
C. The datagram may be accepted without error checking
D. The source port will be incorrect

Solution

  1. Step 1: Understand role of Checksum in UDP

    The Checksum is used for error checking but is optional in IPv4; ignoring it means no error verification.
  2. Step 2: Consequence of ignoring Checksum

    If the Checksum is not read or verified, the datagram may still be accepted but without error checking, risking corrupted data.
  3. Final Answer:

    The datagram may be accepted without error checking -> Option C
  4. Quick Check:

    Ignoring checksum skips error check but datagram accepted [OK]
Hint: Ignoring checksum skips error check, datagram still accepted [OK]
Common Mistakes:
  • Assuming datagram is rejected
  • Confusing checksum with port fields
  • Thinking length is affected
5. You need to design a simple application that sends small messages quickly without guaranteed delivery. Which UDP datagram feature makes it suitable for this?
hard
A. Automatic retransmission of lost packets
B. Fixed 8-byte header with no connection setup
C. Sequence numbers for ordered delivery
D. Built-in encryption for security

Solution

  1. Step 1: Identify UDP features for fast, simple messaging

    UDP uses a fixed 8-byte header and does not require connection setup, enabling quick transmission.
  2. Step 2: Eliminate incorrect features

    UDP does not provide sequence numbers, retransmission, or encryption by default.
  3. Final Answer:

    Fixed 8-byte header with no connection setup -> Option B
  4. Quick Check:

    UDP's simple header and no handshake enable fast messaging [OK]
Hint: UDP's simple header and no handshake enable fast messaging [OK]
Common Mistakes:
  • Confusing UDP with TCP features
  • Expecting retransmission or ordering
  • Assuming built-in security
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard