Calculating the size of the blur for any background (or foreground) distance
When light enters the lens, each different point on the surface of the lens "sees" the scene from a slightly different perspective. These slight differences in perspective cause objects that are not in the plane of focus to be blurred.
Consider the diagram below. Suppose that the camera is focussed on the subject (assumed to be in a plane) so that the sensor records a sharp image of the subject, but objects away from the subject plane will be blurred to a greater or lesser degree.
Point P is in the background. Consider how P is seen relative to the subject, when viewed from the entrance pupil of the lens. Seen from point T, P is in line with Q. Seen from point U, P is in line with R. From intermediate positions across the entrance pupil, P is in line with points in between Q and R.
When all those views are combined together, the point P appears as a blur, which extends from Q to R. So the distance from Q to R (labelled b in the diagram) is the diameter of the blur disk produced by a small bright light at point P.
A similar thing happens with the point S in the foreground. Viewed from T, S is in line with R. Viewed from U, S is in line with Q. So in the integrated view seen by the whole entrance pupil, S appears as a blur from Q to R.
It is a matter of simple geometry to work out the size of the blur in terms of the distances x and y:
b = ax/y
where:
b is the diameter of the blur in the subject plane,
a is the diameter of the entrance pupil,
x is the distance from point P to the subject plane,
y is the distance from point P to the entrance pupil.
The same formula applies whether P is in the background or in the foreground.