The X-Ray Machine
The heart of an X-ray machine is an electrode pair -- a cathode and an anode -- that sits inside a glass vacuum tube. The cathode is a heated filament. like you might find in an older fluorescent lamp. The machine passes current through the filament, heating it up. The heat sputters electrons off of the filament surface. The positively-charged anode, a flat disc made of tungsten. draws the electrons across the tube.
The voltage difference between the cathode and anode is extremely high, so the electrons fly through the tube with a great deal of force. When a speeding electron collides with a tungsten atom, it knocks loose
an electron in one of the atom's lower orbitals. An electron in a higher orbital immediately falls to the lower energy level, releasing its extra energy in the form of a photon. It's a big drop, so the photon has a high energy level -- it is an X-ray photon.
Free electrons can also generate photons without hitting an atom. An atom's nucleus may attract a speeding electron just enough to alter its course. Like a comet whipping around the sun. the electron slows down and changes direction as it speeds past the atom. This "braking" action causes the electron to emit excess energy in the form of an X-ray photon.