Leveling as a solution to uneven density with coffee grounds in portafilter

Any uneven density in the grounds causes the hot water being forced through the coffee while brewing, to take the path of least resistance through the looser section of the coffee. This less dense coffee will be over-extracted and the surrounding denser grounds will not receive enough water flow and will be under-extracted.

To prevent these problems and achieve an even distribution, level the coffee grounds in the portafilter before tamping them, helping to crush out any air pockets. Leveling is also a great way to measure a dose of coffee by eye without the need for scales.

Leveling Methods:

Source: silviaschool.com