Avoiding 404 errors in your Joomla site is very important, especially if they occur due to incorrect site setup. It is a sign of bad website design and could scare off both users and Google. So always create your internal links carefully. And if you have dead links, make sure you detect them. Especially after a site redesign, it could be that the URL structure of the site changes, and also the URLs that the internal links point to. Then you simply have to look them up and fix them.
Fixing or redirecting?
A way of detecting dead links is to use the Redirect manager in the Joomla core. You will be able to find any 404 error, whether it is generated by an external link or an internal link. If you use the tool to redirect the link, then the user will not encounter any issues. However, from a pure SEO perspective, this is not a perfect solution, as the site may become filled with redirected links. These redirections may affect the flow of "SEO juice" and Google may have issues understanding the setup of your site. For this reason, it is better to go to the source link and make sure it points to the correct target URL. This may force you to check every link, which may be a lot of work though.
Detecting dead links
Make sure you audit your site every now and then, especially after major changes. For individual pages, I often use the Chrome extension SEO Minion. It has a nice tool to detect dead links:
However, for larger projects, you need to look at the whole site. This can be done with the Joomla Redirect manager, but this also has its limitations. Better is to use audit tools such as Screaming Frog SEO Spider or SEO Powersuite. They usually have excellent broken links checkers:
Also, Google Search Console will warn you about broken links and 404 errors if your site is registered, which you should always do.
Correct 404 page
Always make sure to show your users a valid error page. First of all, you should show them a friendly message about the page that cannot be found. Secondly, direct them to an alternative target. If this is not possible, at least show them a search box or a link to the home page or suggest they simply use the site navigation. Some SEO extensions like 4SEO are capable of suggesting an alternative target based on the keywords in the URL:
And make sure you stick to the design of the site. Style it similarly, and make sure the header and footer are the same as on the rest of the site. Nowadays, most template providers have a decent 404 page shipped with the template, so it is not required to make template overrides to fix the error page, as was the case in earlier days.
By the way, be aware that not all 404 errors are bad. If you have an article or a webshop product on your website that is no longer relevant, removing it will indeed lead to a page-not-found error, but in this case, it is a valid use, and after some time Google and Bing will simply remove the page from the index. Google actually stated that this situation won't hurt your SEO.
404 response header
Something you should check is whether your error page creates the correct HTTP response header. A normal page usually generates a 200 response code, but a Page Not Found page should create a 404 response. This tells the browser (and search engines) that there is no valid page here. And this is what they should be told. Otherwise, you run the risk of having the page indexed, or other unwanted situations. In your Google Search Console account, you may sometimes spot soft-404's. In cases like this, the page does not generate the correct 404 headers, but Google is still smart enough to spot the Page Not Found issue.
To check whether the page generates the correct HTTP response, open up the Chrome developer tools (using F12) and browse to the Network tab. You then need to refresh the page and then you can see the response header at the top of the list:
Once you have this in place, you should be fine.