How to imagine the electromagnetic waves? I've learned at school, that the electromagnetic radiation consists of photons. And all the frequencies of the wavelengths of photons define electromagnetic spectrum. The lower wavelengths are ionizing radiation. In the middle of the spectrum there is the visible light, and above that infrared, microwave, and radio waves.
But the thing nobody told me, is that: How is it possible to imagine a wave? I don't think, that the photon is physically moving sideways, and that is called the waving. But what is it then?
The explanation of the wavelength is, that it is a spatial period of the wave—the distance over which the wave's shape repeats. But what is this wave exactly? How can a single photon has it?
 A: 
I've learned at school, that the electromagnetic radiation consists of photons.

The electromagnetic wave is described by the solution of classical maxwell's equation which has a sinusoidal dependence for the electric and magnetic fields perpendicular to the direction of motion of the wave. It is called a wave for this reason and the frequency is the repetition rate of the sinusoidal pattern.
Quantum mechanically the classical wave is an emergent phenomenon. It is built up by photons with an energy associated with the observable frequency of the emergent classical beam, E=h*nu.
A photon only has this energy definition and a spin 1 h orientation either in its direction of motion or against it, where h is Planck's constant. The beam built up in the image, is built up by the individual photons ( middle image).

This happens because the quantum mechanical wavefunction of a photon has the E and B information in its complex form, ( a solution of a quantized maxwell equation) and the superposition of photons builds up the classical fields with the frequency nu. 

And all the frequencies of the wavelengths of photons define electromagnetic spectrum. 

The frequencies of the classical electromagnetic spectrum define the energy of the photon, h*nu, not the photon the frequency, because it is only the probability of detection distribution of a single photon that "waves" in space, not the photon itself.

How is it possible to imagine a wave? I don't think, that the photon is physically moving sideways, and that is called the waving. But what is it then?

One need not imagine the photon as a wave. Only the probability of detecting it, as seen in this answer.

The explanation of the wavelength is, that it is a spatial period of the wave—the distance over which the wave's shape repeats. 

This is true for the emergent classical wave.

How can a single photon has it?

A single photon has only a detection probability distribution that "waves", as explained above. It is not a wave. 
A: Maxwell's equations have certain stationary states. We can obtain these so called modes and each classical waveform can be built as a linear combination of these modes.
In process called second quantization, we (hand wavingly) put particles into these modes. These particles are photons. Each mode can have 0, 1, 2 photons.
But there is more: we know from the uncertainity principle that no dynamic degrees of freedom can be absolutely confined, since that would imply infinite momentum. That holds for the coefficient of this electromagnetic mode as well, and hence there is always vacuum fluctuations of the electromagnetic field.
In other words, each mode can be represented as a quantum oscillator. (One derives an equation of motion for a mode, and realizes that some quantities behave like momentum and some like position). Quantum 101 tells that the modes of a quantum oscillator are quantized.
Now, we can have these modes in weird shaped cavity and hence we can have very structured modes with indefinte momentum. However, usually photons are measured in far field of the sample such that they have definite momentum and energy.
So, photon does not oscillate to any direction. Photon is an "occupation" of an electromagnetic mode which oscillates.
One more analogy to help to think about this: One could take a vibrating string and solve it's fundamental mode (say 440Hz). If this would be quantized, one can nerver find the string at rest due to uncertainity principle. Further, we will find that the string can only have quantized amount of energy. In other words, the magnitude of the vibrations is quantized. In other words, we can count how many (integer) energy quanta there are in the string. Let's all this quanta a vibron. Now, that is essentially the same thing to electromagnetism and phonons save Lorentz invariance, special relativity on masslesd particle, commutation relations of spin 1-particles, and some other compex stuff out of scope.
