Defining “Optimal Choice”
The consumer’s choice problem is an example of constrained optimization. In its most general sense, a constrained optimization problem has three elements:
 The choice space. This is the space of all available choices, regardless of whether they are feasible or not. For a consumer, we generally analyze “Good 1  Good 2 space” — that is, the space of all consumption bundles.
 The feasible set. This is a subset of the choice space which contains only those elements of the choice space which are feasible for the agent to choose. For a consumer this is the budget set.
 A (cardinal) payoff function or (ordinal) preference ranking. This allows us to evaluate different elements of the choice space. For consumer choice, these are the consumer’s preferences, which are generally represented by a utility function.
With this general framework, we can say that $X^\star$ is an optimal choice if:
 $X^\star$ is in the feasible set
 There is no other choice $X’$ which is both in the feasible set and strictly preferred to $X^\star$
In the context of consumer choice, this has a good intuitive interpretation: a $X^\star$ is optimal if:
 $X^\star$ is affordable to the consumer, given their income and the prices they face
 there is no overlap between the budget set and the set of bundles preferred to $X^\star$
A bit more informally, we can say that if $X^\star$ is an optimal choice, then any other choice which is better isn’t affordable, and any other choice which is affordable isn’t better.
To get a feel for this, try playing with the following four diagrams. Each diagram shows a budget set, and as you drag the bundle $X$ around the choice space, it shows the set of bundles preferred to $X$. As you drag $X$ around, the graph will indicate if the point is affordable, and whether there is any overlap between the purple “preferred” region and the green budget set. Try to find the four optimal points for these situations by dragging the bundles until all the green check marks light up!
Some things to notice:

In graphs (a), (b), and (c), the optimal bundle is along the budget line; in graph (d), it is not. This is related to the monotonicity of the preferences represented by the indifference curves: if more is always better, then it’s always better to move up and to the right, so the optimal point will always lie along the budget constraint. If preferences are not monotonic, it may be that your optimal point lies within the budget set, as is illustrated in (d).

In graphs (a) and (d), the optimal bundle involves buying some of each good; this is called an interior solution. In graphs (b) and (c), the consumer optimally only buys one good; this is called a corner solution. This is sometimes related to the convexity of the preferences: if a variety of goods is preferred, then you don’t want to spend all your money on one good. If your preferences are concave, as in (c), then you actively disprefer variety, and will always end up consuming either one good or the other. Note, however, that it’s possible to have convex preferences and still end up at a corner solution, as illustrated in (b).
There are a wide variety of preferences and utility functions (and constraints) that may be analyzed using this framework.