Generalized coordinates in classical mechanics are a way to describe the phase space configuration(relative to a reference) of a system. In simple words, these can be used to simplify description of a system by using a small set of (not necessarily independent) variables. Here the term coordinates is not restricted to position, but can represent velocities, momenta etc. as well.
Let’s consider an example. A person is running on a circular track. His motion with respect to the centre of the circle can be represented in 2D space as his position in x and y directions, as shown.
However, the position coordinates in these two directions are not independent of each other. They are related by the equation of a circle:
x² + y² = r²
Hence, we can reduce the number of independent coordinates by introducing a variable θ, such that the two position coordinates are given by
x = r cos θ, y = r sin θ
Thus we moved from cartesian coordinates to polar coordinates. Since the radius is constant, the only variable is θ (we describe θ here as the angle made by the position vector with the reference line (blue) measured counter-clockwise as seen from above). The calculations become much easier because we have a single variable to work with.
In general, for a system of N particles we would need 3N cartesian like coordinates to describe their positions (3 direction for each particle) completely at some instant of time. If the particles are all independent of each other(i.e. no forces between any pair of them) then they are said to have 3N degrees of freedom because they (all N of them) are “free” to move in 3 directions each with respect to a suitable reference frame (hence 3 times N = 3N).
However, if they are bound by some constraint (a force that does no work but limits their motion in some way) e.g. a bead on a wire is bound to move along the wire (it cannot go beyond it hence the wire is the constraint), it can move only in one direction(back and forth) along the wire. The 3 degrees of freedom(if the bead was free to move in all three directions) are reduced to one, and the motion can be described using only one coordinate along the wire.
Generally, we represent generalized coordinates with qi and generalized velocities with q̇i. Note that generalized velocities are nothing but time derivatives of generalized coordinates.
Remember, generalized coordinates are generally selected so as to simplify the mathematical description of a problem, and may or may not be dependent on each other. In some cases, they are equal to the degrees of freedom, but they need not be. Also, they describe the configuration of a system uniquely with respect to a reference configuration.
Where did they come from?
Lagrange regarded principle of virtual work to be more fundamental than the principle of least action and showed that it can be used to solve all problems of equilibrium in mechanics, as the later does not actually account for non-conservative forces.
He derived equations of motion from the d’Alembert’s principle and formulated them with the help of generalized coordinates, thus representing d’Alembert’s principle in a more useful form.
The Euler-Langrange equations of motion are:
j = 1,2..N for N generalized coordinates
qj stand for jth coordinate and L stands for Lagrangian(More on these in upcoming posts).
 The smallest set would be the degrees of freedom of that system and all of those would be independent of each other.