Attacking is by far the most common standard action taken during combat. With most combat, the steps are the same. You first select a target that you can attack. Then you roll d20 and add your Attack Bonus. If your attack roll is equal to or greater than your opponent's AC, then you hit and deal damage. How you calculate your Attack Bonus and damage depend on whether the attack is melee or ranged.
Automatic Misses and Hits: A natural 1 (the d20 comes up 1) on an attack roll is always a miss. A natural 20 (the d20 comes up 20) is always a hit.
With a normal melee weapon, you can strike any opponent within 5 feet. As such, all creatures within five feet of you when you are wielding a melee weapon are considered threatened. Some weapons have reach and can threaten 10 or more feet away.
With a ranged weapon, you can shoot or throw at any target that is within the weapon's maximum range and in line of sight. All Ranged weapons have three ranges: near, medium, and far. Near range attacks are made normally; medium range attacks are made at -4; far range attacks are made at -8. When making a ranged attack against someone within 5', you also do so at disadvantage. When using a ranged weapon, be aware of any cover that might be making the target harder to hit (see below).
Note that with thrown weapons you may use your strength modifier instead of your dexterity modifier when calculating damage.
Your defense is represented by your Armor Class (AC). This number is an abstraction that includes all factors that contribute to your ability to avoid getting hit, including armor, your size, and your ability to dodge. All attackers are making attack rolls trying to get a number equal to or greater than your AC to hit you.
When a situation arises that prevents you from adequately moving well enough to defend yourself (unable to move, surprised, unaware of an attack, etc.), you are considered flat footed and your opponent rolls against your Flat Footed AC.
Note that Flat Footed AC only removes dodge bonuses. If you have penalties due to low Dex, these still apply to flat-footed AC. So, if you have a Dexterity of 8 (inflicting a -1 penalty to AC), the -1 penalties still applies to your flat-footed AC.
Sometimes, you don't need to hurt an opponent, just touch them. To do so, you make an attack against Touch AC.
As a general rule, multiple bonuses of the same type do NOT stack (i.e. wearing 3 suits of armor doesn't help). Dodge bonuses are the exception to this rule.
Note: that some items come in higher qualities or are enhanced by magic. These items have an enhancement bonus. Enhancement bonuses to AC stack with the base stat, but not with each other (i.e. you can only have one enhancement bonus per item). So, if your armor bonus is a +4, a spell that adds a +2 enhancement bonus to that would naturally bring your armor bonus to +6. If you had two spells active, one with a +1 enhancement bonus and one with a +2 enhancement bonus, your total armor bonus would still be +6. Only the highest of the two enhancement bonuses would have an effect.