UDP (User Datagram Protocol): Header, Checksum, IPv4 Pseudoheader, Applications and MCQs
A complete UDP tutorial with field-by-field diagrams, a real 16-bit checksum calculation, IPv4 pseudoheader, operation, DNS and RTP examples, solved numericals and exam questions for APPSC Assistant Professor, RGUKT Lecturer, UGC NET and GATE.
Concept in one line: UDP is a lightweight, connectionless transport protocol that lets one application send a self-contained datagram to another using port numbers. It adds an 8-byte header and checksum-based error detection, but does not itself guarantee delivery, sequencing, flow control or retransmission.
1. UDP Fundamentals — Why Does UDP Exist?
UDP (User Datagram Protocol) is the Internet's simple, connectionless transport protocol. Tanenbaum notes that it provides a way to send encapsulated datagrams without connection setup; Forouzan emphasizes its role in process-to-process communication.
Connectionless
Each user datagram stands alone. The sender does not conduct a TCP-style three-way handshake.
Small header
Every UDP datagram carries a fixed 8-byte header, regardless of its payload length.
Best-effort delivery
Datagrams may be lost, duplicated, delayed or delivered out of order. UDP does not automatically correct these events.
UDP does provide source and destination ports, so data reaches the correct application on the correct host, and a checksum to detect certain transmission errors. Reliability and timing control, when required, can be added by the application.
2. UDP Header Format — Exactly 8 Bytes
The UDP header, drawn in Tanenbaum's Figure 6-27 and Forouzan's Figure 23.9, has four 16-bit fields. It is arranged in two 32-bit rows.
3. UDP Header Fields Explained
| Field | Size | Purpose | Exam clue |
|---|---|---|---|
| Source Port | 16 bits | Identifies sender process, especially useful for a reply | Often a temporary client port |
| Destination Port | 16 bits | Selects receiver process at destination host | Often a well-known server port |
| Length | 16 bits | Byte count of UDP header plus UDP payload | Minimum valid value = 8 bytes |
| Checksum | 16 bits | Detects errors across pseudoheader + UDP header + data | One's-complement arithmetic |
3.1 Source and destination port numbers
Ports are 16-bit integers from 0 through 65,535. For example, a DNS query may originate from a client port such as 52000 and target the server's UDP port 53. The server normally replies to the client's source port.
Port 52000
UDP port 53
53 → 52000
3.2 Length field
For ordinary IPv4 without IP options, the IPv4 packet length cannot exceed 65,535 bytes. Subtracting a 20-byte IPv4 header gives the commonly cited maximum UDP datagram length of 65,515 bytes, or 65,507 bytes of UDP payload. This is a protocol size limit, not a recommended send size; path MTUs are usually much smaller.
3.3 Checksum field
Checksumming is a form of error detection; it does not retransmit, correct or reorder packets. The calculation includes the UDP header, the UDP data and an IP pseudoheader. It uses 16-bit one's-complement summation.
4. IPv4 Pseudoheader for UDP Checksum
The IPv4 pseudoheader supplies network context to the checksum algorithm. It is 12 bytes long and is only a conceptual input to checksum calculation—not an extra eight or twelve bytes inserted into the transmitted UDP header.
Why include IP addresses?
It helps reveal corruption or misdelivery involving the source or destination IP address.
Why include protocol number 17?
It ties the datagram to UDP instead of another transport protocol sharing IP delivery.
The complete bytes summed are: IPv4 pseudoheader (12 bytes) + UDP header (8 bytes) + UDP data, with a temporary zero pad byte when needed to make the data an even number of bytes.
5. How the UDP Checksum Works
The textbook checksum method is based on 16-bit one's-complement addition. The basic steps are:
End-around carry: when addition produces a carry beyond the low 16 bits, add that carry back into the low 16-bit value until no carry remains.
Mini-example: 16-bit arithmetic
Let two 16-bit words be 0x1234 and 0x5678.
Complement every bit:
Checksum = 0x9753
5.1 What happens at the receiver?
The receiver checks the data using the checksum. In a normal validated datagram, the one's-complement sum of all words including the checksum equals 0xFFFF (equivalently, the complemented result is zero). A mismatch indicates a corrupted datagram, which UDP discards.
5.2 Optional checksum and the zero-value trap
0x0000; if the actual checksum computes to zero, it is transmitted as 0xFFFF. Forouzan's fourth-edition text appears to reverse this in its optional-checksum paragraph. For exam numericals, distinguish an omitted IPv4 checksum (0x0000) from a computed zero checksum (0xFFFF). In ordinary UDP over IPv6, checksumming is required, subject to narrowly defined specialized exceptions.6. Fully Worked UDP Checksum Example (Forouzan)
Forouzan's Example 23.2 uses a UDP datagram carrying the seven-character text TESTING. The following is an independently typeset arithmetic walkthrough of that example.
IP and UDP details
Source IPv4: 153.18.8.105
Destination IPv4: 171.2.14.10
Protocol: 17
Source port: 1087
Destination port: 13
Payload details
Data: TESTING (7 bytes)
UDP header: 8 bytes
UDP length: 15 bytes
Checksum pad: one zero byte, not transmitted as payload
Convert the pseudoheader, the UDP header (checksum initially zero), and the padded payload into 16-bit hexadecimal words.
| Component | 16-bit words (hexadecimal) |
|---|---|
| Source IPv4 | 9912, 0869 |
| Destination IPv4 | AB02, 0E0A |
| Zero + UDP protocol 17 | 0011 |
| UDP length in pseudoheader | 000F |
| UDP source port | 043F |
| UDP destination port | 000D |
| UDP length in actual header | 000F |
| Checksum field during calculation | 0000 |
| Data: TE, ST, IN, G + zero pad | 5445, 5354, 494E, 4700 |
Adding all these words with end-around carry produces:
Take the one's complement:
Final 16-bit UDP checksum = 0x6914.
7. UDP Operation — From Application to Application
Forouzan describes independent datagram transmission, encapsulation/decapsulation, queues and multiplexing/demultiplexing. UDP does not establish or release a transport connection.
- The application creates one message and supplies the destination IP and port.
- UDP adds its 8-byte header, including source and destination ports.
- IP encapsulates the UDP datagram in an IP packet and routes it toward the host.
- The destination IP layer passes the UDP datagram to UDP (IP protocol 17).
- UDP checks the datagram as applicable and delivers its payload to the destination application identified by the port.
52000
port 53
7.1 What UDP does not do
| Function | Built into UDP? | Consequence |
|---|---|---|
| Handshake | No | No UDP connection setup |
| Sequence numbering | No | No ordering guarantee |
| ACK and retransmission | No | Applications must handle recovery if needed |
| Flow control | No | No UDP receiver-window mechanism |
| Congestion control | No | Applications need appropriate congestion behavior |
| Error detection | Checksum | Corrupt datagrams may be detected and discarded |
8. UDP Applications and Common Ports
UDP is common in small query/reply exchanges and latency-sensitive applications. Examples from the two textbooks include DNS, RPC and RTP. Forouzan also lists common UDP service ports.
| Application | Typical UDP port | Why UDP fits |
|---|---|---|
| DNS query | 53 | Small request–response transactions; DNS can use TCP too |
| DHCP / BOOTP | 67 server, 68 client | Host configuration datagrams |
| TFTP | 69 | Simple file transfers with application-level acknowledgment/retry |
| NTP | 123 | Time synchronization exchanges |
| SNMP | 161 | Network management queries |
| SNMP notifications | 162 | Trap notifications |
| RTP media | Dynamic / negotiated | Timing-sensitive audio/video payloads over UDP |
DNS query example
A resolver may send a UDP question to a name server on port 53 and get a response with an IP address. This avoids a TCP connection setup for ordinary exchanges.
RTP example
Real-time audio/video often uses RTP over UDP. RTP adds timestamps and sequence numbering, which are RTP functions—not capabilities of the UDP header itself.
RPC (Remote Procedure Call) can also use UDP as a low-overhead transport, but the RPC system must handle lost requests, duplicates and the possibility of repeating non-idempotent operations.
9. UDP vs TCP — Exam Comparison
| Property | UDP | TCP |
|---|---|---|
| Connection | Connectionless | Connection-oriented |
| Minimum header | 8 bytes | 20 bytes |
| Data model | Independent datagrams | Continuous byte stream |
| Message boundaries | Preserved | Not preserved |
| Sequencing | Not built in | Sequence numbers |
| Acknowledgement | Not built in | Yes |
| Retransmission | Not built in | Yes |
| Flow control | Not built in | Yes |
| Congestion control | Not built in | Yes |
| Checksum | Yes; optional in ordinary IPv4 UDP | Mandatory |
| IP protocol number | 17 | 6 |
Remember that smaller overhead does not guarantee a faster application. Packet loss and application-level recovery can change the result.
10. Solved UDP Numericals
Example 1 — UDP length
A message contains 1200 bytes of application data. Find the UDP length.
Answer: 1208 bytes
Example 2 — Header overhead percentage
For the 1200-byte message above, compute the fraction of the UDP datagram occupied by the UDP header.
Answer: approximately 0.66%
Example 3 — Maximum unfragmented UDP payload
Assume Ethernet MTU = 1500 bytes, an IPv4 header without options = 20 bytes and UDP header = 8 bytes.
Answer: 1472 bytes
Example 4 — Maximum ordinary IPv4 UDP payload
Assume the IPv4 Total Length field permits 65,535 bytes and the IPv4 header has no options.
Answer: 65,507 bytes of UDP application data
Example 5 — IPv4 fragmentation of a UDP datagram
Application data = 2000 bytes, UDP header = 8 bytes, IPv4 header = 20 bytes and each outgoing link permits an MTU of 1500 bytes. Assume fragmentation is allowed and no IP options.
IP payload before fragmentation = 2008 bytes; the first fragment can carry 1500 − 20 = 1480 bytes of IP payload (including the UDP header). Remaining IP payload = 2008 − 1480 = 528 bytes.
| Fragment | IP payload | Total IPv4 length | Offset (8-byte units) | MF |
|---|---|---|---|---|
| First | 1480 bytes | 1500 bytes | 0 | 1 |
| Second | 528 bytes | 548 bytes | 185 | 0 |
Answer: two fragments, offsets 0 and 185.
Example 6 — UDP versus TCP header overhead
For 1000 application bytes, ignoring IP and link headers: UDP requires 8 transport-header bytes, while a minimal TCP segment requires 20.
Answer: UDP has 12 fewer transport-header bytes in this comparison.
11. Exam Traps and Fast Revision
| Often confused | Correct exam fact |
|---|---|
| UDP checksum vs reliability | Checksum detects errors; UDP does not retransmit automatically. |
| UDP Length vs payload length | UDP Length includes the 8-byte header. |
| IP protocol vs UDP port | Protocol 17 identifies UDP to IP; port identifies receiving application. |
| Pseudoheader vs transmitted header | Pseudoheader is used in checksum arithmetic, not transmitted as another UDP header. |
| Checksum padding | A zero byte may be included in calculation only; it is not an extra payload byte. |
| UDP and sequence numbers | There are no UDP sequence numbers; RTP has its own sequence field. |
| DNS transport | DNS commonly uses UDP, but TCP is also supported. |
| Checksum omitted under IPv4 | UDP checksum field = 0x0000, not 0xFFFF. |
8 bytes
UDP fixed header
17
UDP's IP protocol number
4 fields
All 16-bit fields
12. 18 APPSC / UGC NET / GATE-Style MCQs
These are original practice questions based on the textbook topics. They are not claimed to be verbatim previous-year questions. Expand an answer to check both the correct choice and its explanation.
Q1. What is the minimum header length of UDP?
- 4 bytes
- 8 bytes
- 16 bytes
- 20 bytes
Show answer and explanation
Answer: B — 8 bytes. UDP has four 16-bit fields: 4 × 16 = 64 bits = 8 bytes.
Q2. Which IP protocol number identifies UDP?
- 1
- 6
- 17
- 47
Show answer and explanation
Answer: C — 17. UDP has IP protocol number 17; TCP is 6.
Q3. How many bits are allocated to the destination port?
- 8
- 16
- 24
- 32
Show answer and explanation
Answer: B — 16. The UDP source and destination port fields are each 16 bits.
Q4. Which UDP field includes both header and user data?
- Source port
- Destination port
- Length
- Checksum
Show answer and explanation
Answer: C — Length. UDP Length = 8-byte header + UDP payload length.
Q5. A UDP message carries 900 bytes of data. What is its UDP length?
- 900
- 908
- 920
- 928
Show answer and explanation
Answer: B — 908. Add the fixed 8-byte UDP header: 900 + 8 = 908 bytes.
Q6. Which statement about the UDP header is correct?
- It contains a sequence number
- It contains a 32-bit ACK field
- It contains no acknowledgement-number field
- It contains a congestion window
Show answer and explanation
Answer: C — It contains no acknowledgement-number field. UDP has four fields only: source port, destination port, length, checksum.
Q7. Which field is NOT part of the IPv4 pseudoheader for the UDP checksum?
- Source IP address
- Destination IP address
- Protocol number
- Ethernet MAC address
Show answer and explanation
Answer: D — Ethernet MAC address. The IPv4 pseudoheader uses source/destination IP addresses, zero byte, protocol, and UDP length.
Q8. What must be done if UDP payload data has an odd number of bytes before checksum calculation?
- Drop the last byte
- Append a zero byte for checksum arithmetic only
- Append a one byte to the transmitted payload
- Divide the data into 8-bit words
Show answer and explanation
Answer: B — Append a zero byte for checksum arithmetic only. A zero pad byte is used for 16-bit summation. It is not part of the transmitted application data.
Q9. Which technique does UDP provide by itself?
- Ordered delivery
- Retransmissions
- Flow control
- Port-based process demultiplexing
Show answer and explanation
Answer: D — Port-based process demultiplexing. UDP uses destination ports to send datagrams to applications; it has no built-in flow control, ordering, or retransmission.
Q10. What is the UDP payload limit for one unfragmented IPv4 packet on a 1500-byte MTU with a 20-byte IP header?
- 1472 bytes
- 1460 bytes
- 1480 bytes
- 1500 bytes
Show answer and explanation
Answer: A — 1472 bytes. 1500 − 20 (IPv4) − 8 (UDP) = 1472 bytes.
Q11. Which protocol commonly uses UDP port 123?
- HTTP
- NTP
- SSH
- FTP
Show answer and explanation
Answer: B — NTP. Network Time Protocol commonly uses UDP port 123.
Q12. Which service commonly uses UDP port 53?
- DNS
- SMTP
- HTTPS
- IMAP
Show answer and explanation
Answer: A — DNS. DNS commonly uses UDP port 53 for queries and responses, but it can also use TCP.
Q13. In IPv4, an omitted UDP checksum is indicated by which field value?
- 0xFFFF
- 0x0000
- 0x00FF
- 0x0101
Show answer and explanation
Answer: B — 0x0000. Per UDP protocol definition, zero indicates no checksum for IPv4. A computed zero checksum is transmitted as 0xFFFF.
Q14. Which statement is correct for IPv6 UDP in the normal case?
- Checksum can always be omitted
- Checksum is generally required
- IPv6 UDP has a 12-byte header
- IPv6 UDP includes a sequence number
Show answer and explanation
Answer: B — Checksum is generally required. For normal UDP over IPv6, a UDP checksum is required; specialized exceptions exist for certain tunnels.
Q15. Given UDP length 1208 bytes, what is the application data length?
- 1200 bytes
- 1208 bytes
- 1216 bytes
- 1192 bytes
Show answer and explanation
Answer: A — 1200 bytes. UDP payload length = UDP length − 8 = 1200 bytes.
Q16. Which header portion is conceptually added for checksum arithmetic but is not part of the transmitted UDP header?
- TCP options
- IPv4 pseudoheader
- Ethernet trailer
- ICMP header
Show answer and explanation
Answer: B — IPv4 pseudoheader. The pseudoheader contributes IP addressing and protocol context only to the checksum calculation.
Q17. What does a UDP receiver ordinarily do with a datagram that fails its checksum?
- Resends it automatically
- Sends a TCP ACK
- Discards it
- Opens a connection
Show answer and explanation
Answer: C — Discards it. UDP detects corruption and discards an invalid datagram; retransmission is not a built-in UDP feature.
Q18. A 16-bit one’s-complement sum (after end-around carry) is 0x68AC. What is the checksum?
- 0x68AC
- 0x9753
- 0xFFFF
- 0x0000
Show answer and explanation
Answer: B — 0x9753. Bitwise complement 0x68AC gives 0x9753.
13. Frequently Asked Questions
What is UDP in computer networks?
UDP is a connectionless transport protocol that delivers independent application datagrams using port numbers and a fixed 8-byte header. It does not provide delivery, ordering, or retransmission guarantees.
What is the size of the UDP header?
The UDP header is always 8 bytes (64 bits), consisting of four 16-bit fields.
How does UDP differ from TCP?
UDP sends independent datagrams without a connection handshake or built-in reliable delivery. TCP establishes a connection and provides reliable, ordered byte-stream delivery with flow and congestion control.
What is the purpose of the UDP pseudoheader?
It ties the checksum to the source and destination IP addresses, protocol number and UDP length so misdelivery or corruption of this context can be detected.
Is the UDP checksum optional?
The textbook discusses optional checksums for UDP over IPv4: a zero checksum field indicates omission. UDP checksums are normally mandatory over IPv6, subject to specialized exceptions.
Does UDP retransmit lost datagrams?
No. If an application needs retransmission or acknowledgements, it must arrange those functions above UDP or select a protocol providing reliability.
Which applications use UDP?
Common examples include DNS queries, DHCP, TFTP, NTP, SNMP, and real-time media transports using RTP over UDP. Individual applications may also support TCP or other transports.
Is UDP always faster than TCP?
Not necessarily. UDP has a smaller transport header and no connection setup, but total application performance depends on workload, congestion, loss and how reliability is implemented.
14. Textbook References and Syllabus Fit
| Reference | Relevant sections |
|---|---|
| Tanenbaum & Wetherall, Computer Networks, 5th ed. | 6.4.1 Introduction to UDP, pp. 541–543; 6.4.2 Remote Procedure Call, pp. 543–546; 6.4.3 Real-Time Transport Protocols, pp. 546–551. Figures 6-27, 6-28. |
| Forouzan, Data Communications and Networking, 4th ed. | 23.2 User Datagram Protocol, pp. 709–715. Figures 23.9–23.11 and Example 23.2. |
| Recruitment syllabus alignment | APPSC Assistant Professor IT Engineering and RGUKT IT explicitly list TCP/UDP and sockets; APPSC Computer Science & Applications lists reference models and congestion control, making UDP an important supporting topic. |
All explanatory figures in this article are newly drawn, and all examination questions except the attributed worked checksum example are original educational examples. Source details are educational references, not claims of official exam questions.
For exam practice, first memorize the 8-byte UDP header, then learn the IPv4 pseudoheader and the 16-bit one's-complement checksum.
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.