When can I cast spells?
Artifacts, creatures, enchantments, lands, planeswalkers, and sorceries can be cast during your first or second main phase.

Instants, such as Lightning Bolt, can be cast during any step except for the untap step and most cleanup steps. You can cast instants after attacking but before your opponent has a chance to block. You cannot cast instants in the middle of another spell or ability resolving.

After any spell or ability resolves, the player who is currently taking a turn gets the opportunity to cast things first.

Some spells or abilities, such as Quicken, modify when you can cast things.

If you are interested in the nitty gritty details, Section 5 of the comprehensive rules, which covers "Turn Structure", has nearly 150 rules that you can read. Much of it has been condensed into this neat chart, but a lot of (situationally relevant) information has been left out.