In response to these challenges, herein we present a first-principles quality machine learning potential to study ion pairing in a prototypical nanoconfined electrolyte. We use this model to study how the free energy of ion pairing changes under confinement, ranging from a single layer of electrolyte to a bulk solution. By disentangling the roles of ion solvation, lattice structure, and the confining surface's electronic structure, this work offers insights into predicting and optimizing nanoconfined ion pairing for sustainable energy storage and filtration applications.