2026-07-037 min readhls protocol, hls in detail, hls specification

HLS Protocol Explained: From Segments to Playback

In-depth technical explanation of the HLS protocol. Master playlists, media playlists, segments, encryption, and the complete playback flow.

HLS Protocol Layers

The HLS protocol operates on three layers:

1. Content Preparation Layer

  • Video is encoded at multiple bitrates using codecs like H.264, HEVC, or AV1
  • Audio is encoded separately, often in AAC or MP3
  • Content is fragmented into segments of equal duration (typically 6 seconds)
  • Each segment is independently decodable (keyframe at the start of each segment)

2. Playlist Layer

  • Master playlist describes available variants (bitrate, resolution, codec)
  • Media playlists list segment URLs for each variant
  • Additional playlists for audio tracks, subtitles, and I-frames

3. Delivery Layer

  • All files served over HTTP/HTTPS
  • Standard HTTP caching applies at every level
  • Playlists may redirect to variant playlists based on client capabilities

Playback Flow

  1. Player fetches the master playlist URL
  2. Player parses the available variant streams and their bandwidth requirements
  3. Player starts with the lowest variant or uses previously stored bandwidth estimates
  4. Player fetches the media playlist for the selected variant
  5. Player begins downloading segments in sequence
  6. As segments download, the player feeds them to the media buffer via MSE
  7. The ABR algorithm continuously monitors download speed and buffer health
  8. When switching quality, the player fetches the new variant's playlist and aligns segments
  9. Playback continues seamlessly until the last segment (VOD) or indefinitely (live)

Encryption and DRM

HLS supports AES-128 encryption for content protection. The encryption key is referenced in the playlist via the #EXT-X-KEY tag:

#EXT-X-KEY:METHOD=AES-128,URI="https://keyserver.com/key.bin",IV=0x...

The player fetches the key before decrypting segments. For commercial DRM, HLS supports FairPlay Streaming (Apple's DRM), which integrates with iOS, macOS, and tvOS for protected content delivery.

Server Requirements

An HLS server needs to:

  • Serve .m3u8 files with Content-Type: application/vnd.apple.mpegurl
  • Serve .ts files with Content-Type: video/mp2t
  • Support byte-range requests (optional, used by some implementations)
  • Configure CORS headers for cross-origin playback
  • Handle concurrent connections for many viewers

Related Articles