Swimming, i.e., being able to advance in the absence of external forces by performing cyclic shape changes, is particularly demanding at low Reynolds numbers. This is the regime of interest for micro-organisms and micro- or nano-robots. We focus in this paper on a simple yet representative example: the three-sphere swimmer of Najafi and Golestanian (Phys. Rev. E, 69, 062901-062904, 2004). For this system, we show how to cast the problem of swimming in the language of control theory, prove global controllability (which implies that the three-sphere swimmer can indeed swim), and propose a numerical algorithm to compute optimal strokes (which turn out to be suitably defined sub-Riemannian geodesics).