Now all of this is regards to the atonement and the forgiveness of the sin.
In other words, when a person does a Teshuva, then this sin is not mentioned to them on their judgment day and they will receive no punishment for it God-forbid in the world to come.
However in order that they should be friendly once again before God – they should be dear and precious to Him as they were prior to the sin, that God should take pleasure from their service to Him, this required in the days of the Beis Hamikdosh to bring a Karbon/sacrifice.
This is like an example of a person who angered a king and yet the king forgave him nevertheless in order to reestablish the bond to the levels that it was prior to the rip in the relationship, a present is given.
However now that we cannot offer a sacrifice, therefore the fast replaces the sacrifices as it states in the Gemarah “that the minimization of my own fat and blood through the fast, should be as if I gave you a sacrifice.”
Hence we find that many of the Taanayim and Amoraim (great Rabbis of the past) would fast even for a very small sin – for example Rabbi Eleazar Ben Azaryah used to permit that a cow would be allowed to go out with the rope between her horns on Shabbos and the Sages forbade it – one time the cow of his neighbor went out in this way, and he did not protest, and his teeth became black from the many fasts that he self-inflicted for not following the words of his fellow Sages.
Similarly we find with Rabbi Yehoishua that he once retorted, “I am embarrassed from your words, House of Shama” and his teeth became black from his many self-inflicted fasts.
And Rav Huna, once the strap of his Teffilin turned upside down and he fasted 40 fasts.
And there are many similar examples.
Based on this our sages have taught based on the Kabbalistic truths, the amount of fasts for various sins, even that are not sins Of Kares or Death From Heaven, for example for anger 151 fasts etc.
And even a transgression of the Rabbis, for example not drinking wine of a gentile, should be 73 fasts.
Similarly if one transgresses a positive Mitzvah of the Rabbis, such as prayer, he should fast, 61 fasts etc.
Generally speaking The secret of fast is a tremendous opportunity to draw down the love of God, just like a sacrifice, which it said “A pleasant pleasing aroma to God.”
As it states in Yeshayahu, “Do you call this a fast and a pleasing day to God?” which shows us, that a proper fast is a pleasing aroma to God.