A filament, a small light bulb, burns off electrons in a process called thermionic emission. The filament is attached to the negatively charged cathode, which rests opposite from a positively charged anode. The polarity difference accelerates the electrons towards the anode at near light-speed. The electrons strike a target that is attached to the anode. The accelerated electrons strike electrons orbiting the target's atoms, dislodging them and releasing energy. 99 percent of this energy is released as heat, the remaining 1 percent is released as x-ray. The target is angled to help aim the x-rays.
The anode target is often made of tungsten, which has a high atomic number. This increases the number of electrons orbiting the atom, thus increasing the chance of an accelerated electron striking something. The entire tube is housed in a vacuum, and has lead shielding to absorb scattered x-rays. The tube is also sealed in an oil solution to help reduce the chance of electrical shock and to help dissipate heat faster. Modern x-ray tubes use a rotating anode to prevent the same spot from being struck repeatadly by accelerated electrons, which would cause pitting no the surface.