A consumer's budget constraint is used with the utility function to derive the demand function. The utility function describes the amount of satisfaction a consumer gets from a particular bundle of goods.
Economists and manufacturers look at demand functions to understand what effect different prices have on the demand for a product or service. In order to reliably calculate it, two data pairs are required that show how many units are bought at a particular price. In simplest terms, the demand function is a straight line, and manufacturers interested in maximizing revenues use the function to help establish the most profitable production yields.
For example, say there are two goods a consumer can choose from, x and y. Assuming no borrowing or saving, a consumer's budget for x and y are equal to income. To maximize utility, the consumer wants to use the entire budget to buy the most x and y possible.
The first part of figuring out demand is to find the marginal utility each good provides and the rate of substitution between the two goods—that is, how many units of x the consumer is willing to give up so she can get more y.
The substitution rate is the slope of the consumer's indifference curve, which shows all of the combinations of x and y the consumer would be equally happy to accept. However, just because the consumer doesn't prefer one combination over another on a subjective level, she has to take into account what is affordable.
The point where the budget line meets the indifference curve is where the consumer's utility is maximized. This happens when the budget is fully spent on a combination of x and y with no money left over, which makes that combination the optimal one from the consumer's point of view.
The point of utility maximization is key to deriving the demand function. Because they are equal where utility is maximized, the marginal rate of substitution, which is the slope of the indifference curve, can be used to replace the slope of the budget curve. The slope of the budget curve is the ratio between the price of x and the price of y. Replacing it with the marginal rate of substitution simplifies the equation so only one price remains. This makes it possible to find out the demand for the product in terms of its price and the total income available.
In terms of this particular example, the demand function would thus formally express the amount of x the consumer is willing to buy, given her income and the price of x.
This demand function can then be inserted into the budget equation to derive the demand for y. The same principles apply: Instead of two price and product variables, the resulting equation could be simplified so it only includes the price of y, the consumer's income and the total quantity of y demanded, given both of those factors.
(For related reading, see: What is the utility function and how is it calculated?)