UDP Tracker Connection Request Binary Structure

This article provides a technical overview of the binary structure of a connection request packet in the BitTorrent UDP Tracker Protocol (BEP 15). Before a BitTorrent client can announce or scrape torrent data via UDP, it must establish a temporary connection with the tracker. Below is the detailed breakdown of the exact byte layout, field definitions, data types, and endianness required to construct a valid connection request.

Packet Overview and Endianness

A UDP tracker connection request is a fixed-size packet consisting of 16 bytes (128 bits).

All values in the BitTorrent UDP tracker protocol are transmitted in network byte order (Big-Endian).

Binary Layout

The 16-byte packet is partitioned into three distinct fields:

Byte Offset Field Name Data Type Size (Bytes) Description / Value
0 - 7 protocol_id 64-bit unsigned integer 8 Magic constant: 0x41727101980
8 - 11 action 32-bit unsigned integer 4 Action identifier: 0 (Connect)
12 - 15 transaction_id 32-bit unsigned integer 4 Random identifier generated by the client

Field Details

1. Protocol ID (Bytes 0–7)

2. Action (Bytes 8–11)

3. Transaction ID (Bytes 12–15)

Example Packet Representation

A raw hexadecimal representation of a valid connection request appears as follows:

00 00 04 17 27 10 19 80 00 00 00 00 7a 3f 1c 2b
|---------------------| |---------| |---------|
      protocol_id         action   transaction_id
       (8 bytes)         (4 bytes)    (4 bytes)

Upon receiving this request, the UDP tracker validates the protocol_id and action, generates a 64-bit connection_id, and echoes back the transaction_id in a 16-byte response packet.