$$F=G\dfrac{m_1m_2}{r^2}$$
I wanted to know why is $r^2$ there? ($r^2$ means the square of the distance between the $2$ objects)
$$F=G\dfrac{m_1m_2}{r^2}$$
I wanted to know why is $r^2$ there? ($r^2$ means the square of the distance between the $2$ objects)
 
    
    From Kepler's law, Newton knew that for circular orbits of radius $r$, $T^2\propto r^3$. However, since Newton also knew calculus and kinematics, he knew that the centripetal acceleration of an object in uniform circular motion is $a_c=rw^2$. Or, in terms of the time period, $a_c=\frac{4\pi^2 r}{T^2}$. Combining this with the Kepler law, Newton could deduce that $a_c\propto\frac{r}{r^3}$, or, $a_c\propto\frac{1}{r^2}$.
Moreover, Newton also knew his second law. So, he deduced that if a celestial object is in a circular orbit then since it is performing a motion that has non-zero acceleration, there must be a force acting on it. Since the acceleration of such a celestial object was simply the centripetal acceleration $a_c$, the force on it must be $ma_c$ towards the center. Let's call this force $F_g$ then $F_g=ma_c\propto\frac{m}{r^2}$. But clearly, if, say the Earth (mass $M$) is applying this force on the Moon (mass $m$) then the Moon should also be applying the same force (in the opposite direction) on the Earth according to the third law of Newton. This can only be generically true if $F_g$ is also proportional to $M$. Thus, $F_g\propto\frac{Mm}{r^2}$.
Newton's genius was also in realizing that this force is not limited to describing the dynamics of celestial bodies but also applies to the dynamics of objects falling to the Earth on ground. He could verify this by confirming that the acceleration of freely falling objects near the ground was in agreement with the prediction from his universal law of gravitation.
Newton's law of gravity cannot be derived in the bounds of Newtonian mechanics. As for the inverse square law it can be understood as geometric dilution corresponding to point-source radiation into three-dimensional space (see diagram)  .This article might help you.
.This article might help you. 
What Newton did was incredible even for today standards. Basically he knew from Kepler studies (Kepler's laws are experimental laws) that the orbits of the planets were ellipses (conic sections more generally), so he asked himself:
He then answered the question proving mathematically that this force is a force that goes like $1/r^2$
I want you to point out how hard and non-trivial this problem is, he didn't simply guess the force saying it could be $1/r^2$ and then proved it produces elliptical orbits, he knew that this results would "prove nothing", because it would only prove that $1/r^2$ gives you elliptical orbits, but how can you be sure that there isn't a different force that goes like, say $1/r^\alpha$ that gives you elliptical orbits aswell?
He solved the direct problem: Given the orbits, what's the force?
I want to point out that, as far as i know, in no university they show us the direct problem, which is way harder than the indirect one. They teach us how to solve the indirect problem, which consists in proving that to a force $\propto 1/r^2$ corresponds orbits that are conic sections.
If you want to go deeper in Newton work I strongly advise you to read the magnificent book by Chandrasekhar - Newton's Principia for the common reader
 
    
    Newton knew Kepler's Laws, which state that:
In fact, only the first law is needed to derive the form of the force of gravity, as I will now show.
If we work in 2D polar coordinates aligned with the orbital plane of the planet with the Sun at the origin, then the equation of the path of a planet is $$ r = \frac{p}{1 +e\cos\phi}\tag{1} $$ (see wikipedia for a derivation). In this coordinate system, $$ \mathbf{e}_r = \left(\begin{matrix} \cos\phi\\ \sin\phi \end{matrix}\right) \quad\text{and}\quad \mathbf{e}_\phi = \left( \begin{matrix} -\sin\phi\\ \cos\phi \end{matrix} \right) $$ are the basis vectors. The angle $\phi$ is a function of time, so the basis vectors are also. Differentiating them gives that $$ \dot{\mathbf{e}}_r = \left( \begin{array}{cc} -\dot{\phi}\sin\phi\\ \dot{\phi}\cos\phi \end{array} \right) = \dot{\phi}\mathbf{e}_\phi, \quad \dot{\mathbf{e}}_\phi = \left( \begin{array}{cc} -\dot{\phi}\cos\phi\\ -\dot{\phi}\sin\phi \end{array} \right) = -\dot{\phi}\mathbf{e}_r. $$ The position vector of a particle is $\mathbf{r} = r\mathbf{e}_r$, so its velocity and acceleration are \begin{align} \dot{\mathbf{r}}&= \dot{r}\mathbf{e}_r + r\dot{\mathbf{e}}_r = \dot{r}\mathbf{e}_r+r\dot{\phi}\mathbf{e}_\phi \\ \ddot{\mathbf{r}} &= \ddot{r}\mathbf{e}_r + \dot{r}\dot{\mathbf{e}}_\phi + \dot{r}\dot{\phi}\mathbf{e}_\phi +r\ddot{\phi}\mathbf{e}_\phi + r\dot{\phi}\dot{\mathbf{e}}_\phi = (\ddot{r}-r\dot{\phi}^2)\mathbf{e}_r + (2\dot{r}\dot{\phi}+r\ddot{\phi})\mathbf{e}_\phi \end{align}
It is sensible to assume that the force between the two bodies acts along the line connecting them, since this is the only unique direction defined in space. It must also depend only on the distance between them, as space is invariant with respect to rotations about this line so the force cannot depend on the angle. That is to say, $\mathbf{f} = f(r)\mathbf{e}_r$.
In this case the angular momentum $\mathbf{J} =\mathbf{x}\times \mathbf{p}$ of the particle in orbit must be conserved, as $$ \frac{d}{dt}\mathbf{J} =\underbrace{\dot{\mathbf{x}}\times \mathbf{p}}_{\mathbf{v}\times m\mathbf{v} = \mathbf{0}}+\underbrace{\mathbf{x}\times\dot{\mathbf{p}}}_{r\mathbf{e}_r\times f(r)\mathbf{e}_r = \mathbf{0}}=\mathbf{0} $$ The magnitude of angular momentum is $J = r \cdot mv = mr^2\dot{\phi}$, so $$ \dot{\phi} = \frac{J}{mr^2}, \quad \ddot{\phi} = -\frac{2J}{mr^3}\dot{r} $$ Finally, to find $\ddot{\mathbf{r}}$ it is necessary to compute $\dot{r}$ and $\ddot{r}$ by differentiating equation (1): \begin{align} \dot{r} &= -\frac{p}{(1+e\cos\phi)^2}\cdot(-e\sin\phi)\dot{\phi} = \frac{r^2}{p}\cdot e\sin\phi\cdot\frac{J}{mr^2} = \frac{Je}{mp}\sin\phi \\ \ddot{r} &=\frac{Je}{mp}\dot{\phi}\cos\phi =\frac{J}{mp}\cdot\frac{J}{mr^2}\cdot\left(\frac{p}{r}-1\right) = \frac{J^2}{m^2}\frac{1}{r^3} - \frac{J^2}{m^2p}\frac{1}{r^2} \end{align} Plugging this in gives \begin{align} m\ddot{\mathbf{r}} &= m\left[\left(\frac{J^2}{m^2}\frac{1}{r^3} - \frac{J^2}{m^2p}\frac{1}{r^2} - r\cdot\left(\frac{J}{mr^2}\right)^2\right)\mathbf{e}_r + \left(2\dot{r}\cdot\frac{J}{mr^2}+r\cdot\left(-\frac{2J}{mr^3}\dot{r}\right)\right)\mathbf{e}_\phi\right]\\ &= -\frac{J^2}{m^2p}\cdot\frac{m}{r^2}\mathbf{e}_r = -\frac{(r_0v_0)^2}{p}\cdot\frac{m}{r^2}\mathbf{e}_r =\mathbf{f}(r) \end{align} Thus $$ f(r) = -\frac{\alpha m}{r^2} $$ is the only possible functional form of $f$. The same force acts on the Sun, so by symmetry if it is proportional to the mass of the planet, it must also be proportional to the mass of the Sun, that is $\alpha = G M$ for some constant $G$: $$ \mathbf{f} = -\frac{GMm}{r^2}\mathbf{e}_r $$ Kepler's second and third laws follow from here! I don't know if this is how Newton actually derived it - I seem to remember that he just wrote down the law in Principia without any derivation - but it is certainly plausible that he used a method similar to this one.
 
    
    He looked at how Earth’s gravity affected a near object (anything at the surface) and a far object (the Moon) and saw an inverse-square-of-distance-from-center-of-Earth relation.
Newton knew that the Moon was about 60 Earth radii away from the center of the Earth. He also knew that it took about a month to orbit the Earth. From this he could compute its centripetal acceleration. It turned about to be about 1/3600 of $g$, the acceleration of gravity at the surface of the Earth, such as when an apple falls from a tree.
Since 3600 is the square of 60, he could see that gravitational acceleration dropped off as the square of the distance from the center of the Earth, and he generalized this to any massive object.
 
    
    It can't be derived it is a law.It can be experimentally verified.Newton got the sense of $r^2$ by Kepler's law of planetary motion.
