We have studied neutron-rich carbon isotopes in terms of the shell model employing a realistic effective hamiltonian derived from the chiral N3LOW nucleon-nucleon potential. The single-particle energies and effective two-body interaction have been both determined within the framework of the time-dependent degenerate linked-diagram perturbation theory. The calculated results are in very good agreement with the available experimental data, providing a sound description of this isotopic chain toward the neutron dripline. The correct location of the dripline is reproduced.