Surgery may be necessary for IBD when medical management fails to control the disease or when complications such as strictures, fistulas, or abscesses develop. The type of surgery depends on the specific condition and the affected area of the digestive tract.