MIDI has got nothing to do with sound. You really got to see that. As to playing notes: when you push a key, your keyboard sends a MIDI 'note on' message, containing 3 bytes: a status byte, telling what kind of information it is (note on in this case), a byte that contains the note number, and a byte containing the velocity.
When releasing the note, your keyboard sends a similar 'note off' message.
This message is received by a some device.
If this device is an expander or sampler: The device gets the message, and looks what it has to do with it. For a 'note on' message: it gets the messages, and plays the sound that you want it to play. This can be any sound that is in the expander, or for a sampler, even any sound that you put in it. It is this device that produces the sound. The MIDI messages only tell the device when, which note and on which velocity.
So which sound will be played is something else that depends on the settings of the expander or sampler.
If you record the MIDI stream with a sequencer (hardware or software), you just record a sequence of messages. So you just remember which message was received at what time. Afterwards, when playing back the stream, you might as well connect a totally different device on it. For example, a sampler on which you recorded 'Uuuuuugly'. It will play the tune with your 'Uuuuuugly' sample.
If you have more questions on the midi protocol, don't be affraid to ask. I implemented it in my home made MIDI-CV convertor. As long as it's not a device-specific question, I can answer it...