While Ogg Vorbis provides an excellent open-source alternative for every use of MP3, and FLAC is best for lossless audio encoding, MP3 is still the most widely compatible format out there, so it is important to know how to produce it properly.
Start with the highest quality source file possible, preferably one recorded to a lossless format.
It is wasteful to encode with a high constant bit rate (CBR) to achieve high quality. Vairable bit rate (VBR) encoding can produce quality just as good while saving significant space / bandwidth.
Use the highest quality VBR setting on your MP3 encoder. Unless you really need to save space / bandwidth, then choose a somewhat lower VBR setting. I personally see no use for CBR encoding in most situations today.
The LAME MP3 encoder is more or less today's industry standard. It's open-source, cross-platform, and included or supported by an extremely wide range of audio production software. You can use its command-line encoder without much hassle, or you can find one of the many GUI tools that use it.
FLAC to max-quality VBR MP3:
flac -dc "example.flac" | lame -V0 - "example.mp3"
WAV to max-quality VBR MP3:
lame -V0 "example.wav" "example.mp3"
FLAC to max-quality VBR MP3 Shell script with metadata preservation:
FLACToMP3
Metadata is important! No one likes to listen to Unknown Track by Unknown Artist.
MP3 metadata is stored in an ID3 tag. A few ID3 fields I'd like to note are Year, Lyrics, Comment (useful for source info, credits, and shoutouts), and of course Album Art (which can be a JPG or PNG image). I recommend version 2.3 ID3 tags, as at least one modern portable MP3 player I've tried chokes on v2.4 tags.
A good command-line MP3 tag swiss-army-knife is eyeD3, and a very powerful GUI MP3 tagger with easy batch processing is EasyTAG.