Start here. This is the direct spoken answer to practice first.
Overview
401 means acceptable authentication is missing or failed; 403 means the caller is known but not allowed.
Spring Security uses an AuthenticationEntryPoint when a request needs authentication, which normally produces 401 for an API and may include a WWW-Authenticate challenge. It uses an AccessDeniedHandler when an authenticated caller lacks authority, which normally produces 403. An anonymous caller denied by an authorization rule may be sent to the entry point because authenticating could change the outcome.