Hiding information on grayscale images has been drawing much attention in recent years. In pervious techniques, many schemes like Zhang and Wang's method or Sudoku method use magic matrix as a plane reference to modify the LSBs of cover images. To further improve the hiding capacity and visual quality, we propose the so-called magic cube based (MCB) information hiding scheme. MCB is an early attempt to use three-dimensional reference to achieve information hiding in grayscale image. Secret data are embedded in the cover pixel LSBs by utilizing spatial coordinates. MCB has a larger probability to modify fewer pixels in the whole image. The comparison experiments show that MCB achieves higher hiding capacity and better visual quality with impressive undetectability. Moreover, our method can easily avoid the overflow problem in the embedding process and the hiding capacity is flexible by operating on magic cubes with different scales.