Can I offset a loss against a gain?

Yes—losses can reduce your CGT bill and be carried forward.