It was realized long ago, that the food packed and heated inside containers remained fresh for a long time. But no one was able to explain the reason. When in 1860, French scientist Louis Pasteur made a discovery and said that due to the bacteria present in the food and also in the atmosphere spoil the food and make it useless and harmful to man, the working of canning was understood.
The heating kills the bacteria in the food, and the sealing of the can prevents more bacteria from getting into the food and if well-sealed, the food inside a can should stay fresh for as long as there is no opening in the can. All cans today are vacuum-packed, which means that the air is sucked out of the can before it is sealed. This way even the bacteria in the air cannot spoil the food.