Sudoku How Does It Work?

Ok I know how to play, But ive alway been wondering howto people make it, is it based on a mathematical algorithm. Or how do they knwo where to put the few number which will lead to a full set if you get me.