"Pick a number and I'll guess it": the math behind the magic

On Vsauce2, Kevin Lieber explains the mathematical magic that enables mentalists to confound audiences by correctly guessing the number they've picked. Even though I know how it's done, it still confounds me.