For instance, in species with sexual differentiation, two males or two females cannot mate, but are considered the same species.
For a more precise definition, you would have to, say, look at the probability that a pair of organisms of the appropriate sex from two different populations would be able to mate, and produce viable offspring (that is, offspring that could themselves mate and produce more offspring).
Asking about a single organism that happens to be infertile, or a single pair that happens not to be able to mate or produce viable offspring, is not particularly interesting, but at a population level you could use a statistical test to get a probability distribution, rather than a yes or no answer.
See https://en.wikipedia.org/wiki/Species#Difficulty_defining_or... for more information.
Note also that it can be the case that two different species can mate, and produce offspring, but the offspring itself is not viable (cannot mate and produce offspring). This happens in the case of mating two closely related species, such as when mating a horse and donkey to get a mule (https://en.wikipedia.org/wiki/Mule), or a lion and a tiger to get a liger (https://en.wikipedia.org/wiki/Liger).
Plants can clone itselves so to be infertile is not the same as to be extinct for them. Infertile also means normally something like "99,9999% unable to produce seeds" but with enough time and a high number of tries, planets will align in the polinisation of two "unfertile" stems of the same plant. At the end seeds will be produced and the new species will exit the 'trap' perfectly (or all DNA of the father will be discarded reverting to the original mother species). Is just a question of time.