The relationship between utility and demand falls under the theory of consumer behaviour. People want to purchase what makes them happy, and happiness in economics is quantified by utility. It is therefore important to understand what utility is and the different types of utility.
Utility refers to the ability of a good or service to satisfy the consumer's needs/wants. It is the preference for a good or service over other goods/services. Utility is a quantitative measure for a subjective feeling. There are two main ways that utility is measured: cardinal and ordinal. A cardinal measurement asks for example, participants in a survey to rate objects from 1-10 to show their preference. An ordinal measurement can be thought of as giving a participant of a survey ten different goods and asking them to order them according to preference. By doing such with all sorts of goods, you can form an index of all goods and their respective utilities.
Marginal utility is an important concept in utility theory. It refers to the increase in utility attributed to the increase in consumption of one more unit of said good and vice versa. The law of dimishing marginal utility states that when additional units of a good are consumed, the resulting increments in utility will diminish. An example is that we can imagine being a lot happier when we receive a chocolate bar when we had none compared to receiving a chocolate bar when we already have 100 of them.
Utility is usually displayed on a graph in an indifference curve, representing the different combinations of two goods that result in the same level of utility. Note that utility curves are always parallel and cannot cross by definition. The utility function exists to show the slope of the utility curve as marginal utility. This when applied to consumer theory will serve as the foundation of the downward sloping demand curve.