Using reference option of the Scale and Rotate commands you can modify their shapes or position with respect to some pre-existing points or geometries of the drawing.
This article explains the method of using Reference option in the context of Scale and Rotate commands.
Scaling with reference
Scaling an object in AutoCAD is pretty straightforward.
You select the scale command then select the objects(s) then type in the scale factor up to which you want to scale the geometry and press Enter.
To increase the size, you can type any scale factor which is greater than 1 and to decrease the size you can enter any scale factor in between 0 and 1.
70 lessons| Easy Level
If you are absolute beginner of AutoCAD then you can get started right from scratch using this free course.
But in the case of this geometry where we want to scale the door block in such a way it fits exactly the door opening, you can use reference option of scale tool.
In this case, the opening of the wall is our reference.
You can use this option for scaling an AutoCAD dynamic block and xRef too with respect to any reference.

To start, select the scale tool from Modify panel of Home tab or use it's command SC.
Now select the door and press enter.
In this case, I have this door as a block but if you have the door as simple geometry then select all the objects that make the complete door.
Now click on the end of the small line on the door which will be the base point and then select Reference option from the command-line.

Now click on the two endpoints of the door block as marked here as point A and B.

Now you will notice that block will change its size along with the cursor movement.
Simply select “Points” option from the command line and click on the two endpoints of the opening on the green wall shown in the image.
The Door block will resize so that the size of door is equal to the opening in the green wall.
See the animated image below for more clarity.

Rotating with reference
Rotating an object in AutoCAD is also very simple, you need to select the object then specify the base point or the pivot point and then the angle up to which you want to rotate the objects.
But in situations where the object is at any unknown angle but you want to rotate it to a particular angle in the drawing, you can use rotate with reference option.
In the example above we scaled the door block so that it fits completely in the wall gap but the door is still not properly aligned to the wall direction.

To align it, first move the lower left point of Door block to the left side of the wall opening as shown in the image B above.
Now click on Rotate tool on the modify panel of Home tab or use its command RO.
Click on the door block to select it and press enter, specify the point of contact of Block and wall as the base point, and select Reference option from the command line.

Now specify the reference line by clicking on the two end points of the door block and then click again on the second point of the wall opening as shown in the animated image below.

In this way, you can easily take reference of an unknown angle to rotate the object to any known angle using the “Reference” option the Rotate command.
Summary
Reference option is not limited to Scale or rotate rather you can use it in several other situations as well in AutoCAD drawings.
But in every case the underlying logic will remain the same.
Finally, I hope this helped, feel free to sahre your questions if you have any.