Exergy analysis is a branch of thermodynamics receiving an increasing interest in the scientific literature and in didactic presentations. Exergy represents the maximum useful work obtainable by a system that can interact with a reference environment. There exist two exergy functions: exergy, that refers to a collection of matter contained within the reference environment; flow exergy, that refers to a collection of matter flowing in a pipe, that can interact with the environment and diffuse into it. The usual derivations of the expressions of exergy and flow exergy are either complicated or not general. Moreover, two separate derivations are necessary, due to the different conceptual schemes employed in the definitions of these properties. As a consequence, the expressions of exergy and flow exergy are often reported without a derivation in didactic treatises. In this paper, we provide a simple and general unified deduction of the expressions of exergy and flow exergy. Moreover, we show that the logical scheme proposed, based on the concept of useful energy of a system contained in a pressure field, allows a simpler deduction and a deeper interpretation of the energy balance equation for a control volume in steady state. Finally, in order to complete the didactic treatment, we rewrite the expression of the molar exergy of a pure substance at ambient temperature and pressure in a form applicable to reactive substances, and we present an application of this form.