When performing a task, neural circuits must represent and manipulate continuous stimuli using discrete action potentials. It is commonly assumed that neurons represent continuous quantities with their firing rate and this independently from one another. However, such independent coding is very inefficient because it requires the generation of a large number of action potentials in order to achieve a certain level of accuracy. We show that neurons in a spiking recurrent network can learn - using a local plasticity rule - to coordinate their action potentials in order to represent information with high accuracy while discharging minimally. The learning rule that acts on recurrent connections leads to such an efficient coding by imposing a precise balance between excitation and inhibition at the level of each neuron. This balance is a frequently observed phenomenon in the brain and is central in our work. We also derive two biologically plausible learning rules that respectively allows the network to adapt to the statistics of its inputs and to perform complex and dynamic transformations on them. Finally, in these networks, the stochasticity of the spike timing is not a signature of noise but rather of precision and efficiency. In fact, the random nature of the spike times results from the degeneracy of the representation. This constitutes a new and a radically different interpretation of the irregularity found in spike trains.