In Hamiltonian formalism, the phase space is a symplectic manifold i.e. a manifold $M$ equipped with a 2-form $\omega$ which is non-degenerate and closed. In a constrained system, the dynamical variables are constrained to lie on a submanifold $N$ of $M$. If the restriction of $\omega$ to $N$ is 0, then $N$ is called a coisotropic submanifold and the constraint is called first class. If the restriction of $\omega$ to $N$ is non-degenerate, then $N$ is called a symplectic submanifold and the constraint is called second class. A general $N$ can always be locall written as a product $N_1 \times N_2$ with $N_1$ coisotropic (first class) and $N_2$ symplectic (second class).
Same thing in a slightly different language: the symplectic structure defines a Poisson bracket $\{,\}$ on the algebra of functions on $M$. The constraints are the equations $f_i=0$ defining $N$. The constraints are called first class if $\{f_i,f_j\}=0$ up to the constraints, for all $i$, $j$. The constraints are called second class if the matrix $\{f_i,f_j\}$ is non-degenerate. In general, up to a change of variables, one can write the matrix of Poisson brackets $\{f_i,f_j\}$ in a block diagonal form: the first block being zero and the second block being non-degenerate. Constraints corresponding to the first block are called first class, the ones corresponding to the second are called second class.
The distinction between primary and secondary constraints appears in the context of the Hamiltonian description of a system given in Lagrangian form. Primary constraints are the constraints which are there if the momenta are not independent (if the matrix of second derivatives of the Lagrangian with respect to the velocities is not invertible). Secondary constraints are extra constraints which are imposed by consistency of the primary constraints with the equations of motion.
If by number of degrees of freedom, one means the dimension of the symplectic manifold where the Hamiltonian dynamics is well-defined without constraints, it is $dim M - 2 n_1-n_1$ where $n_1$ is the number of first class constraints and $n_2$ is the number of second class constraints. Indeed, for a second class constraint, one simply has to restrict ourselves to the constrained submanifold but for a first class constraint, one has to quotient this submanifold by redundancies of the description ("gauge transformations"), which are as numerous as the first class constraints (coisotropic reduction).
The original reference on first/second class constraints is Dirac:
https://books.google.co.uk/books?id=GVwzb1rZW9kC&redir_esc=y
which is still worth reading. A more recent and complete reference is the book by Henneaux and Teitelbaum, "Quantization of gauge systems":
http://press.princeton.edu/titles/5156.html
(one can easily find pdf for these two references but I am not sure of their legal status).