Introduction
LZMA is the Lempel-Ziv-Markov chain compression algorithm that powers 7z archives and the xz format. Igor Pavlov designed it for 7-Zip in 1998, and it delivers some of the best compression ratios of any general-purpose algorithm, often 30-50% smaller than gzip on the same input. The trade-off is speed: LZMA at level 9 is much slower than gzip at level 9. This lzma compress online tool runs the algorithm in your browser with a configurable level from 1 (fast) to 9 (best). No data leaves your device.
What this tool does
- Compresses text into LZMA format with a configurable level from 1 (fastest) to 9 (best ratio).
- Decompresses LZMA data back to the original text, auto-detecting hex or base64 input.
- Outputs compressed data in both hex and base64 formats for easy copy-paste.
- Reports the compression ratio percentage so you can compare against gzip and Brotli.
- Uses the lzma1 pure-JavaScript implementation, so no native dependencies are required.
- Runs entirely client-side with no network requests.
How this tool works
In compress mode, the tool encodes your input as UTF-8 and passes it to the lzma1 library's compressString function with the selected level. The output is a raw LZMA byte stream, displayed as both hex and base64. The compression ratio percentage compares the compressed size to the original UTF-8 byte count.
In decompress mode, the tool auto-detects whether your input is hex (only 0-9 and a-f characters) or base64, converts it to a Uint8Array, and passes it to decompressString. The output is the original text. Level 9 compression is significantly slower than level 1, especially for inputs over a few kilobytes, because LZMA's range coder and large dictionary do more work at higher levels.
How LZMA compression works
LZMA was designed by Igor Pavlov for the 7-Zip archiver and first released in 1998. The name stands for Lempel-Ziv-Markov, reflecting its lineage: it is an LZ77-family dictionary coder (Lempel-Ziv) with a Markov-model context for the entropy stage, replacing the Huffman coding used in DEFLATE with a range coder.
The algorithm has two main parts. The LZ77 stage finds repeated substrings within a sliding window (up to 8 MB in LZMA2, much larger than DEFLATE's 32 KB) and replaces them with distance-length pairs. The range coder stage encodes the resulting symbol stream using a context-adaptive binary arithmetic coder, which can encode each symbol with fractional-bit precision. That fractional-bit precision is why LZMA beats DEFLATE: Huffman coding is stuck at integer bits per symbol, while the range coder is not.
The compression level (1-9) controls the dictionary size, the number of literal context bits, and the number of position state bits. Level 9 uses the largest dictionary and the most context, which finds more matches and models them more accurately, but is much slower. Level 1 is fast and still beats gzip on most inputs.
LZMA is the basis for the .xz container format (RFC 9107 successor to .lzma), which is used by the Linux kernel for kernel.org tarballs, by Debian for .deb package compression, and by Fedora for RPM payloads. The XZ Utils project maintains the canonical C implementation. The lzma1 npm package used here is a pure-JavaScript port that produces output compatible with the reference LZMA decoder.
How to use this tool
- Select mode: Compress or Decompress.
- For compression: set the level from 1 (fast) to 9 (best ratio) using the slider.
- Type or paste text. Output shows hex, base64, and compression ratio.
- For decompression: paste hex or base64 LZMA data. The tool auto-detects the format.
- Use the Swap button to switch between modes.
Real-world examples
Compressing a JSON payload
A developer has a 50 KB JSON payload that needs to fit under a 30 KB storage limit. gzip level 9 brings it to 7.2 KB, but LZMA level 9 brings it to 5.1 KB, a 29% improvement. They compress the JSON here, copy the base64 output, and store it. The extra compression matters because the payload is stored millions of times in a content-addressed cache.
Decompressing an xz-packed tarball fragment
A developer inspecting a .tar.xz file extracts a single LZMA-compressed member as hex and pastes it into the decompress mode. The tool returns the original bytes, which they can then inspect as a tar header or file content. This is useful when debugging xz-packed artifacts without unpacking the whole archive.
Comparing LZMA to gzip and Brotli
A student compresses the same text with the Gzip tool (DEFLATE), the Brotli tool, and this LZMA tool at level 9. LZMA typically produces the smallest output, Brotli is next, and gzip is the largest. The comparison makes the trade-off between ratio and speed concrete: LZMA level 9 took noticeably longer than the other two.
Comparison with similar methods
| Method | Complexity | Typical use |
|---|---|---|
| LZMA (xz) | LZ77 + range coder, large dictionary | 7z, xz, Linux kernel tarballs |
| DEFLATE (gzip) | LZ77 + Huffman, 32 KB window | HTTP Content-Encoding, PNG |
| Brotli | LZ77 + context modeling + dictionary | HTTPS Content-Encoding, web fonts |
| Zstandard | LZ77 + FSE, fast and strong | ZFS, Meta, modern high-speed compression |
Limitations or considerations
LZMA at level 9 is slow. For a 1 MB input, level 9 can take several seconds in the browser because the pure-JavaScript implementation does not have the SIMD and native-code optimizations of XZ Utils. For interactive use, level 1-3 is a better trade-off. The output of this tool is a raw LZMA stream, not an .xz container; if you need the .xz format with its headers and checksums, use XZ Utils on the command line. The lzma1 library does not support streaming compression, so the entire input must fit in memory.
Frequently asked questions
What is the difference between LZMA and LZMA2?
LZMA2 is a container format around LZMA that supports chunked dictionaries, multithreaded compression, and better handling of incompressible data. It is what .xz files use. This tool produces raw LZMA streams, not LZMA2 chunks, but the compression algorithm is the same.
Why is LZMA level 9 so slow?
Level 9 uses the largest dictionary (8 MB in the reference implementation), the most literal context bits, and the most position state bits. Finding matches in a large dictionary is O(n) per position, and the range coder does more work with more context. Level 1 uses a much smaller dictionary and fewer context bits, so it is dramatically faster while still beating gzip.
Is LZMA output compatible with 7-Zip and xz?
The raw LZMA stream from this tool is compatible with 7-Zip's LZMA decoder and with xz --lzma. The .7z and .xz container formats add their own headers and metadata, so you cannot feed this tool's output directly to 7z x and expect it to work without wrapping it in the container first.
Should I use LZMA or Zstandard for my project?
If you need the smallest possible output and can afford the compression time, LZMA. If you need fast compression and fast decompression with a good ratio, Zstandard. Zstandard at level 19 approaches LZMA's ratio while being much faster at decompression. For web content delivery, Brotli is usually the right choice because browsers support it natively.
Conclusion
LZMA delivers some of the best compression ratios of any general-purpose algorithm, at the cost of slower compression than gzip or Zstandard. This tool runs LZMA in your browser with levels 1 through 9 and outputs hex and base64. For faster compression with a similar ratio, try the Zstandard tool. For web content delivery, use the Brotli or Gzip tools.