Magnetic moment
Charged particles which have orbital angular momentum have a magnetic moment μ which is proportional to their angular momentum L.
Electrons, protons and neutrons are spin 1/2 particles and they have an intrinsic magnetic moment proportional to their spin S.
Since Sz is quantized, the z-component of the magnetic moment is quantized.

The square of the magnitude of an electrons spin is always  (3/4)ħ2 and the z-component is equal to ±ħ/2.  For an electron the direction of μ is opposite to that of S and  μz =  ±μB, where μB is the Bohr magneton, μB =  9.27*10-24 A m2.

Forces and torques
In an inhomogeneous magnetic field B a force acts on a magnetic dipole.  In a constant magnetic field a magnetic dipole experiences no net force.
In any magnetic field B a magnetic dipole μ not aligned with the field experiences a torque, trying to align it with the field.  The magnitude of the torque is τ = μBsinθ, where θ is the smallest angle between the directions of the vectors μ and B.

Mathematical description
We denote the eigenstates of the Sz operator by |+> and |->.  Sz|+> = ħ/2|+>,   Sz |-> = -ħ/2|->.  A spin 1/2 particle does not have to be in an eigenstate of Sz, it can be in a state described by a linear combination of those eigenstates, a|+> + b |->.  If a spin 1/2 particle is in the state a|+> + b |->, then the probability of measuring Sz = ħ/2 is |a|2 and the probability of measuring  Sz = -ħ/2 is |b|2.