An orbital is made up of 2 electrons. The orbitals are filled up satsifying all the rules viz. Hund's Rule, Pauli's Exclusion Principle and Aufbau Principle and any orbitals left with only 1 electron is considered unpaired.
For example, the element P, has an atomic mass of 15. So the electron configuration is 1s^2, 2s^2, 2p^6, 3s^2, 3p^3 (The exponents add up tp 15).
Once you figure out the electron configuration, you fill up the corresponding orbitals with electrons, any left with one is considered unpaired. Since 1s can only hold 2 electrons, and P has 15, that's obviously filled and has no unpaired electrons. The same is for 2s which holds 2, 2p which holds 6, 3s which holds 2.
However 3p can hold 6 electrons and in order for that to be filled up you would need to have an element of 18 electrons. So you fill up as much as you can in 3p by first adding 1 electron to each energy level. 3p has 3 energy levels and there are only 3 electrons left to distribute, so each of those energy levels only gets 1, because you have to fill them all with one before you can start adding a second.
So since you are only able to fill one electron in each of the three energy levels of the 3p orbital, that leaves the orbital open for 1 more electron in each of its energy levels. So there are 3 unpaired electrons in P.