# Why mod operation can be used as hash function

I'm new here, and I'm currently trying to understand why mod operation can be used as a hash function.

For example, consider the function $$h(x)=x\mod 2^{256}$$, where $$x$$ can be a string of any length. The book says that this function will return a fixed size of 256 bits. To my understanding, $$h(x)$$ will return an integer in the interval $$[0,2^{256})$$, which can be expressed in 256 bits. My question is that, suppose $$x$$ is $$5$$, then $$h(x)=5$$, which can also be expressed in 3 bits (101). How do we guarantee that the output will be the size of $$256$$ bits? (I am just new to computer science and apologize if the question is too elementary).

• How does your car guarantee that the odometer is always 7 digits even though you only drove less than 10000 miles since you bought it? – Jörg W Mittag Feb 27 at 1:15
• Note that that function has nothing to do with Cryptographic hash functions. Collisions findings and pre-image attacks are imminent. – kelalaka Feb 28 at 13:49