Dogs learn just like humans, by trial and error. Their learning goes on whether we are actively teaching them or not. Dogs learn in 2 main ways - through classical conditioning, or operant conditioning.
When we are training our dogs to perform certain behaviours or tricks, we are using operant conditioning. This is where we pair the appropriate behaviour with a reward, which makes the behaviour more likely to happen the next time. If used correctly through positive reinforcement, operant conditioning can create a wonderful bond between you and your dog, and is so beneficial for their mental health and enrichment. Dogs will naturally seek to perform behaviours that have brought positive consequences, and will try to avoid behaviours that have brought negative consequences in the past.