The quantum nature of an oscillating mechanical object is anything but apparent. The coherent states that describe the classical motion of a mechanical oscillator do not have a well defined energy, but are quantum superpositions of equally spaced energy eigenstates. Revealing this quantized structure is only possible with an apparatus that measures energy with a precision greater than the energy of a single phonon. One way to achieve this sensitivity is by engineering a strong but nonresonant interaction between the oscillator and an atom. In a system with sufficient quantum coherence, this interaction allows one to distinguish different energy eigenstates using resolvable differences in the atom’s transition frequency. For photons, such dispersive measurements have been performed in cavity1,2 and circuit quantum electrodynamics3. Here we report an experiment in which an artificial atom senses the motional energy of a driven nanomechanical oscillator with sufficient sensitivity to resolve the quantization of its energy. To realize this, we build a hybrid platform that integrates nanomechanical piezoelectric resonators with a microwave superconducting qubit on the same chip. We excite phonons with resonant pulses and probe the resulting excitation spectrum of the qubit to observe phonon-number-dependent frequency shifts that are about five times larger than the qubit linewidth. Our result demonstrates a fully integrated platform for quantum acoustics that combines large couplings, considerable coherence times and excellent control over the mechanical mode structure. With modest experimental improvements, we expect that our approach will enable quantum nondemolition measurements of phonons4 and will lead to quantum sensors and information-processing approaches5 that use chip-scale nanomechanical devices.