Transformerless power supply
If you're here asking about the basics of a line-connected power supply for running some hobby project, then you shouldn't be trying to do this at all.  This is NOT where you want to learn by experimenting.  The cost of mistakes are too high.  The results can burn down your house or electrocute you, or someone else.

If you need a little current at 5 V to run a microcontroller from, just buy the power supply, or use a USB power adapter. These things are cheap, small, and easily available.  Someone else who actually knows what they are doing has done the engineering to provide the 5 V safely.

The Meanwell IRM-01-5 is just one of many examples.  This one mounts on your PCB like any other part, only has a footprint of 1.3 x .9 inches (34 x 22 mm), puts out 200 mA at 5 V, works with line power anywhere in the world, and costs under $5 in singles.  Doing this yourself just doesn't make sense.