In linear molecule, it has $3N-5$ degree of freedom in vibration mode and $3N-6$ in non-linear molecule. I can get idea about $5$ and $6$ which is related to translation and rotation but I cannot find ideas about $3N$ where this number comes from.
The motion of N atoms in three dimensions (x,y,z) produces 3N degree of freedom. Every molecule also has whole body rotation (as the atoms are now bonded together) about each of the 3 axes and translational motion along each axis making 6 motions altogether. If the molecule is linear, rotation about the principal symmetry axis in not measurable so there are only 5 motions. This produces 3N-6 or 3N-5 degrees of freedom. These are the number of vibrational normal modes (number of distinct vibrational types) of the atoms in the molecule. For example, in H$_2$O, N = 3 and as it is not linear (it is bent with O at the apex as HOH) there are 9 - 6 = 3 vibrational normal modes. Two vibrations are totally symmetric, one asymmetric and this is what is observed experimentally.