Magnet is a URI scheme that defines the format of magnet links, a de facto standard for identifying files (URN) by their content, via cryptographic hash value rather than by their location.
Although magnet links can be used in a number of contexts, they are particularly useful in peer-to-peer file sharing networks because they allow resources to be referred to without the need for a continuously available host, and can be generated by anyone who already has the file, without the need for a central authority to issue them. This makes them popular for use as "guaranteed" search terms within the file sharing community where anyone can distribute a magnet link to ensure that the resource retrieved by that link is the one intended, regardless of how it is retrieved.
The standard for Magnet URIs was developed by Bitzi in 2002, partly as a "vendor- and project-neutral generalization" of the
freenet: URI schemes used by eDonkey2000 and Freenet, respectively, and attempts to follow official IETF URI standards as closely as possible. BitTorrent introduced the
btmh: protocol in 2020 as part of its BitTorrent v2 changes.
Magnet URIs consist of a series of one or more parameters, the order of which is not significant, formatted in the same way as query strings that ordinarily terminate HTTP URLs.
The following parameters are supported:
|xt||Exact Topic||URN containing file hash. This is the most crucial part of the magnet link, and is used to find and verify the specified file. The URN is specific to the protocol, so a file hash URN under btih (BitTorrent) would be completely different from the file hash URN for ed2k
|dn||Display Name||A filename to display to the user, for convenience.|
|xl||eXact Length||The file size, in bytes|
|tr||Address TRacker||Tracker URL; used to obtain resources for BitTorrent downloads without a need for DHT support. The value must be URL encoded.
|ws||Web Seed||The payload data served over HTTP(S)|
|as||Acceptable Source||Refers to a direct download from a web server. Regarded as only a fall-back source in case a client is unable to locate and/or download the linked-to file in its supported P2P network(s)
|xs||eXact Source||Either an HTTP (or HTTPS, FTP, FTPS, etc.) download source for the file pointed to by the Magnet link, the address of a P2P source for the file or the address of a hub (in the case of DC++), by which a client tries to connect directly, asking for the file and/or its sources. This field is commonly used by P2P clients to store the source, and may include the file hash.|
|kt||Keyword Topic||Specifies a string of search keywords to search for in P2P networks, rather than a particular file
|mt||Manifest Topic||Link to the metafile that contains a list of magneto (MAGMA – MAGnet MAnifest); i.e. a link to a list of links
|so||Select Only||Lists specific files torrent clients should download, indicated as individual or ranges (inclusive) of file indexes.
|x.pe||PEer||Specifies fixed peer addresses to connect to. Used to bootstrap discovery of peers in the absence of (e.g.) trackers or DHT.
The standard also allows for application-specific experimental parameters, which must begin with "x".
The xt parameter specifies the URN for a given p2p protocol. Its purpose is to provide a search parameter for finding the metadata to the torrent. This effectively acts as a replacement to a .torrent file, which itself contains the torrent metadata, by instead searching the p2p network (using the URN) for that metadata. Each protocol handles a URN uniquely; for example,
xt=urn:btih:FFC7E738EAA4CD4ECF51EC6FD669C6CDE2C281A8 uses the btih (BitTorrent v1 protocol), so a BitTorrent client can take the hash and lookup the torrent's metadata in the BitTorrent DHT. In the case of DHT the client searches through a set of pre-known nodes and requests the metadata for an infohash; those nodes will make the same request to other known nodes until eventually a swarm is found and returned.
xt also allows for a group setting. Multiple files can be included by adding a count number preceded by a dot (".") to each link parameter.
magnet:?xt.1=[ URN of the first file]&xt.2=[ URN of the second file]
xt=urn:tree:tiger:[ TTH Hash (Base32) ]
xt=urn:sha1:[ SHA-1 Hash (Base32) ]
xt=urn:bitprint:[ SHA-1 Hash (Base32) ].[ TTH Hash (Base32) ]
xt=urn:ed2k:[ ED2K Hash (Hex) ]
xt=urn:aich:[ aich Hash (Base32) ]
xt=urn:kzhash:[ Kazaa Hash (Hex) ]
xt=urn:btih:[ BitTorrent Info Hash (Hex) ]
btmh) to allow for torrents that can participate in both v1 and v2 swarms
xt=urn:btmh:[ BitTorrent Info Hash (Hex) ]
xt=urn:md5:[ MD5 Hash (Hex) ]
There are two types of download links that a Magnet link can include as a direct or backup source.
xs=http://[Client Address]:[Port of client]/uri-res/N2R?[ URN containing a file hash ]
xs=dchub://[hub address]:[hub port]
xs=http://cache.freebase.be/[ SHA-1 hash ]
xs=ed2kftp://[client address]:[client port]/[ed2k hash]/[file size]/
For experimental and self-complementing informal options, the prefix
x. followed by a chosen suffix letter can be used. These names are guaranteed to never be standardized.
x.[name of the new parameter]=[data of the new parameter (URL encoded)]
||No||dchub:[Note 1]||dchub:[Note 1]||No||No||Unknown|
(Same priority as xs)