The Principle 
Fermat's Principle, also known as "The Principle of Least Time" states that:
- "Light travels through the path in which it can reach the destination in least time".
It is a fundamental law of optics from which the other laws of geometrical optics can be derived.
Derivation for Law of Reflection 
The derivation of Law of Reflection using Fermat's principle is straightforward. The Law of Reflection can be derived using elementary calculus and trigonometry. The generalization of the Law of Reflection is Snell's law, which is derived below using the same principle.
The medium that light travels through doesn't change. In order to minimize the time for light travel between two points, we should minimize the path taken.
1. Total path length of the light is given by
3. When we substitute both values of d1 and d2 for above, we get
4. In order to minimize the path traveled by light, we take the first derivative of L with respect to x.
5. Set both sides equal to each other.
6. We can now tell that the left side is nothing but and the right side means
7. Taking the inverse sine of both sides we see that the angle of incidence equals the angle of reflection
Derivation for Snell's Law 
The derivation of Snell's Law using Fermat's Principle is straightforward. Snell's Law can be derived using elementary calculus and trigonometry. Snell's Law is the generalization of the above in that it does not require the medium to be the same everywhere.
To mark the speed of light in different media refractive indices named n1 and n2 are used.
Here is the speed of light in a vacuum and because all materials slow down light as it travels through them.
1. Time for the trip equals distance traveled divided by the speed.
3. Substituting this result into equation (1) we get
4. To minimize the transit time, we take the derivative with respect to the variable and set it equal to zero:
5. After careful examination the above equation we see that it is nothing but
6. This leads to
7. Substituting for and for we get
8. Multiplying through by gives us our result