Rayo vs. relámpago

The Spanish nouns 'rayo' and 'relámpago' are both associated with the natural phenomenon of lightning. While they are often used interchangeably, there is a nuanced difference in their usage which relates to the various elements of a lightning strike.

Rayo

'Rayo' in Spanish primarily denotes the physical manifestation of lightning, particularly the bolt that one sees striking the ground or another object.
El rayo impactó el árbol y lo partió en dos.
(The lightning bolt hit the tree and split it in two.)
Ella fue golpeada por un rayo durante la tormenta.
(She was struck by a bolt of lightning during the storm.)
Se puede ver el camino de los rayos durante una tormenta eléctrica.
(You can see the path of lightning bolts during an electrical storm.)

Relámpago

'Relámpago' in Spanish refers specifically to the flash of light produced by a lightning strike. It is derived from the verb relampaguear, which describes the act of flashing or sparkling.
El relámpago iluminó todo el cielo nocturno.
(The flash of lightning lit up the entire night sky.)
Es posible ver un relámpago sin oír el trueno si estás lo suficientemente lejos.
(It's possible to see a flash of lightning without hearing thunder if you're far enough away.)
Los relámpagos son comunes en las tormentas tropicales.
(Flashes of lightning are common in tropical storms.)

Summary

'Rayo' and 'relámpago' both refer to elements of a lightning strike, but whereas 'rayo' typically represents the physical bolt, 'relámpago' represents the light flash that accompanies it.