Kinetic Energy of a Rotating Rigid Body and Moment of Inertia
We can obtain a general idea of the rotation of rigid bodies and compare it with real situations or we can consider some real bodies as nearly rigid to obtain our results.The necessity of deriving an expression of kinetic energy of a rotating rigid body before defining moment of inertia lies inside the idea of defining moment of inertia.
It means we first find the kinetic energy of a rotating rigid body and compare it with the kinetic energy of a particle in linear motion - where we can find the measure of mass of a rotating body called moment of inertia.
Kinetic Energy of a Rotating Rigid Body
Consider a rigid body which rotates about y-axis as shown in Figure 1. The body is made up of large number of particles of masses $m_1$, $m_2$, $m_3$ and so on. The mass $m_1$ is at a distance $r_1$ and the mass $m_2$ is at a distance $r_2$ from the axis of rotation and so on. When the body rotates, each particle of the body moves in its own circle of a particular radius centred on the axis.
The angular velocity $\omega$ of all particles is the same but the magnitude of linear velocity (linear speed) is not the same for all particles. That's because a particle at larger distance from the axis of rotation of the body needs to move along a circle of larger radius but the time is the same for all particles to complete one rotation that is, the angular velocity for all particles is constant.

Let the particle of mass $m_1$ rotates with linear speed $v_1$ and the particle of mass $m_2$ rotates with linear speed $v_2$, and so on. Now the kinetic energy of any particle of mass $m_i$ rotating with its linear speed $v_i$ is $\frac{1}{2}{m_i}{v_i}^2$.
So the total kinetic energy of the rotating rigid body is the sum of the kinetic energies of all particles rotating in the body. Suppose there are $n$ particles and $K_i$ is the kinetic energy of any particle where $i$ can vary from 1 to $n$. The total kinetic energy $K$ of the rotating body is
\[K = \sum\limits_{i = 1}^n {{K_i}} = \sum\limits_{i = 1}^n {\frac{1}{2}{m_i}{v_i}^2} \tag{1} \label{1}\]
You know that $v = \omega r$. Since angular velocity is constant, the linear speed $v_i$ is $v_i = \omega r_i$. So the above expression becomes,
\[K = \frac{1}{2}\left( {\sum\limits_{i = 1}^n {{m_i}{r_i}^2} } \right){\omega ^2} \tag{2} \label{2}\]
You know the kinetic energy of a particle of mass $m$ moving with linear speed $v$ is $\frac{1}{2}m{v^2}$. So by comparison of $\frac{1}{2}m{v^2}$ for linear motion with Eq. \eqref{2} for rotational motion, the quantity ${\sum\limits_{i = 1}^n {{m_i}{r_i}^2} }$ is the measure of mass of the rotating body called moment of inertia. The moment of inertia $I$ of the rotating rigid body is
\[I = \sum\limits_{i = 1}^n {{m_i}{r_i}^2} \]
And we can write Eq. \eqref{2} as,
\[K = I{\omega ^2} \tag{3} \label{3}\]
The kinetic energy of a rotating rigid body about an axis is defined in terms of the moment of inertia and the angular speed. If you think a single particle rotating along a circle of radius $r$ with linear speed $v$, you can easily write the kinetic energy of the particle as $\frac{1}{2}m{v^2}$ but you know $v = \omega r$ and the kinetic energy becomes $\frac{1}{2}m{r^2}{\omega ^2} = \frac{1}{2}I{\omega ^2}$ where $I$ for the single particle is $m{r^2}$.
In words you can define the moment of inertia of a body rotating about an axis as the product of its mass and square of its distance from the axis of rotation.
If a body is not only a point mass but a rigid body of uniform mass distribution, you can not simply take the body as a single point mass but instead you have to define a particular element of the body and use the integration to find the moment of inertia of the whole body.
Moment of Inertia of Uniform Mass Distributions
In fact you can not tell exactly how much moment of inertia a particular body has. It means you can make as many axes as possible about which a rigid body can rotate. So the moment of inertia of the same body is different for different rotation axis. That's the reason why you have to tell about which axis the rigid body rotates.
Here we discuss about the moment of inertia of some uniform mass distributions. Moment of inertia is not constant for non-rigid bodies even if the rotation axis is the same and it is because the distance of particles of non-rigid body from the axis of rotation varies.
Moment of Inertia of a Rod
Consider a rod of length $L$ perpendicular to the axis of rotation through $O$ as shown in Figure 2. Now we consider an infinitesimally small element of the rod of mass $dm$ and thickness $dx$ at a distance $x$ from the axis of rotation.

If the total mass of the rod is $M$, the ratio of $dm$ to the ratio of the total mass $M$ is equal to the ratio of length $dx$ to the total length $L$. So you can write,
\[\begin{align*} \frac{{dm}}{M} &= \frac{{dx}}{L}\\ {\rm{or,}}\quad dm &= \frac{{M}}{L}dx \end{align*}\]
The moment of inertia of the element of the mass $dm$ about the axis is
\[dI = dm{\kern 1pt} {\kern 1pt} {x^2}\]
The total moment of inertia of the whole rod is found by integrating the above expression from $-l$ to $L - l$ (see Figure 2).
\[\begin{align*} I &= \int\limits_{ - l}^{L - l} {dm\,{x^2}} = \frac{M}{L}\int\limits_{ - l}^{L - l} {\,{x^2}} dx\\ {\rm{or,}}\quad I &= \frac{1}{3}M({L^2} - 3Ll + 3{l^2}) \end{align*}\]
Case 1: When the axis of rotation passes through the left or right end that is, when $l = 0$ or $L = l$, the moment of inertia of the rod is $I = \frac{1}{3}M{L^2}$.
Case 2: When the axis of rotation passes through the mid-point of the rod that is, when $l = \frac{L}{2}$, the moment of inertia of the rod is $I = \frac{1}{12}M{L^2}$.
You can also see here that the moment of inertia is different for different axis of rotation.
Moment of Inertia of a Cylinder
Here we find the moment of inertia of a cylinder. You can also find the moment of inertia of a disk (in fact a disk is a cylinder). We'll use the moment of inertia of a disk to find the moment of inertia of a solid sphere later.
First consider a cylinder of height $h$ whose inner radius is $R_1$ and outer radius is $R_2$ as shown in Figure 3. The cylinder rotates about an axis which passes through the centres of the cross sections of the cylinder.

And we consider an infinitesimally small volume element of the cylinder of mass $dm$ and thickness $dr$. The inner radius of the element is $r$ and outer radius is $r + dr$. The volume of the element of the cylinder is $dV = 2\pi r{\kern 1pt} dr{\kern 1pt} h$ and the mass of the element is $dm = \rho dV = 2\rho \pi r{\kern 1pt} dr{\kern 1pt} h$. Here $\rho $ is the density of the cylinder. So the moment of inertia of the element is
\[dI = dm{\kern 1pt} {\kern 1pt} {r^2} = (2\rho \pi r{\kern 1pt} dr{\kern 1pt} h){r^2} = (2\rho \pi h){r^3}dr\]
The total moment of inertia of the whole cylinder is obtained by integrating the moment of inertia $dI$ from $R_1$ to $R_2$:
\[\begin{align*} I &= 2\rho \pi h\int\limits_{{R_1}}^{{R_2}} {{r^3}dr} = 2\rho \pi h\left( {\frac{{R_2^4}}{4} - \frac{{R_1^4}}{4}} \right)\\ {\rm{or,}}\quad I &= \frac{{\rho \pi h}}{2}(R_2^4 - R{}_1^4) \end{align*}\]
The total volume of the cylinder is $V = \pi h(R_2^2 - R_1^2)$. If $M$ is the total mass of the cylinder, the density is $\rho = \frac{M}{V} = \frac{M}{{\pi h(R_2^2 - R_1^2)}}$. Thus, putting the value of $\rho$ in the above expression for the total moment of inertia $I$ we get,
\[I = \frac{{\pi hM(R_2^4 - R{}_1^4)}}{{2\pi h(R_2^2 - R_1^2)}} = \frac{1}{2}M(R_1^2 + R_2^2)\]
Case 1: If the cylinder is solid that is, $R_1 = 0$ the moment of inertia is $I = \frac{1}{2}MR_2^2 = \frac{1}{2}MR_{}^2$. There is only one radius, so $R_2$ is written as $R$. This is also the moment of inertia of a disk.
Case 2: When $R_1 = R_2 = R$ the moment of inertia of the cylinder becomes $I = MR_{}^2$. This is the same as the moment of inertia of a body of mass $M$ about an axis at a distance $R$ from the axis of rotation. This result is the same as the moment of inertia of a thin circular ring about the axis through its centre and perpendicular to its plane.
Moment of Inertia of a Spherical Shell
Consider a spherical shell which rotates about the x-axis with its centre at the origin of our coordinate system as shown in Figure 4. The radius of the spherical shell is $R$. To find the moment of inertia of the spherical shell consider an infinitesimally small area element of the spherical shell of mass $dm$, radius $r$ and thickness $dx$ at a distance $x$ from the centre.

The area of the spherical shell is $4\pi {R^2}$ and the area of the element is its circumference times its thickness which is $2\pi r{\kern 1pt} dx$. Let $M$ denotes the total mass of the spherical shell. The ratio of the mass of the element to the total mass of the spherical shell is equal to the ratio of the area of the element to the total area of the shell that is,
\[\begin{align*} \frac{{dm}}{M} &= \frac{{2\pi r{\kern 1pt} dx}}{{4\pi {R^2}}}\\ {\rm{or,}}\quad dm &= \frac{{rM{\kern 1pt} dx}}{{2{R^2}}} \end{align*}\]
In Figure 4 you can write $x = R\sin \phi $ and if you differentiate $x = R\sin \phi $ in both sides with respect to $\phi$, you'll get $dx/d\phi = R\cos \phi $. And $r = R\cos \phi $, so you can write $dx/d\phi = r$. Also $dx = Rd\phi $ and we can find the mass of the element by using the above expression as
\[dm = \frac{M}{{2{R^2}}}\frac{{dx}}{{d\phi }}Rd\phi = \frac{M}{{2R}}dx\]
The moment of inertia of the element about the axis (in our case x-axis) through its centre perpendicular to its plane is the same as the moment of inertia of a thin ring about the axis through its centre perpendicular to its plane. Check the previous discussion for the moment of inertia of a cylinder. You also know from Figure 4 that $r = \sqrt {{R^2} - {x^2}} $. Therefore, the small moment of inertia of the element is,
\[\begin{align*} dI &= dm{\kern 1pt} {\kern 1pt} {r^2} = \left( {\frac{M}{{2R}}dx{\kern 1pt} } \right){\kern 1pt} {r^2}\\ or, \quad dI &= \left( {\frac{M}{{2R}}dx{\kern 1pt} } \right){\kern 1pt} ({R^2} - {x^2}) = \frac{M}{{2R}}({R^2} - {x^2})dx \end{align*}\]
The moment of inertia of the half of the spherical shell is found by integrating the moment of inertia of the element from $0$ to $R$. The total moment of inertia of the whole spherical shell is two times the moment of inertia of the half of the spherical shell. So the total moment of inertia is,
\[\begin{align*} I &= 2\int\limits_0^R {\frac{M}{{2R}}({R^2} - {x^2})dx = \frac{M}{R}\int\limits_0^R {({R^2} - {x^2})dx} } \\ {\rm{or,}}\quad I&= \frac{2}{3}M{R^2} \end{align*}\]
Moment of Inertia of a Solid Sphere
Now we find the moment of inertia of a solid sphere of radius $R$ about the x-axis along its one diameter as shown in Figure 5. The centre of the sphere is the origin of our coordinate system. Instead of considering a spherical shell as the infinitesimally small element of the sphere we take an infinitesimally small disk of radius $r$ and thickness $dx$ at a distance $x$ from the centre of the sphere. First we find the moment of inertia of the disk element of mass $dm$.

To do this you know $r = \sqrt {{R^2} - {x^2}} $ from Figure 5. And volume of the disk element is $dV = \pi {r^2}dx = \pi ({R^2} - {x^2})dx$. The total volume of the sphere is $\frac{4}{3}\pi {R^3}$. The ratio of the mass of the disk element to the total mass of the sphere is equal to the ratio of the volume of the disk element to the total volume of the sphere. Therefore,
\[\begin{array}{c} \frac{{dm}}{M} = \frac{{\pi ({R^2} - {x^2})dx}}{{\frac{4}{3}\pi {R^3}}}\\ {\rm{or,}}\quad dm = \frac{{3M({R^2} - {x^2})dx}}{{4{R^3}}} \end{array}\]
As already discussed, the moment of inertia of a disk about the axis through its centre perpendicular to its plane is the same as the moment of inertia of a solid cylinder about the corresponding axis. Therefore, the moment of inertia of the disk element is
\[dI = \frac{1}{2}dm{\kern 1pt} {\kern 1pt} {r^2} = \frac{{3M{{({R^2} - {x^2})}^2}dx}}{{8{R^3}}}\]
The moment of inertia of the half of the sphere is determined by integrating the above expression of the moment of inertia of the disk element from $0$ to $R$. So the total moment of inertia of the sphere about the axis along its diameter is twice of this:
\[I = 2\int\limits_0^R {dI} = \frac{{6M}}{{8{R^3}}}\int\limits_0^R {{{({R^2} - {x^2})}^2}dx} = \frac{2}{5}M{R^2}\]
Carry out the integration and the the result will be the same as you see here.