Solid-state nuclear magnetic resonance (SSNMR) and nuclear quadrupole resonance (NQR) spectra provide detailed information about the electronic and atomic structure of solids. Modern ab initio methods such as density functional theory (DFT) can be used to calculate NMR and NQR spectra from firstprinciples, providing a meaningful avenue to connect theory and experiment. Prediction of SSNMR and NQR spectra from DFT relies on accurate calculation of the electric field gradient (EFG) tensor associated with the potential of electrons at the nuclear centers. While static calculations of EFGs are commonly seen in the literature, the effects of dynamical motion of atoms in molecules and solids have been less explored. In this study, we develop a method to calculate EFGs of solids while taking into account the dynamics of atoms through DFT-based molecular dynamics simulations. The method we develop is general, in the sense that it can be applied to any material at any desired temperature and pressure. Here, we focus on application of the method to NaNO 2 and study in detail the EFGs of 14 N, 17 O, and 23 Na. We find in the cases of 14 N and 17 O that the dynamical motion of the atoms can be used to calculate mean EFGs that are in closer agreement with experiments than those of static calculations. For 23 Na, we find a complex behavior of the EFGs when atomic motion is incorporated that is not at all captured in static calculations. In particular, we find a distribution of EFGs that is influenced strongly by the local (changing) bond environment, with a pattern that reflects the coordination structure of 23 Na. We expect the methodology developed here to provide a path forward for understanding materials in which static EFG calculations do not align with experiments.