When a microcontroller pin is configured as an output, it fairly obviously provides current when set HIGH. How much depends on the chip, up to 40mA on an Arduino Nano, but not all pins at the same time!
Less obviously, when an output pin is set LOW, the pin sinks current, also up to 40mA on a Nano.
In this example circuit, the output pin is held HIGH by a 1k resistor connected to the 5V rail. The voltmeter reads 5V when the pin is set HIGH. When the output pin is set LOW, it pulls the resistor down to ground, and the voltmeter reads zero volts.

Useful because binary logic can meet switching requirements either way round by inverting the meaning of HIGH and LOW. Both handy and complicated! But as an example, James is using an NPN transistor, which works with the logic in my circuit. If his junk box was full of PNP transistors, which are upside-down compared with NPN, he could invert the logic in the Arduino to match PNP electronics.
Why did I specify a 1k resistor in the example? At 5V 1000 ohms limits the current sunk by the output pin to 5mA, well within the 40mA maximum, and enough to drive an NPN/PNP transistor fully ON. It’s “about right”, not carefully calculated. As FETs are switched by volts, not amps, the resistor could have a much higher value.
A good reason for experimenting with basic Arduinos is they use a slow but robust chip that’s more resilient to mistakes. Faster microcontrollers with more memory and features tend to be delicate. Get the electronics wrong, and pop! Many other microcontrollers can’t source or sink much current. For them, as Bazyle recommends, check the data-sheet and read the small print.
Dave