Question - How is it done?
Honestly - It's usually done with samples - no actual, original, music is ever recorded in the vast majority of modern rap music. You can buy royalty-free sample banks (like these:
http://www.sweetwater.com/c990--Virtual_Instruments_Loops ) and mix/match cut/chop them to your rap-beating heart's content.
As long as you have a computer to work with, a software solution for handling samples/loops (like the ones mentioned before - It may be worth noting that Fruity Loops is hands-down the most commonly used tool for the job...and I don't think I saw Acid mentioned anywhere, but it is also fairly commonly used) will be much cheaper than an equivalent hardware solution (like these
http://www.sweetwater.com/c657--AKAI--DJ_Groove_Production There are other brands, but those AKAI MPC things are the most commonly used... they are even endorsed in quite a few rap songs as being the shiznizzle fo shizzle nizzle).
For the minority of 'beat composers' who do actually play and record some original music (it sounds like you are wanting to fit in here), they either use keyboards with nice patches built-in (Triton, Motif etc: See here:
http://www.sweetwater.com/c512--Keyboard_Workstations ) or simple midi controllers (like this for example:
http://www.sweetwater.com/store/detail/Keystation88es/ ) to control synthesizers - which can be either standalone hardware units ( see:
http://www.sweetwater.com/c504--Sound_Modules and also:
http://www.sweetwater.com/c517--Table_Top_Synths ) , or, probably more commonly used are VSTi-style 'Virtual Instruments' (see:
http://www.sweetwater.com/shop/computer-audio/plugins/ and follow any links under the Virtual Instrument section). Of course, there is the occasional 'beat' that has some real audio recorded for it (acoustic guitar on that Nelly song, and Travis Barker's drums on that Soldier Boy song come to mind) but those are few and far between...
It takes considerably more time, skill, talent, and investment to actually make some music for a rap-beat, and most of the audience will not know the difference, or even care 1 teeny tiny little bit if they did know, and one could reasonably assume that's why the vast majority of rapbeats are no more than arrangements of pre-recorded samples.
I think that's really about all there is to know about it - Hope that helps!
Ahh, one more thing - if you can get past the corny intro, and actually watch the whole thing, this guy pretty much shows all these things in action:
https://www.youtube.com/watch?v=S7wZD1ewxB4&feature=related Everything he's doing on that AKAI MPC thingy can be done in software like Fruity Loops or whatever, and the loop disks/sample libraries are more-or-less the digital equivalent of that vinyl sample-record he's recording samples off of. This guy has just been around a bit longer than Fruity Loops and samplebank CDs so he keeps working with the tools he's familiar with.
edit: Of particular interest is the end, which is kinda cut off - he says "In my experience, the best beats, I get together in about ten minutes" - that really says it all right there...straight from the mouth of one of the most successful (and highly paid) professionals in the field. Look at his unbelievable list of credits here: http://en.wikipedia.org/wiki/Just_Blaze (for those who don't feel like clicking, he's produced for Jay-Z, Snoop Dogg, Kanye West, Usher, Mariah Carey, and pretty much every other successful Rap/Hip Hop/R&B artist... ever.)