It takes things in consideration like strength of opponent offenses, giving up 400 yards and 40 points to Texas is better than giving it up to Houston.
Also, the type of scoring drives offenses had against a defense. Like it’s better if a defense gives up a a scoring drive of 25 yards because the QB on the previous drive threw an interception giving the team a short field than it is a team scoring on a 75 yard drive. The numbers are adjusted for this.
They don’t count against a defense points scored by an opposing defense due to pick 6, fumble recovery or safety.
I believe they also count how many drives a defense has had to take the field for. If an offense isn’t very good the defense to take the field more so the more drives a defense has to defend the chances are greater there will be more points and yards against, so they adjust for that.