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?".
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 is created for the specific purpose of setting up exports for common formats and uses. For information about several common encoding presets, see this:
"FAQ: How do I export a movie for YouTube, Vimeo, iPad, iPhone, or Apple TV?"