According to wikipedia:

"Discipline:

Discipline in BDSM is the practice in which the dominant sets rules which the submissive is expected to obey. When rules of expected behavior are broken, punishment is often used as a means of disciplining.

Punishment:

In BDSM, rules can be made so that a submissive ("sub") knows how they should behave (so that the dominant is not displeased). Rules can also be for reminding subs of their inferior status, or for training a novice sub. When such rules are broken, punishment is often used as a means of discipline. Punishment itself can be physical (such as caning) or psychological (such as public humiliation) or a combination of both (i.e., through bondage)."

The goal of discipline is to teach the sub that they have made a mistake, so that they learn self-restraint and become a better sub in the future. The punishment is generally related to the mistake, and is generally proportionate to the severity and frequency of the mistake. For example, a punishment for speaking out of turn for the first time may be a simple restraint (such as being silenced using a gag). The sub may also be given the option of choosing a punishment (i.e., to be either caned on the buttocks or slapped on the face).

Purpose of discipline and punishment:

There are lots of reasons why punishment is part of the BDSM lifestyle. More often than not, punishment is used to train the submissive and correct behaviors to help the submissive become the best version of themselves. One of the key components of this lifestyle is the rules. While the rules can be revisited and adjusted as the relationship progresses, there must be consequences when the rules are broken.

There are two different elements at play here. One is discipline and the other is punishment. How are they different, you ask? Don’t they go hand in hand? Yes and no. By definition discipline is to train to act in accordance with a specific set of rules. This is like going to the gym when you are training for a race of some sort. Punishment is a consequence of breaking a set of rules that have been established. Think detention for being late to school. Two sides of the same coin that work together for the best desired outcome.

The desired outcome is to have a healthy relationship where you both feel safe, happy, and cared for. By following rules that are set by the Dom, the submissive can relax and trust that they are taken care of. When the submissive complies with the rules, the Dominant feels proud that he is able to have been given the gift of submission. The Dominant then feels accepted, desired, and confident like the Master they are.