301 and 302 both are HTTP codes which have a single line minor difference as both are use to redirect URL. 301 is used when URL is redirected permanently while 302 is used when URL is redirected on temporary basis.
301 Moved Permanently. A 301 redirect is a permanent redirect which passes between 90-99% of link equity (ranking power) to the redirected page. 301 refers to the HTTP status code for this type of redirect. In most instances, the 301 redirect is the best method for implementing redirects on a website.
A 302 redirect means that the move is only temporary. Search engines need to figure out whether to keep the old page or replace it with the one found at the new location.