LZ4 (compression algorithm)

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Original author(s)Yann Collet
Developer(s)Yann Collet
Initial releaseApril 24, 2011 (2011-04-24)
Stable release
1.9.2 / August 20, 2019; 11 months ago (2019-08-20)[1]
Repository Edit this at Wikidata
Written inC
Operating systemCross-platform
TypeData compression
LicenseSimplified BSD License
Websitelz4.github.io/lz4/ Edit this at Wikidata

LZ4 is a lossless data compression algorithm that is focused on compression and decompression speed. It belongs to the LZ77 family of byte-oriented compression schemes.


The algorithm gives a slightly worse compression ratio than the LZO algorithm – which in turn is worse than algorithms like DEFLATE. However, compression speeds are similar to LZO and several times faster than DEFLATE, while decompression speeds can be significantly higher than LZO.[2]


LZ4 only uses a dictionary-matching stage (LZ77), and unlike other common compression algorithms does not combine it with an entropy coding stage (e.g. Huffman coding in DEFLATE).[3][4]

The LZ4 algorithm represents the data as a series of sequences. Each sequence begins with a one-byte token that is broken into two 4-bit fields. The first field represents the number of literal bytes that are to be copied to the output. The second field represents the number of bytes to copy from the already decoded output buffer (with 0 representing the minimum match length of 4 bytes). A value of 15 in either of the bitfields indicates that the length is larger and there is an extra byte of data that is to be added to the length. A value of 255 in these extra bytes indicates that yet another byte to be added. Hence arbitrary lengths are represented by a series of extra bytes containing the value 255. The string of literals comes after the token and any extra bytes needed to indicate string length. This is followed by an offset that indicates how far back in the output buffer to begin copying. The extra bytes (if any) of the match-length come at the end of the sequence.[5][6]

Compression can be carried out in a stream or in blocks. Higher compression ratios can be achieved by investing more effort in finding the best matches. This results in both a smaller output and faster decompression.


The reference implementation in C by Yann Collet is licensed under a BSD license. There are ports and bindings in various languages like Java, C#, Python etc.[7] Databases like Hadoop use this algorithm for fast compression. LZ4 was also implemented natively in the Linux kernel 3.11.[8] The FreeBSD, Illumos, ZFS on Linux, and ZFS-OSX implementations of the ZFS filesystem support the LZ4 algorithm for on-the-fly compression.[9][10][11][12] Linux supports LZ4 for SquashFS since 3.19-rc1.[13] LZ4 is also implemented in newer Zstd archiver by Yann Collet.


  1. ^ "LZ4 v1.9.2". Github. 30 August 2019. Retrieved 30 August 2019.
  2. ^ Michael Larabel (2013-01-28). "Support For Compressing The Linux Kernel With LZ4". Phoronix. Retrieved 2015-08-28.
  3. ^ Collet, Yann (2019-03-30). "LZ4 Block Format Description". GitHub. Retrieved 2020-07-09. There is no entropy encoder back-end nor framing layer.
  4. ^ DEFLATE Compressed Data Format Specification version 1.3. IETF. doi:10.17487/RFC1951. RFC 1951. Retrieved 2020-07-09.
  5. ^ Yann Collet (2011-05-26). "RealTime Data Compression". Retrieved 2015-08-28.
  6. ^ ticki (2016-10-25). "How LZ4 works". Retrieved 2017-06-29.
  7. ^ Extremely Fast Compression algorithm http://www.lz4.org on GitHub
  8. ^ Jonathan Corbet (2013-07-19). "Kernel development". LWN.net. Retrieved 2015-08-28.
  9. ^ "FreeBSD 9.2-RELEASE Release Notes". FreeBSD. 2013-11-13. Retrieved 2015-08-28.
  10. ^ "LZ4 Compression". illumos. Retrieved 2015-08-28.
  11. ^ Illumos #3035 LZ4 compression support in ZFS and GRUB on GitHub
  12. ^ "Features: lz4 compression". OpenZFS. Retrieved 2015-08-28.
  13. ^ Phillip Lougher (2014-11-27). "Squashfs: Add LZ4 compression configuration option". Retrieved 2015-08-28.

External links[edit]