Deriving photon energy equation using $E=m{c}^{2}$ and de Broglie wavelength

So I was learning de Broglie wavelength today in my physics class, and I started playing around with it. I wondered if it was possible to calculate the energy of a light wave given its wavelength and speed. After rearranging a bit, I plugged it into $E=m{c}^{2}$, and realized I had found the equation for the energy of a photon that I learned at the beginning of my quantum mechanics unit, $E=hf$

$\lambda =\frac{h}{p}$

$p=\frac{h}{\lambda}$

$E=m{c}^{2}$

$E=\frac{p}{c}\cdot {c}^{2}$

$E=\frac{hc}{\lambda}=hf$

I have a few questions about this. Firstly, I do not understand how it can make sense to do $\frac{p}{c}$ in this context, because, as I understand it, light has no mass. How can I come to $E=hf$ using the mass of a massless object?

Secondly, as I was doing those steps, I thought I would be calculating the energy of the entire light ray. I now realize I was finding the energy of a single photon. In hindsight, this makes sense, because the energy of the entire light ray must depend on some length value, correct?

This led me to two other questions: do light rays have some finite length? how do I calculate the energy of a light ray, not just a single photon?