During a colostomy or ileostomy, a surgeon connects parts of the intestines to an opening in the abdomen where stool drains out.