The concept of degrees of freedom as used in the kinetic theory specifies the number of independent ways in which an atom or molecule can take up energy. It depends only on the possibilities of motion of the atom or molecule.
Gas molecules of all types have x-, y- and z components of velocity that are entirely independent of one another. Thus, they have three ways to move in translation, i.e., three degrees of translational freedom.
An atom (or a monatomic molecule, i.e., a molecule containing a single atom, e.g., He) treated as a point mass, has no rotational motion. Hence, it has only three degrees of translational freedom.
A diatomic molecule, in addition to translation, can rotate about axes perpendicular to the line connecting the atoms, as shown in below figure, but not about that line itself. Therefore, it has only two degrees of rotational freedom.

Two degree of rotational freedom of a diatomic molecule
Further, the two atoms may oscillate alternately toward and away from one another along the line joining them, as if connected by a spring. As a, i harmonic oscillator can have potential energy as well as kinetic energy, a diatomic molecule is regarded to have two degrees of vibrational freedom. Thus, at high enough temperatures, a diatomic molecule has seven degrees of freedom : three of translation, and two each of rotation and vibration.
Notes :
(1) That a monatomic gas molecule does not have rotational energy, and that a diatomic molecule does not have a third rotational degree of freedom corresponding to rotation about the line joining the atoms, are explained by quantum theory.
(2) Also according to quantum theory, rotational and oscillatory motions begin at certain higher temperatures. For a molecule of a diatomic gas (like hydrogen), only translation is possible at very low temperatures (below about 100 K). As the temperature increases, rotational motion can begin; so that, at room temperature, a diatomic molecule has only five degrees of freedom-behaving like a pair of atoms rigidly connected like a dumbbell. Oscillatory motion can begin only at quite high temperatures substantially above room temperature (usually of the order of thousands of kelvin).