I'd like to add this is NOT the recommended way, as running the compiler shouldn't be done as root.
look at the /usr/src directory with "ls -ld /usr/src". Most systems make it owned and writable either by group "src" or by group "staff". Add the user you want to use for compiling software packages to that group, then you can do all steps as normal user except the final installation of the compiled binaries (THIS is where sudo should be used).
Side node especially for kernels on debian/ubuntu: There is the very nice helper package "kernel-package". Install it!
Then, configure your kernel normally (make menuconfig or make xconfig, whichever you like better) and when you've finished, do something like:
make-kpkg --initrd --rootcmd fakeroot --revision [your hostname].1.0 kernel_image
This will still run as normal user and create a kernel .deb package which you can install using "sudo dpkg -i".