A hash table stores key-value pairs by transforming keys into hash values using a hash function. This hash is used as an index to store the key-value pair in an array of buckets. If multiple keys hash to the same value, a bucket may contain multiple key-value pairs. To retrieve a value, the key is hashed to find the correct bucket, and then the key-value pair is returned if the key matches or a collision is resolved by searching the bucket.