1. You may need to trim the timeline so that only the section you want will be exported. When you create a new composition, you are asked to define its length, but if you need to change its length, you can do so by going to Composition>Composition Settings… or using the Cmd+K keyboard shortcut. Set the duration to match your composition.
You can also trim the composition down from within the timeline panel using the “work area.” At the beginning and end of the timeline, you’ll find blue handles that can be dragged to define the “work area.” (There are actually two sets of blue handles – the smaller ones can be used to zoom the view of the timeline in and out.) You can think of the work area handles as After Effects’ equivalent of an in and out point. If you drag the work area handles to the section of the timeline you want to keep, then right-click on the lighter area directly between them, you’ll see a few options appear. Select “Trim Comp to Work Area” to remove everything outside the handles and shorten the length of the composition. However, even if you don’t want to trim the comp down, you can use the blue handles to choose the area you want to export.
2. Once you have your work area defined, export your composition using the Render Queue by going to Composition > Add to Adobe Media Encoder. If you haven't already opened the program, it takes a really long time. You will think something is wrong. It's not :) You'll know you're ready when AME is open, and your composition title appears in the queue. >>>
3. Select the output type from the dropdown menu directly under your comp name. This is what type of file you want to create. The most common types are H.264 or Quicktime for video, and Animated GIF for, well, a GIF.
4. Next click on the blue text on the right under "output file" to select the location to save your new file. If you don't do this, your rendered file will be saved in a temporary AME folder, and will be very difficult to find.
Finally, click the green play icon, and you're done!