Help dimensioning mosfet as switch with high current
Select a MOSFET that can block the maximum voltage

In the transistor's datasheet, usually under the section absolute maximum ratings, will be \$V_{DSS}\$ (drain-source voltage). If the voltage from the drain to the source exceeds this, the MOSFET will probably be damaged. So, calculate the maximum voltage that could be experienced in your circuit, considering also the possibility of switching transients, then add a margin of at least 20% for robustness.

Look for a MOSFET (using the parametric search tool of your vendor or manufacturer) with \$V_{DSS}\$ around this value. A device with \$V_{DSS}\$ higher than you need will work fine, but will probably be more expensive, slower to switch, or less efficient than one with a lower (but not too low!) \$V_{DSS}\$.

Calculate resistive losses

The MOSFET, when on, looks much like a resistor. The datasheet will specify \$R_{DS(on)}\$, the resistance between drain and source when the MOSFET is all the way on. Determine the maximum current your MOSFET will have to pass, and you can calculate the resistive losses in the MOSFET just as you would for a resistor:

$$ P = I^2 R_{DS(on)} $$

Calculate switching losses

MOSFETs (all transistors, really) take time to switch. During this time, there will be high current and high voltage in the MOSFET simultaneously, which means high losses in the MOSFET (\$P=IE\$) for that brief period. If you are not doing PWM or similar, than the time you spent switching relative to the time you spend on or off will be very small, and switching losses will be negligible. If this is not the case, then you must consider switching losses in your calculations. That's enough for another question, so either don't do PWM, or add a healthy margin to your power calculations (say, 50%) to be safe.

Calculate junction temperature

You now have a number that represents the power dissipation in the transistor, in watts. Compare this against the maximum power dissipation in the absolute maximum ratings. If you have exceeded this, you can't use this MOSFET no matter how big your heatsink is. Otherwise, you can use this MOSFET, but you may need a heatsink.

Rule of thumb: If it's less than \$1W\$, and your device is in a TO-220 package, you are probably good. If you want to be robust and you want to be able to touch the thing without getting a burn, you will want less than \$0.5W\$, or add a small heatsink.

You must absolutely not exceed the maximum junction temperature listed in absolute maximum ratings. It's probably in the neighborhood of \$175^\circ C\$. The junction temperature is a function of the ambient temperature, the power dissipation, and the thermal resistance from the junction to ambient.

You know the ambient temperature (look at a thermometer) and the power dissipation (you already calculated). To calculate the total thermal resistance, add the thermal resistance of all the things between the junction and ambient. If you plan to operate with no heatsink at all, the datasheet probably lists \$R_{\theta JA}\$ or junction-to-ambient thermal resistance. If you do use a heatsink, that heatsink's datasheet will specify its thermal resistance. Add to this the junction-to-case thermal resistance from the transistor datasheet, and also the thermal resistance for the interface between the heatsink and the transistor case (typical values usually in the transistor datasheet; for a TO-220 with thermal grease, \$0.5^\circ C/W\$ is typical).

So now you have your total thermal resistance \$R_\theta\$ in \$^\circ C/W\$, your total power dissipation in watts, and your maximum junction temperature \$T_{J(max)}\$ and ambient temperature \$T_A\$ in \$^\circ C\$. Your transistor will not be destroyed if:

$$ T_{J(max)} &gt; T_A + P \cdot R_\theta $$

If that's true, you are good. Otherwise, get a bigger heatsink, a transistor with a lower \$R_{DS(on)}\$, reduce the ambient temperature, or reduce the current in the transistor.

Example

Let's do these calculations with FQP50N06. No particular reason other than I had the datasheet on my desktop.

Maximum \$V_{DSS}\$ is 60V. This is safely above the 28V in your circuit.

Maximum \$I_D\$ is 35.4A. This is safely above the 20A in your circuit.

The current will be 20A and the datasheet says \$R_{DS(on)}\$ could be as high as \$0.022\Omega\$. That means my power dissipation will be

$$(20\:\mathrm A)^2 \cdot 0.022\:\Omega = 8.88\:\mathrm W $$

I'm going to assume you are not doing PWM, so switching losses are negligible.

Can I run this without a heatsink? Let's say I want it to work with ambient temperatures as high as \$40^\circ C\$. The datasheet says the junction-to-ambient thermal resistance is \$62.5^\circ C\$. So, the junction temperature will be:

$$ 40^\circ \mathrm C + 8.88\:\mathrm W \cdot 62.5^\circ \mathrm C = 595^\circ \mathrm C $$

This is well above the maximum junction temperature specified in the datasheet, \$175^\circ \mathrm C\$, so you have a problem. You could solve that by using a larger heatsink, which reduces the thermal resistance. Or you could find a transistor with a lower \$R_{DS(on)}\$ which will reduce the power the heatsink must dissipate.