Why is the work done in reversible process greater than work done in irreversible process? I have read in my textbook that maximum work is done by gas in a reversible expansion, but I do not know the reason behind it.
Also is work done by gas maximum in reversible compression also?
 A: Its almost true.  Of course, Jamie would beg to differ.
However, the general logic is simple.  If you have something that's irreversible, energy is lost.  That energy was work that could have been used to produce valuable work.
If you consider this gas expansion as part of a cycle, then it is more clear that that irreversability calls for more work to be done to reset the system, and that is where the saying comes from.
What makes it difficult to understand is that many of the more expressive uses of expanding gas, such as Jamie's example above, are one-shots which waste a considerable portion of their energy.  In exchange for wasting that energy, they can be constructed to hold onto a much larger total energy and emit that energy rapidly.
Hence, "don't try this at home."
A: The reason why more work is done in a reversible process than an irreversible process is in an irreversible process entropy is generated within the gas whereas in a reversible process entropy is not generated. That additional entropy has to be transferred to the surroundings in the form of heat, leaving less heat available to be converted to work.
To elaborate, since entropy is a property of the system, the difference in entropy between two equilibrium states is the same, regardless of the process (reversible or irreversible) that connects the two states. Consequently, in an irreversible process the additional entropy generated in the system must be transferred to the surroundings in order for the change in entropy of the system to be the same. The only way to transfer entropy to the surroundings is to transfer heat to the surroundings. This means more heat has to be transferred to the surroundings in an irreversible process than a reversible process. That leave less heat to be converted to work for the irreversible process than the reversible process.
Hope this helps
A: Thermodynamically the reversible heat is defined as TdS and dS>Q/dT according to the second law of thermodynamics. According to Transport phenomenon the heat of compression/expansion is given by
$$ \rho c_p \frac{\partial T}{\partial t} = - (\nabla  \cdot q) -(\frac{\partial ln( \rho)}{\partial T})_p \frac{DP}{Dt}- \tau:\nabla v $$
so energy is lost as heat as a function of DP/Dt how fast we compress the gas or a non reversible process. also the last term is the viscous dissipation
A: 
I have read in my textbook that maximum work is done by gas in a
reversible expansion, but I do not know the reason behind it.

The reason why more work is done by the system in a reversible process than an irreversible process is entropy is generated within the gas in an irreversible process.  Whenever entropy is generated within the system there is a lost opportunity for the system to perform useful work.
FIG 1 is an example of a reversible and irreversible isothermal ideal gas expansion process connecting the initial and final equilibrium states 1 and 2.
For the reversible expansion the external pressure is slowly reduced so that all the while the gas is in thermal and mechanical equilibrium with the surroundings between the initial and final equilibrium states (1 and 2).  The reversible heat transfer to the gas equals the reversible work done by the gas. The reversible work done by the gas is the area under the PV=constant curve and is
(1) $W_{Rev}=nRTln(V_{2}/V_{1})$
For the irreversible process the system is initially in equilibrium with the surroundings at state 1 just like the reversible process. The external pressure is then abruptly reduced to  $P_2$ such that there is no time for the gas to initially expand or transfer heat with its surroundings. The gas then expands irreversibly against a constant external pressure $P_2$ absorbing heat and doing irreversible work $W_{Irr}$, until it reaches the final equilibrium pressure and volume at state 2. The irreversible work is
$W_{Irr}=P_{2}(V_{2}-V_{1})=P_{2}V_{2}-P_{2}V_{1}$
From the ideal gas law:
$P_{2}V_{2}=nRT$ and $P_{2}=nRT/V_{2}$. Substituting in the equation for $W_{Irr}$ gives us
(2) $W_{Irr}=nRT(1-V_{1}/V_{2})$
Comparing equations (1) and (2) we have, for all $V_{2}>V_{1}$,
$W_{Rev}>W_{Irr}$
Which is also evident from the fact that the area under the reversible path is greater than that under the irreversible path.
The rapid irreversible expansion generates entropy due to viscous friction losses. The irreversible work $W_{Irr}$ is therefore equal to the sum of the reversible work $W_{Rev}$ and the viscous friction work, $W_{Vf}$, or
$W_{Irr}=W_{Rev}+W_{Vf}$
Since $W_{Rev}>W_{Irr}$, the viscous friction work $W_{Vf}$ is negative, meaning it dissipates energy that would otherwise be available for doing useful work. The irreversible work done by the gas is somewhat analogous to the work done on or by a parallel spring damper system, where the viscous friction work is the heat dissipated in the damper, and the reversible work is that done on or by the spring.

Also is work done by gas maximum in reversible compression also?

Yes, meaning the work done by the gas is less negative for a reversible compression than an irreversible compression. For example, during a reversible isothermal compression less heat is transferred to the surroundings than during an irreversible isothermal compression.
Fig 2 below shows a reversible and irreversible isothermal compression.  For the irreversible compression, at state 1 the gas is in thermal and mechanical equilibrium with the surroundings.  The external pressure is then abruptly increased from $P_1$ to $P_2$, allowing no time for the gas to initially compress or transfer heat. The gas then undergoes a rapid (irreversible) compression process during which negative work is done and heat is irreversibly transferred from the gas to the surroundings.
The heat out is greater than that of the reversible compression. The result is the work done by the gas is more negative during the irreversible process than the reversible process. The viscous friction work is once again negative and adds to the negative reversible work.
Hope this helps.

A: 1st part-Since from the carnot cycle and 2nd law of thermodynamics, we know that efficiency for any cyclic process is maximum when it is a reversible carnot cycle .Since efficiency is maximum ,the work done is also maximum for reversible process
2nd part-
No the magnitude of work done  by gas in reversible compression is less than work done in irreversible compression.
A: Since work done is integral of $P_{\rm external} \times ΔV$ , work will be maximum $P_{\rm internal}$ is almost equal to external pressure (using ideal gas rule) . And as the condition completely exists in reversible case, Reversible process has greater work done than irreversible process.
