A nuclear reactor produces heat through controlled nuclear fission: atomic nuclei split and release energy.
Most commercial plants use that heat to generate steam that spins a turbine connected to an electrical generator. The details vary by reactor design.
Reactor safety relies on multiple systems and operational practices, including heat removal, monitoring, and containment.
Electricity generation itself occurs at the generator: the reactor is the source of thermal energy used to drive it.