I hope you’re not exporting from After Effects but using the Render Queue instead.
Depending on which platform you are on, and what applications you have available, there are several options for optimizing file size and quality.
Understand this: any form of compression (other than RLE) will result in a compromise between file size and quality, it’s inevitable when you are discarding data.
If you have Apple Compressor try rendering the After Effects file with no compression (Animation, highest quality) then passing it to Compressor for H264 rendering. You can preview the results and tweak the settings before submitting the job compression. I’ve found that Compressor, while slower, does a better job than Adobe Media Encoder in terms of file size / quality.
If you have Media Encoder you can also preview and tweak the settings before encoding.
The final file size depends entirely on the type of images, motion, color (i.e. large expanses of a single color compress well to small file sizes) and audio in the file.