Redirects are used to redirect pages automatically to another page or domain. It’s important to know which one to use, since you want to let search engines know without being penalized.
For example if you have a website that you need to maintain you want to let the search engines know that this is only temporary so they know. Why? Because you don’t want to lose your rankings due to website maintenance. The 302 redirect is exactly for these scenarios. This way people will still use the original URL but end up on a different one and you won’t lose your precious rankings because your website is currently unavailable.
The 301 redirect is permanent. You let the search engines know that your website was permanently moved to the new address. Any inbound links to the old URL will have their search engine ranking values attributed to the new page. This way when you permanently move your website to a new domain your inbound links will still count.