Take this sequence of numbers.
That is 20 numbers long
But you could also write it as
So by saying there are 4 zeros, followed by 5 fours then 2 sixes etc....
You go from 20 numbers long to 12 numbers. That's a very basic way of compressing a file.
It's a similar method, a good compression algorithm would count how many A,B,C etc & 1,2,3 etc...so it would be this file has 36 A character in it 45 zeros etc... then entered into an array to keep track of the line that character/number is on.
I'm just not sure exactly how to go from that to extracting it into its original form.
Perhaps try and find currently written compression algorithms and learn from that.