Do I need a resistor when connecting LED to digital output pin?

If i'm understanding correctly, the digital output pins provide 5volts, but only supply 20mA of current. When they say 20mA, does that mean that is their safe limit, as in, I could draw more, but that would be not be recommended? or the absolute max and impossible for them to supply more? If it is the latter scenario, is it because of internal resistance?

Thank you

If i'm understanding correctly, the digital output pins provide 5volts, but only supply 20mA of current

You do not understand correctly.
A direct short to ground could cause an output pin to source much more than the absolute maximum pin limit of 40mA.

… so use a resistor to limit the current to under 40 ma or you are likely to let the magic smoke out.

-br

Yes, you always need a resistor in series with an LED. An LED is a diode, and diodes are current driven devices, so you always must limit the current through the diode.
An 1kiloohm resistor is a good choice today, for example.. :slight_smile:

Ah, okay. I was under the impression that when they said 20mA limit, that they would automatically output 20mA through some internal resistance of some sort.

Thank you all for the answers

remedemic:
Ah, okay. I was under the impression that when they said 20mA limit, that they would automatically output 20mA through some internal resistance of some sort.

You are not the only one to make that error, it is quite a common misconception. Just for the record a circuit that does limit current to a fixed value regardless of load is called a constant current driver. You use them for driving high current LEDs rather than a resistor.