Saturday, 7 November 2026

UDP (User Datagram Protocol): Header, Checksum, IPv4 Pseudoheader, Applications & MCQs

Computer Networks · Transport Layer · Lesson 04

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.

Tanenbaum + Forouzan18 MCQs8 FAQsNo external assets

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.

Key distinction: IP identifies the destination host; the UDP destination port identifies the receiving application/process. Transport-layer message boundaries are preserved in UDP: one send corresponds to one datagram rather than a continuous TCP byte stream.

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.

Bit 0Bit 15Bit 16Bit 31
Source Port16 bits
Destination Port16 bits
UDP Length16 bits
Checksum16 bits
Application data (0 or more bytes)
Original reconstruction of the standard UDP format: four 16-bit fields make an 8-byte header. The payload follows it and is not part of the 8-byte header.
4 fields × 16 bits = 64 bits = 8 bytes
Exam fact: UDP has no sequence number, acknowledgement number, window size or control flags in its header.

3. UDP Header Fields Explained

FieldSizePurposeExam clue
Source Port16 bitsIdentifies sender process, especially useful for a replyOften a temporary client port
Destination Port16 bitsSelects receiver process at destination hostOften a well-known server port
Length16 bitsByte count of UDP header plus UDP payloadMinimum valid value = 8 bytes
Checksum16 bitsDetects errors across pseudoheader + UDP header + dataOne'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.

Client
Port 52000
→
DNS server
UDP port 53
→
Reply
53 → 52000

The example client port 52000 is illustrative. Server port 53 is the customary DNS service port.

3.2 Length field

UDP Length (bytes) = 8 + Application Data Length (bytes)

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.

081631
Source IPv4 Address 32 bits
Destination IPv4 Address 32 bits
All zeros 8 bits
Protocol = 17 8 bits
UDP Length 16 bits
IPv4 pseudoheader reconstructed from Tanenbaum Figure 6-28 and Forouzan Figure 23.10. It supplies the IP source, IP destination, protocol number and UDP length.

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:

1. Build pseudoheader
→
2. Set checksum field to zero
→
3. Add 16-bit words
→
4. Wrap carries
→
5. Complement sum
Checksum = one's complement of the folded 16-bit sum

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.

0x1234 + 0x5678 = 0x68AC

Complement every bit:

~0x68AC (16 bits) = 0x9753

Checksum = 0x9753

This is only a two-word arithmetic demonstration. Real UDP uses all pseudoheader, header and data words.

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

Important textbook distinction: Tanenbaum's IPv4 UDP discussion correctly describes an omitted checksum field as 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

UDP Length = 8 + 7 = 15 bytes = 0x000F

Convert the pseudoheader, the UDP header (checksum initially zero), and the padded payload into 16-bit hexadecimal words.

Component16-bit words (hexadecimal)
Source IPv49912, 0869
Destination IPv4AB02, 0E0A
Zero + UDP protocol 170011
UDP length in pseudoheader000F
UDP source port043F
UDP destination port000D
UDP length in actual header000F
Checksum field during calculation0000
Data: TE, ST, IN, G + zero pad5445, 5354, 494E, 4700

Adding all these words with end-around carry produces:

Folded Sum = 0x96EB

Take the one's complement:

Checksum = 0xFFFF − 0x96EB = 0x6914

Final 16-bit UDP checksum = 0x6914.

Why is 0x000F present twice? The UDP length occurs in both the IPv4 pseudoheader and the actual UDP header. Both must be included in checksum arithmetic.

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.

  1. The application creates one message and supplies the destination IP and port.
  2. UDP adds its 8-byte header, including source and destination ports.
  3. IP encapsulates the UDP datagram in an IP packet and routes it toward the host.
  4. The destination IP layer passes the UDP datagram to UDP (IP protocol 17).
  5. UDP checks the datagram as applicable and delivers its payload to the destination application identified by the port.
Each animated object represents an independent datagram; the illustration does not imply all UDP datagrams always arrive.
Original concept animation illustrating port-directed independent UDP datagrams. Pure CSS, no external assets or script. Motion is disabled automatically when reduced motion is requested.

7.1 What UDP does not do

FunctionBuilt into UDP?Consequence
HandshakeNoNo UDP connection setup
Sequence numberingNoNo ordering guarantee
ACK and retransmissionNoApplications must handle recovery if needed
Flow controlNoNo UDP receiver-window mechanism
Congestion controlNoApplications need appropriate congestion behavior
Error detectionChecksumCorrupt 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.

ApplicationTypical UDP portWhy UDP fits
DNS query53Small request–response transactions; DNS can use TCP too
DHCP / BOOTP67 server, 68 clientHost configuration datagrams
TFTP69Simple file transfers with application-level acknowledgment/retry
NTP123Time synchronization exchanges
SNMP161Network management queries
SNMP notifications162Trap notifications
RTP mediaDynamic / negotiatedTiming-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

PropertyUDPTCP
ConnectionConnectionlessConnection-oriented
Minimum header8 bytes20 bytes
Data modelIndependent datagramsContinuous byte stream
Message boundariesPreservedNot preserved
SequencingNot built inSequence numbers
AcknowledgementNot built inYes
RetransmissionNot built inYes
Flow controlNot built inYes
Congestion controlNot built inYes
ChecksumYes; optional in ordinary IPv4 UDPMandatory
IP protocol number176

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.

UDP Length = 1200 + 8 = 1208 bytes

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.

Overhead = (8 / 1208) × 100 ≈ 0.6623%

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.

Payload = 1500 − 20 − 8 = 1472 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.

65,535 − 20 (IP) − 8 (UDP) = 65,507 bytes

Answer: 65,507 bytes of UDP application data

This is a theoretical IPv4 packet-size calculation; it does not mean the packet avoids fragmentation.

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.

FragmentIP payloadTotal IPv4 lengthOffset (8-byte units)MF
First1480 bytes1500 bytes01
Second528 bytes548 bytes1850

Answer: two fragments, offsets 0 and 185.

The UDP header appears in the first IP fragment. The receiver's IP layer reassembles fragments before passing the complete UDP datagram upward.

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.

UDP overhead = 8 / 1008 × 100 ≈ 0.794%
TCP overhead = 20 / 1020 × 100 ≈ 1.961%

Answer: UDP has 12 fewer transport-header bytes in this comparison.

Real application efficiency also depends on ACKs, retransmissions and traffic patterns.

11. Exam Traps and Fast Revision

Often confusedCorrect exam fact
UDP checksum vs reliabilityChecksum detects errors; UDP does not retransmit automatically.
UDP Length vs payload lengthUDP Length includes the 8-byte header.
IP protocol vs UDP portProtocol 17 identifies UDP to IP; port identifies receiving application.
Pseudoheader vs transmitted headerPseudoheader is used in checksum arithmetic, not transmitted as another UDP header.
Checksum paddingA zero byte may be included in calculation only; it is not an extra payload byte.
UDP and sequence numbersThere are no UDP sequence numbers; RTP has its own sequence field.
DNS transportDNS commonly uses UDP, but TCP is also supported.
Checksum omitted under IPv4UDP 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?

  1. 4 bytes
  2. 8 bytes
  3. 16 bytes
  4. 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. 1
  2. 6
  3. 17
  4. 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?

  1. 8
  2. 16
  3. 24
  4. 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?

  1. Source port
  2. Destination port
  3. Length
  4. 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?

  1. 900
  2. 908
  3. 920
  4. 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?

  1. It contains a sequence number
  2. It contains a 32-bit ACK field
  3. It contains no acknowledgement-number field
  4. 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?

  1. Source IP address
  2. Destination IP address
  3. Protocol number
  4. 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?

  1. Drop the last byte
  2. Append a zero byte for checksum arithmetic only
  3. Append a one byte to the transmitted payload
  4. 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?

  1. Ordered delivery
  2. Retransmissions
  3. Flow control
  4. 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?

  1. 1472 bytes
  2. 1460 bytes
  3. 1480 bytes
  4. 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?

  1. HTTP
  2. NTP
  3. SSH
  4. FTP
Show answer and explanation

Answer: B — NTP. Network Time Protocol commonly uses UDP port 123.

Q12. Which service commonly uses UDP port 53?

  1. DNS
  2. SMTP
  3. HTTPS
  4. 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?

  1. 0xFFFF
  2. 0x0000
  3. 0x00FF
  4. 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?

  1. Checksum can always be omitted
  2. Checksum is generally required
  3. IPv6 UDP has a 12-byte header
  4. 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?

  1. 1200 bytes
  2. 1208 bytes
  3. 1216 bytes
  4. 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?

  1. TCP options
  2. IPv4 pseudoheader
  3. Ethernet trailer
  4. 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?

  1. Resends it automatically
  2. Sends a TCP ACK
  3. Discards it
  4. 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?

  1. 0x68AC
  2. 0x9753
  3. 0xFFFF
  4. 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

ReferenceRelevant 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 alignmentAPPSC 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.

Lesson 04 complete. Next in the series: TCP — Service Model, Segment Header, Flags, TCP Options and Window Fields (Lesson 05).
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.

NumPy Tutorial

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top