The official documentation of how specificity works is here. In a high number base specificity is simply (100 * ID rules) + (10 * class rules) + (1 * tag rules).
If you are running into a very obnoxious website or wish to use a very broad rule you can use :not(#some_id_which_you_will_never_find) to artificially increase specificity. ID rules have the highest value so you should use them.
For example I wanted to ensure that every div in a website was not marked as visibility: hidden and used this:
div:not(#oStHDi_0):not(#oStHDi_1):not(#oStHDi_2):not(#oStHDi_3):not(#oStHDi_4):not(#oStHDi_5) {
    visibility: inherit !important;
}
This has a specificity of 601.
In your case body has specificity 001, html > body is 002 and body:not(#foobar) is 101.