What a 301 redirect means
HTTP status 301 "Moved Permanently" tells browsers and crawlers that a resource has a new permanent address, given in the Location header. Browsers cache it, and search engines replace the old URL with the new one in their index over time.
Google has confirmed that 301 redirects pass ranking signals such as links to the target URL, so a correctly redirected page keeps its rankings after a move.
When to use a 301
Use a 301 whenever the change is permanent: moving to a new domain, switching from http to https, choosing between www and non-www, changing URL structure, merging two articles into one or retiring a product page in favour of a close replacement.
For temporary moves, such as a maintenance page or a short promotion, use a 302 redirect or 307 redirect so the original URL stays indexed. A 308 is the permanent equivalent of a 307 and is treated like a 301 by Google.
Best practices
Redirect each old URL to the most relevant new page, not everything to the homepage, which Google may treat as a soft 404. Point redirects straight at the final URL to avoid a redirect chain, and update internal links and your XML sitemap so they use the new URLs directly.
Keep redirects in place for at least a year after a migration, and longer if old URLs still have backlinks.
Example
A 301 in nginx and Apache:
# nginx
location = /old-page { return 301 https://example.com/new-page; }
# Apache (.htaccess)
Redirect 301 /old-page https://example.com/new-page