There are lots of misguided "explanations" out there which may contribute to your confusion. Here are the two basic facts:
1) The cosmological expansion causes redshift in the spectrum of distant object (Hubble's law).
2) The spectrum of an object that moves away from the observer is red-shifted (Doppler effect).
Many well-intentioned (but misguided) people will explain that the latter can be used to explain the former because, within some uniformly expanding stuff, the relative speed of two points is indeed directly proportional to their distance (the usual analogy is to consider the points at the surface of a toy balloon whose size increases at a constant rate).
This look nice an convincing at first sight. In fact a correct counterpart of Hubble's law exists for the aforementioned toy balloon (or also between particles within an ordinary explosion) precisely for the straightforward reason given in the previous paragraph.
However, when the expansion of the Universe itself is concerned, the analogy is best abandoned because there is no longer any established "background" in which the concepts involved can be naively trusted (including the notion of distance between widely separated points). Instead, we must rely on local concepts (local geometry) which are well-defined and more fundamental.
To be blunt, when the fabric of our legendary "expanding balloon" is the fabric of spacetime itself, the vibrations of travelling photons can only be expressed in terms of the vibrations of that fabric itself. As the fabric expands, so does the wavelength of the photons, which are thereby "redshifted".
Photons that were emitted when the Universe was (1+z) times smaller than today are observed today with a redshift of z (which is to say that they have a wavelength (1+z) times larger than it was when they started their journey).
The first link below discusses the issue in the framework of a simple multiple-choice question
The second link provides a more detailed in-depth explanation.
The third link provides a robust derivation of the Doppler effect in a relativistic context.
The fourth link is an overview of related basic physical concepts.