Carbon is created inside of stars. Stars start out as mostly clouds of hyrdrogen that pull together from their own gravity. As they become denser the pressure and temperature inside increases and the hydrogens start to fuse together, forming helium. As the star ages the hydrogen gets used up and turned into more heliums, and now the heliums fuse and become beryllium. Then another helium fuses to this and becomes carbon.