How the XT Parameter Identifies Hashes in Magnet Links
Magnet links allow peer-to-peer networks to locate and share files
decentralized without requiring a physical .torrent file.
At the core of this system is the xt parameter, which
stands for “Exact Topic.” This parameter contains a standardized Uniform
Resource Name (URN) that holds the exact cryptographic hash of the
content, enabling BitTorrent clients to search the Distributed Hash
Table (DHT), discover peers, and cryptographically verify data integrity
during downloads.
The Structure of the XT Parameter
The xt parameter is a key-value pair formatted within a
standard Uniform Resource Identifier (URI) query string. A typical
BitTorrent xt parameter appears as:
xt=urn:btih:<hash>
This string is composed of three distinct components:
urn:(Uniform Resource Name): Specifies that the identifier represents a persistent, location-independent resource name rather than a network address.btih(BitTorrent Info Hash): Identifies the target namespace and algorithm scheme.btihindicates the standard BitTorrent v1 info-hash.<hash>: The unique mathematical fingerprint generated from the.torrentmetadata (specifically theinfodictionary).
Cryptographic Encodings: Hexadecimal vs. Base32
BitTorrent v1 relies on the SHA-1 cryptographic hashing algorithm to
produce a 160-bit (20-byte) hash. Inside the xt parameter,
this raw binary hash is encoded in one of two text-based
representations:
- Hexadecimal (Base16): A 40-character alphanumeric
string containing characters
0-9anda-f(e.g.,xt=urn:btih:4a8b7...). - Base32: A 32-character string using uppercase
letters
A-Zand numbers2-7(e.g.,xt=urn:btih:JJEXO...).
BitTorrent clients automatically detect the length of the string—40 characters for Hex or 32 for Base32—and decode it back into the original 20-byte binary sequence.
BitTorrent v2 and Multihash Support
Modern magnet links also support BitTorrent v2 specifications via the
btmh (BitTorrent Multihash) identifier:
xt=urn:btmh:<multihash>
Unlike v1, BitTorrent v2 utilizes SHA-256 (a 256-bit hash) formatted
according to the Multihash standard. The Multihash format prepends
metadata describing the hashing function and length directly to the hash
string, allowing the xt parameter to remain
algorithm-agnostic and adapt to future cryptographic standards.
How Peers Use the XT Hash
Once decoded, the hash inside the xt parameter serves
two primary functions:
- Peer Discovery: The client uses the hash as a lookup key across the Distributed Hash Table (DHT) and peer-exchange networks to query for other nodes announcing that exact same hash.
- Data Verification: As pieces of the payload are downloaded from various peers, the client hashes the received data and compares it to the piece hashes linked to the master info-hash. If the calculated hash does not match, the corrupt or tampered data is discarded.