Procedure for reducing the degrees of freedom of an arbitrary system

Your system is currently represented by two coordinates, $x$ and $y$. Without any constraints, any point $(x,y)$ on the plane could be a valid state of your system. But you have a constraint: valid states must obey the equation $x+\cos y=5$. This restricts the space of valid states for your system from a two-dimensional plane to a one-dimensional curve, specifically this curve:

enter image description here

Since your state space is constrained to be one-dimensional, you now only need one parameter to distinguish between different states. This parameter is your one degree of freedom. For example, you might choose to express the state of the system as solely a function of the single parameter $w$, where:

$$y=w$$ $$x=5-\cos w$$


Technically, given a $3N$-dimensional position manifold, it is implicitly assumed that the zero-locus $$\bigcap_{\ell=1}^m\{f_{\ell}=0\}$$ for the $m$ independent holonomic constraints is an embedded submanifold, which necessarily have dimension $3N-m$. Hence the constrained system has $3N-m$ generalized coordinates/degrees of freedom.

See also this related Phys.SE post.