If only the password hash is stored and the user inputs the original password, how does the program know that it is correct? I guess it could check all the possible salts but if there are 32bit salts then the program has to check all 2^32 salts (worst case) which seems like it would take a really long time.
The answer is simply; the salt is stored alongside the password hash. A typical database scheme would look like;
uid | username | password | password_salt -----|-------------|------------------|-------------- 0 | alice | 862a6c81b7f8361b | 71e9c02731
The salt is not a secret. It is there to make certain types of attacks orders of magnitude more difficult.
This answer should contain everything you need to know.
If not, then this answer has even more information on the ins and outs of salting.
As lynks pointed out, the salt is stored with the hash. The point of salts is to make it so that someone can't attack the DB as a whole by looking for a password that matches the hash of any user.
For example, lets say I had the user table for really big website A and they had 100 million users. If they were using a 32 bit hash (which is not at all secure anyway) and every user had a password that resolved to a different hash, then I would only have to try about 43 passwords before I found one that matched some user. If, however, a different salt is used for each, then I have to attack each password individually.