The maximum energy a photon can transfer is indeed given by E = hf as you say. This is what happens when the photon is 'absorbed' (i.e. disappears). It is also possible for a photon to be 'inelastically scattered' and transfer only part of its energy. In this case the photon (or another one; photons have no identity tags) comes out of the encounter with a lower energy, such that E = h (f {in} - f {out} ).

There are many ways to establish this experimentally. Perhaps the simplest is obtained via photoionization: The absorption of light by an atom occurs at several very sharp and specific frequencies, seen as lines in the absorption spectrum. These lines get closer together at higher frequencies until they reach a 'series limit' where they merge into a continuous absorption.

The lines mean that photons of a particular frequency have been absorbed to produce a higher allowed energy level of the atom from its normal state. The 'series limit' is where a photon has transferred enough energy to remove an electron completely from an atom, and form a positive ion.

This same 'ionization energy' can also be measured electrically. So the **frequency** of the photon can be directly related to the **voltage** of the electrical pulse required to produce the same effect, and the electrical **energy** is simply the **voltage** multiplied by the **charge** on an electron.