Skip to content

What is libtorrent? The BitTorrent library inside many apps

Discover what libtorrent is, how Rasterbar's C++ library powers clients like qBittorrent, and how sequential downloading enables video streaming.

In short

  • libtorrent is a high-performance open-source C++ library implementing the BitTorrent protocol.
  • Created by Arvid Norberg, it powers popular clients like qBittorrent, Deluge, and Tribler.
  • Sequential downloading overrides rarest-first piece selection to let video players stream files during download.
  • The library handles trackerless DHT lookups, peer exchange (PEX), and micro transport protocol (uTP).
On this page
  1. What is libtorrent-rasterbar, and who maintains it?
  2. Which applications rely on libtorrent?
  3. How libtorrent differs from libtransmission
  4. Rarest-first vs sequential downloading: how torrent streaming works
  5. Decentralized swarms: how DHT and magnet links operate
  6. Real-time media streaming in MacLC
  7. The legal reality of BitTorrent and open media

libtorrent is a high-performance, open-source C++ library that implements the BitTorrent peer-to-peer file sharing protocol. Created by Swedish software engineer Arvid Norberg, it acts as the underlying networking, piece verification, and data storage engine behind many of the world’s most widely used desktop torrent clients, including qBittorrent, Deluge, and modern media streaming players.

While end users interact with graphical buttons, progress bars, and search fields, the complex engineering required to communicate with thousands of worldwide peers happens invisibly inside libtorrent. Understanding its architecture reveals how peer-to-peer networks work and how modern video players can stream video files without waiting hours for downloads to complete.

What is libtorrent-rasterbar, and who maintains it?

The project—formally known as libtorrent-rasterbar to distinguish it from older, unrelated libraries—was initiated by Arvid Norberg in 2002 under Rasterbar Software. Developed continuously for over two decades, it has evolved into one of the most mature, feature-complete peer-to-peer protocol implementations in existence.

libtorrent is licensed under the permissive BSD 3-Clause License (with portions covered by the Boost Software License), making it freely accessible for both open-source and proprietary software. The project releases regular updates through its public repository on GitHub, with stable version 2.1.2 representing the modern standard for high-throughput desktop clients.

Architecturally, libtorrent manages the entire lifecycle of peer-to-peer communication:

  • Disk I/O and Caching: It utilizes asynchronous multi-threaded disk architectures to ensure that writing hundreds of incoming data blocks to solid-state or mechanical drives never stalls the network thread.
  • Bandwidth Management: It provides granular rate limiters, token-bucket bandwidth allocators, and automatic transport management through uTP (Micro Transport Protocol), which prevents torrent traffic from congesting home Wi-Fi networks.
  • Cryptographic Integrity: It verifies incoming data blocks against SHA-1 or SHA-256 hashes defined in the torrent metadata, immediately discarding corrupted or maliciously altered packets.

Which applications rely on libtorrent?

Rather than writing tens of thousands of lines of low-level networking code to implement BitTorrent Enhancement Proposals (BEPs), software developers embed libtorrent as a shared dependency. Prominent applications built on libtorrent include:

  • qBittorrent: The leading cross-platform open-source torrent client worldwide relies on libtorrent for all network and storage operations, wrapping it in a clean Qt interface.
  • Deluge: A popular modular, lightweight client that connects a Python user interface to libtorrent’s C++ core.
  • Tribler: A decentralized peer-to-peer research client developed by Delft University of Technology that uses libtorrent for content discovery and download management.
  • MacLC: An open-source media player for Apple Silicon that uses libtorrent 2.1 to stream video files sequentially from magnet links and torrent files with zero external software required.

Users on macOS can also install the standalone library and its Python bindings via Homebrew by running brew install libtorrent-rasterbar.

How libtorrent differs from libtransmission

When discussing torrent engines on macOS, users frequently compare libtorrent with libtransmission, the engine powering the famous Transmission client.

While both libraries implement the BitTorrent protocol efficiently, their engineering goals diverge:

Feature & Philosophy libtorrent (Rasterbar) libtransmission
Primary Language Modern C++ (C++17 / Boost) C (C11)
Primary Goal Feature completeness, max throughput, deep API Extreme minimalism, tiny memory footprint
Piece Prioritization Granular per-piece, per-file, and deadline-based Basic high / normal / low piece priority
BitTorrent v2 (BEP 52) Full native support with Merkle tree verification Selective / gradual adoption
Streaming Capabilities Advanced sequential streaming with deadline scheduling Standard batch downloading

libtransmission is celebrated for its lightweight footprint, making it ideal for headless home servers, embedded network-attached storage (NAS) boxes, and minimalist desktop utilities.

libtorrent, by contrast, focuses on throughput and depth. It offers granular piece-deadline APIs, sophisticated peer scoring, and robust support for the latest protocol specifications, making it the preferred choice for rich clients and applications that require on-demand media streaming.

Rarest-first vs sequential downloading: how torrent streaming works

To understand how video streaming works over BitTorrent, you must understand how swarms distribute data.

In traditional BitTorrent downloading, clients follow the rarest-first algorithm. The client queries connected peers to find out which pieces of a file are least common in the swarm, downloading those pieces first. This strategy is vital for swarm health: it distributes rare data widely, prevents bottlenecks, and ensures that files remain downloadable even if the original seeders disconnect. Learn more about swarm dynamics in our guide to seeders vs leechers.

Animation

Where the pieces come from, and in which order

seeder60 %seeder35 %80 %50 %seederYouStarting…
Seeders (solid) have the whole file; leechers (partial rings) are still downloading and share what they have. Rarest first spreads pieces evenly across the swarm. Streaming asks for the pieces just ahead of the playhead first, so the film can start before the download ends.

Rarest-first downloading, however, is terrible for watching video. A media player cannot decode a movie if it possesses piece #45, piece #800, and piece #3,000 while missing piece #1. Traditional video containers like MP4 and MKV require the file header (moov atom or Matroska EBML header) at the very start of the file, followed immediately by continuous frames in chronological sequence.

To enable streaming, libtorrent exposes piece-priority APIs that allow applications to request blocks sequentially. The client prioritizes piece #1, then piece #2, piece #3, and so on, creating a rolling buffer of decoded frames.

The trade-off is swarm etiquette: if every peer in a swarm only downloads sequentially and disconnects as soon as the movie finishes, the tail end of the file becomes rare. High-quality streaming implementations balance this by continuing to seed pieces to the swarm in rarest-first order while downloading chronological pieces for the local playhead.

Early peer-to-peer networks relied on centralized tracker servers to coordinate connections. If the tracker went offline, nobody could find peers.

libtorrent implements modern decentralized protocols defined in the official BitTorrent Enhancement Proposals:

  1. Distributed Hash Table (DHT / BEP 5): DHT turns every client into a miniature routing node using the Kademlia protocol. Instead of querying a central server, clients look up peers directly across a global decentralized network. Learn the technical details in what is DHT torrent.
  2. Peer Exchange (PEX / BEP 11): Connected peers share lists of other peers they know, accelerating swarm discovery without tracker traffic.
  3. Magnet Links (BEP 9 & 10): Instead of downloading a .torrent file, users click a magnet link containing a cryptographic info-hash. libtorrent uses the extension protocol to download the torrent’s metadata directly from peers before initiating piece transfers.

Real-time media streaming in MacLC

Streaming media over peer-to-peer networks requires more than switching a sequential download flag. Swarm speeds fluctuate: a connection might deliver 40 megabytes per second one moment and drop to 500 kilobytes per second the next.

MacLC handles this by pairing libtorrent 2.1 with a dedicated torrent playback pipeline:

  • The Start Gate: When you paste a magnet link (⌘U) or open a torrent file in MacLC, the player waits for about 20 seconds of film while it measures the swarm’s speed, then begins playback (and plays anyway after two minutes).
  • Adaptive Buffer: Based on measured swarm speed, MacLC maintains a buffer of 10 to 90 seconds. A marker on the playback bar shows what is downloaded ahead, along with speed and peer counts.
  • Playlist Automation: If a torrent contains multiple files—such as episodes of an open series—MacLC chains them into a playlist and attaches corresponding subtitle tracks.

BitTorrent is an open peer-to-peer communication protocol. Like web browsers and HTTP, it is legal technology; what matters is copyright law and the content you share. Stream only material you have the legal right to watch, such as public domain works, Creative Commons releases, and open-source films like Blender Foundation projects. This guide provides technical information, not legal advice.

Because BitTorrent operates by uploading downloaded pieces back to other peers simultaneously, sharing copyrighted files without permission constitutes copyright infringement in most jurisdictions. Read our analysis on is torrenting legal for a clear breakdown of copyright laws.

By pairing libtorrent’s mature C++ networking core with legal, open-access media, you can experience the resilience of peer-to-peer streaming. Explore how the entire process functions behind the scenes in our guide to how torrent streaming works.

Questions people ask

What is the difference between BitTorrent and libtorrent?

BitTorrent is the underlying peer-to-peer communications protocol. libtorrent (specifically libtorrent-rasterbar) is a C++ software library that developers embed into applications to handle BitTorrent networking, peer connections, and disk storage.

Is libtorrent safe to have on my computer?

Yes. libtorrent is legitimate, open-source software distributed under a permissive BSD licence. It contains no spyware, adware, or malware, and its source code is publicly audited by security researchers worldwide.

How does libtorrent stream video without downloading the whole file first?

Instead of downloading random pieces from across the file using the default rarest-first algorithm, libtorrent provides piece-priority controls that request video data sequentially from start to finish, filling a playback buffer in real time.

Which is better: libtorrent or libtransmission?

libtorrent offers deeper configuration, higher network throughput, and advanced piece-prioritization APIs ideal for complex clients and streaming players. libtransmission is engineered for minimal memory usage in the lightweight Transmission client.

Before you download

MacLC is free. If it is useful to you, a gift helps it skip “Open Anyway” and funds the next release.