The magnetic and electronic properties of strontium titanate with different carbon dopant configurations are explored using first-principles calculations with a generalized gradient approximation (GGA) and the GGA+*U* approach. Our results show that the structural stability, electronic properties and magnetic properties of C-doped SrTiO_{3} strongly depend on the distance between carbon dopants. In both GGA and GGA+*U* calculations, the doping structure is mostly stable with a nonmagnetic feature when the carbon dopants are nearest neighbors, which can be ascribed to the formation of a C–C dimer pair accompanied by stronger C–C and weaker C–Ti hybridizations as the C–C distance becomes smaller. As the C–C distance increases, C-doped SrTiO_{3} changes from an n-type nonmagnetic metal to ferromagnetic/antiferromagnetic half-metal and to an antiferromagnetic/ferromagnetic semiconductor in GGA calculations, while it changes from a nonmagnetic semiconductor to ferromagnetic half-metal and to an antiferromagnetic semiconductor using the GGA+*U* method. Our work demonstrates the possibility of tailoring the magnetic and electronic properties of C-doped SrTiO_{3}, which might provide some guidance to extend the applications of strontium titanate as a magnetic or optoelectronic material.