Friction is the ubiquitous mechanical process of sticking and energy dissipation at the interface between objects. Despite its technological and economic significance, friction remains poorly understood, being a non-linear, out-of-equilibrium, many-body process. According to the widely known empirical laws of friction, it is proportional to the load on the interface and independent of velocity. However, these laws fail at the nanoscale: atomistic models and some atomic force probe experiments exhibit superlubricity below a critical value of the interface interaction strength, as well as a complex dependence on velocity, temperature and lattice mismatch. Using laser-cooled trapped ion crystals in an optical lattice, we study these phenomena with microscopic control and atom-by-atom sub-lattice-site resolution not available in any solid state probes, allowing us to build a bottom-up understanding of the physics of friction. In particular, we observe: 1) 4 different friction regimes over 5 orders of magnitude in velocity, 2) superlubricity induced by lattice mismatch, and 3) the breaking of superlubricity above a critical strength of the optical lattice, representing an observation of the long-theorized analyticity-breaking Aubry transition. We show that these basic properties of friction at the few-atom level capture the physics of infinite-atom models and represent the basic building block that can be used to understand friction at larger length scales.