I usually keep my Glock 19 under the mattress, right under much chest so I know where to get it.
You could keep it under your pillow, but just make sure not to have a round chambered. I dont keep it there, since I usually move a lot during the night, and wouldnt want it knocked out, and if SHTF, I wouldnt want it laying on the floor while im searching under my pillow.
I was thinking about attaching some sort of pouch to the bedsheets at the head of my bed where I could keep a gun. Maybe a path of denim attached with safety pins? Im not sure, but I think it would be much more accessable than if it were under the bed or in my nightstand (which is where I also keep a .22 magnum revolver).
I wouldnt want to keep it in the open though, becuase that last think I would want it an unarmed burglar to become armed with my own weapon.