Neutron stars are formed when large stars run out of fuel and collapse. To get a neutron star, you need to have star that’s larger than about 1.5 solar masses and less than 5 times the mass of the Sun.
If you have less than 1.5 solar masses, you don’t have enough material and gravity to compress the object down enough. You only get a white dwarf. This is what will happen to our own Sun one day.
If you have more than 5 times the mass of the Sun, your star will end up as a black hole.
But if your star is right in between those masses, you get a neutron star.
The neutron star is formed when the star runs out of fuel and collapses inward on itself. The protons and electrons of atoms are forced together into neutrons. Since the star still has a lot of gravity, any additional material falling into the neutron star is super-accelerated by the gravity and turned into identical neutron material.
Just one teaspoon of a neutron star would have the mass of over 5 x 1012 kilograms.
A neutron star actually has different layers. Astronomers think there’s an outer shell of atomic nuclei with electrons about 1 meter thick. Below this crust, you get nuclei with increasing numbers of neutrons. These would decay quickly on Earth, but the intense pressure of the gravity keeps them stable.
When neutron stars form, they maintain the momentum of the entire star, but now they’re just a few kilometers across. This causes them to spin at tremendous rates, sometimes as fast as hundreds of times a second.