---
title: "UDP segment structure"
subject: "Computer Networks and Security"
chapter: 5
key: "semester_7/computer_networks_and_security:udp-segment-structure"
source: https://www.bctengineer.com/q/semester_7/computer_networks_and_security/udp-segment-structure
site: BCT Engineering
---

# UDP segment structure

Computer Networks and Security · Chapter 5: Transport Layer

- Asked in: 2070 Chaitra, 8 marks
- Video: [Lec-75: UDP (User Datagram Protocol) header in Computer Networks in Hindi](https://www.youtube.com/watch?v=HF_znV8x9a0) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/computer_networks_and_security/udp-segment-structure
- Whole chapter: https://www.bctengineer.com/md/semester_7/computer_networks_and_security/chapter-5

## Question

Explain the UDP segment structure. Illustrate your answer with appropriate figures.

## Short answer

UDP segment has an 8-byte fixed header: source port, destination port, length, and checksum. The checksum covers a pseudo-header, UDP header, and data for error detection. No connection setup, retransmission, or flow control; message boundaries are preserved. Used by DNS, DHCP, and real-time applications.

## Answer

**UDP (User Datagram Protocol, RFC 768)** is a simple connectionless transport protocol. It adds only port numbers, length and an optional error check to IP. The unit is called a **user datagram**.

#### UDP header (8 bytes fixed)
```text
 0                 15 16                31
+--------------------+--------------------+
|   Source port      | Destination port   |
+--------------------+--------------------+
|   Length           |   Checksum         |
+--------------------+--------------------+
|            Data (application)           |
+-----------------------------------------+
```

| Field | Size | Meaning |
|---|---|---|
| Source port | 16 bits | Port of sender (optional, 0 if unused) |
| Destination port | 16 bits | Port of receiving application |
| Length | 16 bits | Header + data in bytes (minimum 8) |
| Checksum | 16 bits | Covers header, data and a pseudo-header; optional in IPv4, mandatory in IPv6 |

#### Checksum and pseudo-header
The checksum is the 16-bit one's complement of the one's complement sum of a pseudo-header, the UDP header and the data. The pseudo-header is not transmitted; it protects against wrong delivery.

```text
+-------------------------------+
| Source IP address (32)        |
| Destination IP address (32)   |
| Zero (8)| Protocol=17| UDP len|
+-------------------------------+
```

#### Encapsulation
```text
[ Ethernet hdr | IP hdr | UDP hdr | Data | trailer ]
```
UDP data length can be at most 65,535 − 8 = 65,527 bytes (65,507 with the 20-byte IP header).

#### Features
- Connectionless, no handshake, no retransmission, no flow or congestion control.
- Message boundaries preserved. Used by DNS (53), DHCP (67/68), SNMP (161), TFTP (69), RTP and VoIP.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the fixed size of the UDP header and its fields?
   A. 20 bytes with 5 fields
   B. 8 bytes: source port, destination port, length, checksum
   C. 12 bytes with sequence numbers
   D. 8 bytes: ports, sequence, checksum
   Answer: B. UDP header is 8 bytes with four 16-bit fields. (Key point: Header size)

2. The UDP Length field gives:
   A. Data length only
   B. Header plus data in bytes (minimum 8)
   C. Pseudo-header length
   D. Number of datagrams
   Answer: B. Length covers header and data, so the minimum is 8. (Key point: Length field)

3. What is the purpose of the pseudo-header in the UDP checksum?
   A. It is transmitted to carry addresses
   B. It protects against wrong delivery and is not transmitted
   C. It encrypts the data
   D. It holds port numbers
   Answer: B. The pseudo-header (IPs, zero, protocol 17, length) is used in the checksum only. (Key point: Pseudo-header)

4. Regarding the UDP checksum:
   A. Optional in IPv4, mandatory in IPv6
   B. Mandatory in IPv4, optional in IPv6
   C. Optional in both
   D. Absent in both
   Answer: A. The checksum may be omitted in IPv4 but is required in IPv6. (Key point: Checksum rules)

## Related in Computer Networks and Security

- [Firewall, its need and types](https://www.bctengineer.com/question.md?key=semester_7%2Fcomputer_networks_and_security%3Afirewall-types-working) — Computer Networks and Security, chapter 8, asked 7×
- [IPv6 datagram format](https://www.bctengineer.com/question.md?key=semester_7%2Fcomputer_networks_and_security%3Aipv6-datagram-format) — Computer Networks and Security, chapter 7, asked 2×
- [Proxy server and bandwidth reduction](https://www.bctengineer.com/question.md?key=semester_7%2Fcomputer_networks_and_security%3Aproxy-server-bandwidth) — Computer Networks and Security, chapter 6

## Related in other subjects

- [Declaration vs definition; C program structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adeclaration-definition-structure-of-c) — Computer Programming, chapter 3
- [VLSM preventing IP address loss](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Avlsm-prevents-ip-loss) — Internet and Intranet, chapter 2
- [Combining two identical radar transmitters](https://www.bctengineer.com/question.md?key=semester_7%2Frf_and_microwave_engineering%3Atwo-radar-transmitters-combining) — RF and Microwave Engineering, chapter 4, asked 2×
- [DMA active and idle cycles](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Adma-cycles-disadvantages) — Instrumentation II, chapter 1
