The compatibility of the battery depends on the voltage. Both the battery and tool must operate on the same voltage.
Flexvolt batteries are an exception. Flexvolt batteries are compatible with Dewalt 60v and 20v tools, and can be charged by 60v or 20v Dewalt chargers. Flexvolt tools require Flexvolt batteries to operate and are not compatible with Dewalt 20v batteries.