How to Create Magnet Link from Torrent Info Hash

A raw 40-character torrent info hash is the cryptographic identifier for a torrent’s metadata, and it can be easily converted into a fully functional magnet link using the standard Magnet URI scheme. By appending the 40-character hexadecimal string to the base BitTorrent uniform resource name (URN), you create a valid link that any modern BitTorrent client can recognize. While the bare hash is sufficient for clients operating on a Distributed Hash Table (DHT) network, you can also append optional parameters such as display names and tracker URLs to speed up peer discovery.

The absolute minimum requirement for a valid BitTorrent magnet link is the Magnet URI scheme prefix, the exact topic parameter (xt), and the BitTorrent Info Hash URN prefix (urn:btih:).

The standard syntax is: magnet:?xt=urn:btih:<40-character-hash>

Step-by-Step Construction

  1. Obtain the 40-Character Hash: Ensure the hash is a 40-character hexadecimal string (using characters 0-9 and a-f or A-F). Example: 4a7e93540974b7b2520da08b1a8dc7ec1cfc5c7d
  2. Prepend the Base URI: Place magnet:?xt=urn:btih: immediately before the hash without spaces.
  3. Assemble the Minimal Link: magnet:?xt=urn:btih:4a7e93540974b7b2520da08b1a8dc7ec1cfc5c7d

This minimal link can be pasted directly into clients like qBittorrent, Transmission, or Deluge to locate peers via the DHT network.

Adding Optional Parameters

To improve connection speed and user experience, you can append additional metadata using standard URL query formatting (&parameter=value). All values should be URL-encoded.

Complete Example

Combining the hash, a display name, and a public tracker results in a robust magnet link:

magnet:?xt=urn:btih:4a7e93540974b7b2520da08b1a8dc7ec1cfc5c7d&dn=Example+Torrent+Name&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce