If you just add the two areas, you count the overlap twice. The correct formula is: total = area1 + area2 - overlap.
To find the overlap, compute the intersection rectangle. The intersection has left edge max(x1a, x1b), right edge min(x2a, x2b), bottom edge max(y1a, y1b), and top edge min(y2a, y2b).
If the intersection has positive width and height, compute its area. Otherwise, overlap is zero.