The rectum has little shelves in it called transverse folds. These folds help keep stool in place until you're ready to go to the bathroom. When you're ready, stool enters the lower rectum, moves into the anal canal, and then passes through the anus on its way out.
Learn more about the anatomy of the large intestine.
Goldberg, Stephen. Clinical Anatomy Made Ridiculously Simple. MedMaster, 1999.
Kapit, W. and Elson, L. The Anatomy Coloring Book. Harper Collins, 1977.