The coherent states that describe the classical motion of a mechanical oscillator do not have well-defined energy, but are rather quantum superpositions of equally-spaced energy eigenstates. Revealing this quantized structure is only possible with an apparatus that measures the mechanical energy with a precision greater than the energy of a single phonon, $hbaromega_text{m}$. 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 phonon number states by resolvable differences in the atoms transition frequency. Such dispersive measurements have been studied in cavity and circuit quantum electrodynamics where experiments using real and artificial atoms have resolved the photon number states of cavities. Here, we report an experiment where 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 of varying amplitude and probe the resulting excitation spectrum of the qubit to observe phonon-number-dependent frequency shifts $approx 5$ 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 our approach will make quantum nondemolition measurements of phonons an experimental reality, leading the way to new quantum sensors and information processing approaches that use chip-scale nanomechanical devices.