When you create a public key, your private key is put through a special mathematical function, and this function can only handle numbers up to just below 256 bits. The maximum value is:
max = 115792089237316195423570985008687907852837564279074904382605163141518161494337
So when you generate a 256 bit number, you will want to check that it's below this maximum value.
But 2^256 is 115792089237316195423570985008687907853269984665640564039457584007913129639936
You can easily verify this
https://www.wolframalpha.com/input/?i=2%5E256
The number of private keys are limited by the secp256k1 Elliptic Curve Cryptography algorithm. It is the "n" value listed here https://en.bitcoin.it/wiki/Secp256k1
If you want to understand better how this work programmatically, you should see this very nice explanatory video: https://www.youtube.com/watch?v=iB3HcPgm_FI