What exactly is a gauge anomaly? In lots of papers I read about gauge anomalies. For example, avoiding gauge anomalies in the MSSM is the reason for introducing an extra Higgs doublet. Gauge anomalies in the Standard Model are cancelled due to accidental symmetries etc. Can someone please explain what a gauge anomaly exactly is and also how introducing an extra Higgs doublet helps avoid it in MSSM?
 A: Anomalies (not anamolies) are a whole subject whose basics are covered by one or several chapters of almost any good enough quantum field theory textbook so it's counterproductive to retype this whole chapter here.
But generally, in quantum field theory, anomalies are quantum mechanical effects breaking symmetries that exist in the classical theory – quantum mechanical contributions that are zero in the classical theory because of the symmetry but that are inevitably nonzero in the quantum theory because the quantum completion doesn't allow all the symmetries to be preserved.
An anomaly in a global symmetry is a physical effect that changes the dynamics but keeps it logically consistent; a gauge anomaly – the quantum mechanical breakdown of a gauge symmetry – renders the theory inconsistent because the gauge symmetry is needed to decoupled the unphysical (negative-norm) polarizations of the gauge boson so it should never be broken.
Anomalies appear because certain divergent integrals cannot be simultaneously set to zero. They appear in theories that admit left-right asymmetry, especially in even spacetime dimensions. 
The simplest Feynman diagrams that quantify the anomaly are $n$-gons, polygons, where $n=d/2+1$ where $d$ is the spacetime dimensions. So importantly enough, anomalies in the $d=10$ dimensional effective theories resulting from superstring theory are calculated using hexagon Feynman diagrams.
In the undergraduate example of $d=4$, anomalies are given by $n=3$ i.e. triangle Feynman diagrams. A fermion – left-right-asymmetric particle – is running in the loop of the Feynman diagram. Three gauge bosons are attached. The diagram is proportional to something like 
$${\rm Tr}(Q^3)$$
where $Q$ is a generator of a $U(1)$ subgroup of the gauge symmetry, a charge. All such traces of cubic expressions have to vanish for consistency, and they indeed vanish in the Standard Model – but a cancellation between quarks and leptons is necessary for that. The Standard Model with leptons only or quarks only would be inconsistent.
The MSSM has the same chiral spectrum as the Standard Model with one exception: there are extra higgsinos. They contribute some extra term to the anomalies that aren't cancelled by anything. The arguably simplest way to cancel the anomaly is to add not one Higgs doublet (one doublet of superfields) but two doublets, with mutually opposite values of the charges (assuming the same chirality). So these two MSSM higgsinos cancel the anomalies against one another.
The two Higgs doublets in the MSSM are important for another reason: one Higgs doublet is only able to give masses to the upper quarks only; or the lower quarks only. One actually needs both Higgs doublets, the up-type and the down-type, to allow all quarks to become massive.
