Given maximal social distancing duration and intensity, how can one minimize the epidemic final size, or equivalently the total number of individuals infected during the outbreak? A complete answer to this question is provided and demonstrated here for the SIR epidemic model. In this simplified setting, the optimal solution consists in enforcing the highest confinement level during the longest allowed period, beginning at a time instant that is the unique solution to certain 1D optimization problem. Based on this result, we present numerical results showing the best possible performance for a large set of basic reproduction numbers and lockdown durations and intensities.