As per UEFA co-efficients, the top three ranked countries – Spain, Germany and England - are given four Champions League places, while the three countries below - currently Italy, Portugal and France - are given three.
So maximum of 4 teams are allowed from Spain, Germany, England - the top 3 teams in the league will directly qualify to the Group stages and the team finished 4th will play the CL qualifiers.
If the team finished outside the Top-4 in the league, but if it won the Champions League, they'll qualify directly to CL and the team finished 4th will lose their CL spot.
Eg: In 12/13 season, Spurs finished 4th in EPL but Chelsea who finished 6th in the league, went on to win UCL and qualified directly to CL, as a result Spurs pushed to Europa league.