Last I heard, the matchmaking allows a difference in member count of up to 3. Hence, if you bring 6 members to war, your opponent will bring from 3 to 9.
The other condition I know of, is that you can’t match with someone you’ve recently been matched with.
(And there’s an implicit condition in that everyone gets matched with a single opponent … or the next step might wind up with double bookings …)
With those conditions, you’ll get matched with some alliance with the “closest” war score remaining. You can see the war score in the popup from alliance score; it is determined by the “power” score of the best 30 heroes, with extra weight to the best 5, plus a “power” score of the best troop of each element, all calculated for each member going to war, summed, and finally modified by the alliance’s recent war history: The more wins, the higher the score.