(For a video version of this frequently asked question and answer, click this link.)
Compression is essential for reducing the size of movies so that they can be stored, transmitted, and played back effectively. Compression is achieved by an encoder; decompression is achieved by a decoder. Encoders and decoders are known by the common term codec.
No single codec or set of settings is best for all situations. For example, the best codec for compressing cartoon animation is generally not efficient for compressing live-action video. Similarly, the best codec for playback over a slow network connection is generally not the best codec for an intermediate stage in a production workflow.
To determine what the best settings are for your purposes, read this section on compression and this section on planning your work with final delivery specifications in mind.
When you create a movie for distribution, it is often highly compressed; when you create a movie for an intermediate stage in a post-production workflow, it is usually losslessly compressed (or even uncompressed).
Examples of lossless codecs include Animation and PNG at highest quality settings in a QuickTime container. Losslessly compressed movies often don't play smoothly in a media player, but that isn't relevant because that's not their purpose. See "FAQ: Why does my output file not play smoothly, and why is my output file huge?".
Good examples of highly-compressed formats for online distribution include H.264 and On2 VP6, which are the video codecs used in F4V and FLV files. See "Render and export a composition as an F4V or FLV file".
If you want even more control over encoding and compression options, consider using Adobe Media Encoder or another dedicated encoding and compression application to convert losslessly encoded master files or image sequences exported from After Effects into files for final delivery.
In many cases, you can and should use encoding presets in Adobe Media Encoder, which are created for the specific purpose of setting up exports for common formats and uses. For information about several common encoding presets, see this:
Europe, Middle East and Africa