One way to think of a hash is like a human fingerprint (hashes are also sometimes referred to as fingerprints)..
You can "compress" any person in to a (pretty much) unique finger-print.. but, you cannot know who someone is by their fingerprint alone.. This is just like a hash, you can easily work out hash("abcdef") -> a1b2c3
, but given only a1b2x3
, you cannot trivially tell the source data.
To reverse a finger print, you need to compare the fingerprint to a database of known people->finger-prints
(if the unknown fingerprint matches Person1, the unknown fingerprint belongs to them)
With a hash, again you must do much the same thing - you have a database with all string->hash mappings (called a rainbow table). Then you lookup the row with the hash "a1b2c3" and it shows "abcdef" was hashed in order to get this. The other more common way is to simply try every combination of characters, hash them and compare (a brute force attack)
Finally, while human fingerprints are "unique", it's possible to have two the same, it's just incredibly unlikely - it's the same with hashing... Some hashing algorithms are more susceptible to collisions than others.
my question is if the hashes are all unique, wouldn't i be able to compress anything into a 40 char string?
Theoretically hashing is a great compression method, but to decompress is incredibly impractical beyond (say) 10 ASCII characters of data.. You're right, you can compress anything to a 40 character string, but you cannot decompress it practically (even theoretically is a bit of a stretch..)