It depends on the style of beer, the temperature, the type of yeast, and the amount of sugar. Altering any of these variables changes the beer a great deal.
In general, you should ferment for at least a week for an ale, and at least a month for a lager. Pay attention to the temperature requirements for various yeast strains, because they impact the flavor of the beer, as well as the alcohol content.
You can also do secondary fermentation by adding more sugar after the primary fermentation, or simply moving the beer to a different fermenter (removing the trub) and letting it sit a while longer. It’s fun to ferment the same batch of beer for different amounts of time and see how it effects the character of the beer, if you have enough interest.
An excellent and free online source for home-brewing knowledge is John Palmer’s book, “How to Brew”. http://www.howtobrew.com/