An x-ray is a form of energy within a certain range of wavelengths. Any radiation between 3×1016 Hz to 3×109 Hz (30 petahertz to 30 exahertz) is considered x-ray radiation. These are very short wavelengths, just below the ultraviolet region of the spectrum. The actual wavelength is about 10,000 times smaller than the wavelength of visible light. Short wavelength rays have high energy, which is why x-rays pass through most things. The high energy level of an x-ray photon doesn’t ‘fit’ with others atoms’ electron orbits, making it difficult for atoms to absorb x-rays unless the atom is large enough to accommodate the x-ray photon’s energy.
The x-ray machine at your doctor’s office generates x-rays by cranking a bunch of electrons up to a very high speed using a highly charged cathode. These electrons are then drawn to an anode make of tungsten. There, the electrons strike tungsten atoms and are either deflected or knock other electrons out of orbit. The collisions emit photons at the wavelength of x-rays which are channeled using a small window and lots of lead shielding.
From there, the rays are passed through some portion of your anatomy. Many of them go right through, but your bones are made from larger atoms (calcium, mostly) than your other bits, and these atoms have a greater chance of absorbing some x-rays. On the other side of you, the rays strike a photosensitive plate. The more x-rays that strike the plate, the darker that portion of the plate. That’s why the resulting image is a negative, with your bones the brightest; they absorbed the most x-rays. Doctors can x-ray image your blood vessels or other soft tissue by injecting or making drink a special contrast dye that absorbs x-rays.
The x-rays that are absorbed by your body aren’t entirely harmless. The x-ray photons can knock electrons away from their atoms, creating ions and starting a minor chain reaction. Richcheting ions alter substances in your body at the atomic level, destroying or altering the DNA of your cells. This ‘ionising radiation’ is what did the damage suffered by those who endured unshielded, very long or frequent x-ray exposures in the days before the dangers of x-rays were understood. Today’s medical x-rays are very safe when used properly, and vastly superior to being cut open every time a doctor needs a look inside you.