Imaging of vibrational excitations in and near nanostructures is essential for developing low-loss infrared nanophotonics, controlling heat transport in thermal nanodevices, inventing new thermoelectric materials and understanding nanoscale energy transport. Spatially resolved electron energy loss spectroscopy has previously been used to image plasmonic behaviour in nanostructures in an electron microscope, but hitherto it has not been possible to map vibrational modes directly in a single nanostructure, limiting our understanding of phonon coupling with photons and plasmons. Here we present spatial mapping of optical and acoustic, bulk and surface vibrational modes in magnesium oxide nanocubes using an atom-wide electron beam. We find that the energy and the symmetry of the surface polariton phonon modes depend on the size of the nanocubes, and that they are localized to the surfaces of the nanocube. We also observe a limiting of bulk phonon scattering in the presence of surface phonon modes. Most phonon spectroscopies are selectively sensitive to either surface or bulk excitations; therefore, by demonstrating the excitation of both bulk and surface vibrational modes using a single probe, our work represents advances in the detection and visualization of spatially confined surface and bulk phonons in nanostructures.