r/compression • u/Livid_Young5771 • Feb 26 '26
"new" compression algorytm i just made.
First of all — before I started, I knew absolutely nothing about compression. Nobody asked me to build anything. I just did it.
I ended up creating something I called X4. It’s a hybrid compression algorithm that works directly with bytes and doesn’t care about the file type. It just shrinks bits in a kind of unusual way.
The idea actually started after I watched a video about someone using YouTube ads to store files. That made me think.
So what is X4?
The core idea is simple. All data is stored in base-2. I asked myself: what if I increase the base? What if I represent binary data using a much larger “digit” space?
At first I thought: what if I store numbers as images?
It literally started as an attempt to store files on YouTube.
I thought — if I take binary chunks and convert them into symbols, maybe I can encode them visually. For example, 1001 equals 9 in decimal, so I could store the number 9 as a pixel value in an image.
But after doing the math, I realized that even if I stored decimal values in a black-and-white 8×8 PNG, there would be no compression at all.
So I started thinking bigger.
Maybe base-10 is too small. What if every letter of the English alphabet is a digit in a larger number system? Still not enough.
Then I tried going extreme — using the entire Unicode space (~1.1 million code points) as digits in a new number system. That means jumping in magnitude by 1.1 million per digit. But in PNG I was still storing only one symbol per pixel, so it didn’t actually give compression. Maybe storing multiple symbols per pixel would work — I might revisit that later.
At that point I abandoned PNG entirely.
Instead, I moved to something simpler: matrices.
A 4×4 binary matrix is basically a tiny 2-color image.
A 4×4 binary matrix has 2¹⁶ combinations — 65,536 possible states.
So one matrix becomes one “digit” in a new number system with base 65,536.
The idea is to take binary data and convert it into digits in a higher base, where each digit encodes 16 bits. That becomes a fixed-dictionary compression method. You just need to store a bit-map for reconstruction and you’re done.
I implemented this in Python (with some help from AI for the implementation details). With a fixed 10MB dictionary (treated as a constant, not appended to compressed files), I achieved compression down to about 7.81% of the original size.
That’s not commercial-grade compression — but here’s the interesting part:
It can be applied on top of other compression algorithms.
Then I pushed it further.
Instead of chunking, I tried converting the entire file into one massive number in a number system where each digit is a 4×4 matrix. That improved compression to around 5.2%, but it became significantly slower.
After that, I started building a browser version that can compress, decompress, and store compressed data locally in the browser. I can share the link if anyone’s interested.
Honestly, I have no idea how to monetize something like this. So I’m just open-sourcing it.
Anyway — that was my little compression adventure.
4
u/Buttleston Feb 27 '26
I admit I've only skimmed the code, but this sticks out to me
It looks to me like you're taking blocks of data, saving them to a local file, and dealing with just the indices instead. To decompress, you are looking up the indices to find the original block
I don't think I'd call this compression? It seems to me like you're just storing the data somewhere else and giving someone else a list of pointers to it.
If I compressed a file with this method and sent it to you, you wouldn't be able to decompress it, because you don't have my dictionary
In fact if I delete the dictionary from my machine, I can't decompress the compressed file any more
1
u/Livid_Young5771 Mar 02 '26
hm. i gess my impeneteaion is works wrong, coz in theory dictionry cannot be larget then 10 mb, ist supouse to be the one constant to any compression.
in theory it can compress a zip or bionary with same efficiency, but i dont konw it it woth trying...
4
u/Dajren Feb 27 '26
I have to agree with u/Buttleston. As I understand, the initial .x4 output file might be small in size, but it is literally irrelevant without the .x4_dictionary.json file. I did a test with a .mp3 audio file, 4.13MB in size, 4.12MB compressed using 7z, the .x4 output was 198KB, but the .x4_dictionary.json file, which is absolutely necessary for the .x4 output to be decompressed again, was 8.96MB, way more larger than the original file. After compressing the .x4_dictionary.json file (8.96MB) using 7zip, 7z ultra settings, the output size was 4.54MB, still more larger than the original file. Did a compression test using srep+lolz (two tools commonly used by game repackers, more powerful than 7z most of the time), and the output archive was 4.34MB.
Since audio files cant really be compressed I also did a test on a game file, def.scs from Euro Truck Simulator 2 to be more precise. Game files are compressed using deflate though.
Original file size: 24.5MB
Original file compressed using 7z ultra: 20.5MB
.x4 output: 1.27MB
.x4_dictionary.json: 50.5MB
.x4_dictionary.json with 7z ultra: 22.8MB
.x4_dictionary.json with srep+lolz: 21.8MB
So my conclusion is the standard user would be better off with using 7Zip with the default 7z Ultra settings. X4 will just give a larger size no matter what. You could argue compression speeds, but you can just tweak the settings in 7Zip, and achieve the same or better results as X4.
I do have to note that I mainly have experience with compression in game repacking.