Let R be a homogeneous ring over an infinite field, I⊂R a homogeneous ideal, and $\frak a$⊂I an ideal generated by s forms of degrees d1,…,ds so that codim($\frak a$:I)[ges ]s. We give broad conditions for when the Hilbert function of R/$\frak a$ or of R/($\frak a$:I) is determined by I and the degrees d1,…,ds. These conditions are expressed in terms of residual intersections of I, culminating in the notion of residually S2 ideals. We prove that the residually S2 property is implied by the vanishing of certain Ext modules and deduce that generic projections tend to produce ideals with this property.