Spain will progress as one of the top two sides if they avoid defeat against Uruguay on Saturday (01:00 BST).
Even if they lose, they will still finish inside the top two unless Cape Verde beat Uruguay. If that happens, Spain will finish third on four points, which is likely to be good enough.
Spain will top the group with a draw, unless Cape Verde win and overturn a goal difference deficit of four.
The group winners go on to play the runners-up of Group J.
Uruguay will be through if they beat Spain. If they draw, then a top-two finish is only possible if Cape Verde also draw.
Cape Verde will make the top two if they beat Saudi Arabia. They can also definitely go through with a draw if Spain beat Uruguay.
If Uruguay and Cape Verde both win they will be tied for top spot, or if they draw for second spot. As they drew with each other, placings would be determined on goal difference - which is level at zero.
If goal difference is identical, positions will be decided first by the better disciplinary record (Cape Verde -3, Uruguay -2) and then by Fifa world ranking, which Uruguay hold.
The second-placed team will face Argentina.
Neither team will qualify if they lose.
Saudi Arabia must beat Cape Verde, and will also need Spain to avoid defeat against Uruguay, to finish second. Four points would likely be enough in third anyway.