How GZIP Encoding Works

This visual narrative walks through how a short sentence is compressed with GZIP. Follow each step to see the header bytes, sliding window matches from the LZ77 stage, and the creation of Huffman-coded output bits. Use the controls to step through the process and connect each animation state with the pseudocode on the left.

Pseudocode

  1. emit_gzip_header()
  2. init_window_and_frequency_tables()
  3. for each position in input_data:
  4.     match = longest_match_in_window()
  5.     if match.length ≥ 3:
  6.         emit_length_distance(match)
  7.     else emit_literal(current_byte)
  8.     update_symbol_frequencies(token)
  9. codes = build_huffman_codes(frequencies)
  10. write_block_header(codes)
  11. write_tokens_with_codes(tokens)
  12. write_footer(crc32(input), input_size)

Encoding Timeline

Input data & window

Tokens emitted

    Compressed bitstream