X-rays are produced when fast-moving electrons hit a metal target.

A heated cathode releases electrons. A high voltage accelerates them. They collide with a metal target, releasing x-rays.

High voltage is used to accelerate the electrons to the speeds they need to release x-rays from the target.

If an electron is ejected from an inner shell, the vacany will be filled by an electron from an outer shell.

Most of the energy of the electrons is converted to heat; only a small percentage is converted to x-rays.

Electron slows down, releasing energy as an x-ray.

X-rays are composed of tiny packets of energy (photons/quanta) that collectively behave like a wavemotion.

X-rays are produced when fast-moving electrons hit a metal target, where they are forced to decelerate rapidly. Most of their kinetic energy is converted to heat but some is transformed to x-rays. The X-rays emitted can only have as much energy as the kinetic energy of the electrons that produced them. The faster the electron moves, the more energetic (and more penetrating) the x-ray.

The target is usually made of tungsten, which has a high melting point. In order for electrons to reach the speeds necessary to release x-rays, they must be accelerated. A second metal plate, situated near the target, usually provides the electrons. Often, the electrons are released from the metal plate by heating it (a process called thermionic emission). Electrons are negatively charged and so can be accelerated by applying a potential difference of thousands of Volts between the plate and the target (so that the target is positive with respect to the plate).
Most of the electrons, incident on the target, lose their KE gradually in numerous collisions, their energy going simply into heat. However a few electrons lose most or all of their energy in single collisions with target atoms; this is the energy that is evolved as x-rays.
According to classical physics, a charged particle that is decelerated (like an electron hitting a target) should radiate electromagnetic energy. This is called Bremsstrahlung. (Bremsstrahlung is the German word for braking radiation).
When methods of measuring x-ray wavelength and frequency were developed, the resulting x-ray spectra were analysed. This led to an understanding that x-rays are also produced in another way. X-rays can be emitted as a result of electronic transitions in the atoms of the anode (see below). These x-rays have very specific frequencies that are characteristic of the metal used as target.
In other words, a fast-moving electron striking the target can do two things: it can give rise to X-rays of any energy up to its own, or it can give rise to X-rays of particular energies, which are dependent on the spacing of shells in the target atom.

1. Braking radiation (Bremsstrahlung) whereby the bombarding electron may be decelerated by being swept around a nucleus of a target atom and the energy lost by the electron, is radiated as an x-ray photon.
2. K-shell knockout whereby the bombarding electron strikes and dislodges an electron from the K-shell of a target atom, causing an electron from an outer shell to drop back and radiate its excess energy as an x-ray photon.
To view these two methods of production of x-rays click on the following external link and scroll to the bottom of the page. It is worth investing time in this demonstration.
N.B. After viewing the simulation, close the window to return to this website.
Demonstration of Bremstrahlung

According to quantum physics, electromagnetic radiation occurs in quanta of energy E = hf.
Therefore when an electron is slowed down and mass-energy is conserved, we get
½ Mu² - ½ Mv² = hf

Both light and x-rays are produced by transitions from orbit to orbit of electrons in atoms, light by the transitions of outer electrons and x-rays by the transitions of inner electrons.