The LempelZivMarkov chain algorithm (LZMA) is an algorithm used to perform data compression. It has been under development since 1998^{[1]}^{[2]} and is used in the 7z format of the 7Zip archiver. This algorithm uses a dictionary compression scheme somewhat similar to LZ77 and features a high compression ratio (generally higher than bzip2^{[3]}^{[4]}) and a variable compressiondictionary size (up to 4 GiB).^{[5]}
Contents 
LZMA uses an improved and optimized version of the LZ77 compression algorithm, backed by a range encoder. Streams of data, repeatedsequence size and repeatedsequence location seem to be compressed separately.^{[citation needed]}
In LZMA compression, the compressed stream is a stream of bits, encoded using adaptive binary range coder. The stream is divided into packets, each packet describing either a single byte, or an LZ77 sequence with its length and distance implicitly or explicitly encoded.
There are 7 types of packets:^{[citation needed]}
packed code (bit sequence)  packet description 

0 + byteCode  A single byte encoded using an adaptive binary range coder. The range coder uses context based on some number of the most significant bits of the previous byte. Depending on the state machine, this can also be a single byte encoded as a difference from the byte at the last used LZ77 distance. 
1+0 + len + dist  A typical LZ77 sequence describing sequence length and distance. 
1+1+0+0  A onebyte LZ77 sequence. Distance is equal to the last used LZ77 distance. 
1+1+0+1 + len  An LZ77 sequence. Distance is equal to the last used LZ77 distance. 
1+1+1+0 + len  An LZ77 sequence. Distance is equal to the second last used LZ77 distance. 
1+1+1+1+0 + len  An LZ77 sequence. Distance is equal to the third last used LZ77 distance. 
1+1+1+1+1 + len  An LZ77 sequence. Distance is equal to the fourth last used LZ77 distance. 
The length is encoded as follows:
Length code (bit sequence)  Description 

0+ 3 bits  The length encoded using 3 bits, gives the lengths range from 2 to 9. 
1+0+ 3 bits  The length encoded using 3 bits, gives the lengths range from 10 to 17. 
1+1+ 8 bits  The length encoded using 8 bits, gives the lengths range from 18 to 273. 
The distance is encoded as follows:
First a distance class is encoded using 6 bits. The 5 other bits of the distance code encode the information about how many direct distance bits need to be extracted from the stream.
The LZMA implementation extracted from 7Zip is available as LZMA SDK and has been put by Igor Pavlov under the public domain.^{[6]} It was originally distributed under the terms of both the LGPL and Common Public License, with a special exception for linked binaries. Version 4.61 beta was released into the public domain on November 23 2008. In this version there is also a LZMA2 version available ( Improved version of LZMA)
The reference open source LZMA compression library is written in C++ and has the following properties:
In addition to the original C++, the LZMA SDK contains reference implementations of LZMA compression and decompression ported to ANSI C, C#, and Java.^{[6]} There also exists an implementation in Pascal and Python bindings for the C++ library.^{[7]}^{[8]}
This (the 7Zip) implementation uses several variants of hash chains, binary trees and Patricia tries as the basis for its dictionary search algorithm.
Decompressiononly code for LZMA generally compiles to around 5 kiB and the amount of RAM required during decompression is principally determined by the size of the sliding window used during compression. Small code size and relatively low memory overhead, particularly with smaller dictionary lengths, and free source code make the LZMA decompression algorithm wellsuited to embedded applications.
Software that uses or supports LZMA:


