You need to know about noclip for this. Noclip is probably used by developers or something, but who cares. It lets you fly through walls and floors and do all kinds of stuff. To activate it, just press ~ in a level, type "noclip", press enter, and go back to playing (Turning it off is the same way). I'd recommend playing around with it in as many of the levels as you can, just because it's fun.

But to get the cube, you have to use it right.

You need to wait until the last load. This is the one that happens while you're walking though the guts of Apeture on some platform above the deadly water stuff, just before you go into the room where you get clusterfucked by turrets. At any point during this last stretch, activate noclip, and fly through the ceiling until you're above GLaDOS's room (this'll make sense after you play with noclip).

While you're up there, look for a big area not connected to the rest of the facility. as you approach it, it should seem familiar: The parking lot filled with the remains of GLaDOS. You can deactivate noclip and walk around if you want, but the real treasure is down below.

Re-activate noclip and fly through the ground, and you should see a large tunnel sequence above a room. You could just fly to the room, but it's more fun to take off noclip and go through the tunnels. when you enter the room, it should also seem familiar: the cake room, complete with Companion Cube and tons of GLaDOS spheres. Unfortunately, the cake can't be moved, and neither can the spheres, but the Cube can!

If you wish to go about frolicking with the cube, you have to prepare. Objects can't be pulled through walls and ceilings like you, so you'll have to set up a portal to use as a link to wherever you want to go, whether it be outside or back to fight GLaDOS (although the incandescent particle field before GLaDOS's room will burn the Cube, and you don't get another).

What's cool is that these extra locations are the same ones used in the two end scenes, so you can move around the Cube and it'll appear in the end. You could even set is so it's the last thing you see before fading out into Still Alive.