{"slug": "google-sheets-irpf-seguridad-social-spain-formula", "title": "Google Sheets IRPF & Seguridad Social Spain Formula", "summary": "Google Sheets formulas for calculating Spanish social security contributions for self-employed workers (autónomos) and income tax (IRPF) deductions for employees. The code includes specific contribution rates, minimum and maximum bases for 2022, and progressive tax brackets used to compute net income after social security and tax withholdings.", "body_md": "cotizar_seguridad_social_autonomo.gs\n\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      \nLearn more about bidirectional Unicode characters\n\n \n    Show hidden characters\n\n// last changed 01.01.2022\n\n  // Source: http://www.seg-social.es/wps/portal/wss/internet/Trabajadores/CotizacionRecaudacionTrabajadores/10721/10724/1320/1322\n\n // https://www.grupo2000.es/que-seguros-sociales-debo-aplicar-en-2020-bases-y-tipos-de-cotizacion/\n\n  var MINIMO = 960.6;\n\n  var MAXIMO = 4139.4;\n\n  var CONTINGENCIAS_COMUNES = 28.3;\n\n  var CONTINGENCIAS_PROFESIONALES = 1.3;\n\n  var CESE_DE_ACTIVIDAD = 0.9;\n\n  var FORMACION = 0.1;\n\nfunction test() {\n\n  var a = cotizar_autonomo_mensual();\n\n  var b = cotizar_autonomo_mensual(11200);\n\n  return a + ' ' + b;\n\n}\n\nfunction cotizar_autonomo_annual(value_annual) {\n\n  return cotizar_autonomo_mensual(value_annual/12) * 12;\n\n}\n\nfunction cotizar_autonomo_mensual(value_monthly) {\n\n  if (value_monthly == null || value_monthly <= MINIMO) {\n\n    value_monthly = MINIMO;\n\n  }\n\n  if (value_monthly >= MAXIMO) {\n\n    value_monthly = MAXIMO;\n\n  }\n\n \n\n  var cotizacion_total = CONTINGENCIAS_COMUNES + \n\n    CONTINGENCIAS_PROFESIONALES +\n\n    CESE_DE_ACTIVIDAD +\n\n    FORMACION;\n\n \n\n  var result = value_monthly * (cotizacion_total / 100);\n\n  return result;\n\n}\n\nes_income_tax.gs\n\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      \nLearn more about bidirectional Unicode characters\n\n \n    Show hidden characters\n\n// LAST CHANGED: 01.01.2022\n\nvar MAX_SOCIAL_SECURITY_EMPLOYED_MONTHLY = 4139.40; // engineer\n\nvar MIN_SOCIAL_SECURITY_MONTHLY_INGENIERO = 1572.3;\n\nvar COTIZACION_SEGURIDAD_SOCIAL_CUOTA_CONTINGENCIAS = 4.7;\n\nvar COTIZACION_SEGURIDAD_SOCIAL_CUOTA_DESEMPLEO = 1.55;\n\nvar COTIZACION_SEGURIDAD_SOCIAL_CUOTA_FORMACION_PROFESIONAL = 0.1;\n\nvar COTIZACION_SEGURIDAD_SOCIAL_TOTAL = COTIZACION_SEGURIDAD_SOCIAL_CUOTA_CONTINGENCIAS + COTIZACION_SEGURIDAD_SOCIAL_CUOTA_DESEMPLEO + COTIZACION_SEGURIDAD_SOCIAL_CUOTA_FORMACION_PROFESIONAL;\n\nvar OTROS_GASTOS_CUANTÍA_FIJA_CON_CARÁCTER_GENERAL = 2000;\n\nvar MÍNIMO_PERSONAL_Y_FAMILIAR = 5550;\n\n// https://www2.agenciatributaria.gob.es/wlpl/PRET-R200/index.zul\n\nfunction es_substract_income_tax(income_yearly, overwrite_social_security) {\n\n  var social_security = MAX_SOCIAL_SECURITY_EMPLOYED_MONTHLY * 12;\n\n  if (income_yearly*COTIZACION_SEGURIDAD_SOCIAL_TOTAL <= MAX_SOCIAL_SECURITY_EMPLOYED_MONTHLY * 12) {\n\n    social_security = income_yearly*COTIZACION_SEGURIDAD_SOCIAL_TOTAL;\n\n  }\n\n  if (overwrite_social_security != null) {\n\n    social_security = overwrite_social_security;\n\n  }\n\n  var relevant_income = income_yearly - social_security - OTROS_GASTOS_CUANTÍA_FIJA_CON_CARÁCTER_GENERAL;\n\n  //  - MÍNIMO_PERSONAL_Y_FAMILIAR\n\n  var tax_of_relevant_income = es_calculate_income_tax(relevant_income) - es_calculate_income_tax(MÍNIMO_PERSONAL_Y_FAMILIAR);\n\n  var result = Math.round((income_yearly - tax_of_relevant_income - social_security) * 100)/100;\n\n  return result;\n\n}\n\nfunction es_substract_income_tax_monthly(income_monthly, overwrite_social_security) {\n\n  var yearly = es_substract_income_tax(income_monthly * 12, overwrite_social_security * 12);\n\n  var monthly = yearly / 12;\n\n  return monthly;\n\n}\n\nfunction es_calculate_income_tax(value) {\n\n  var sum = 0;\n\n  var tax1 = calculate_tax_by_slice(value, 0, 12450, 19);\n\n  var tax2 = calculate_tax_by_slice(value, 12450, 20200, 24);\n\n  var tax3 = calculate_tax_by_slice(value, 20200, 35200, 30);\n\n  var tax4 = calculate_tax_by_slice(value, 35200, 60000, 37);\n\n  var tax5 = calculate_tax_by_slice(value, 60000, 300000, 45);\n\n  var tax6 = calculate_tax_by_slice(value, 300000, 100000000, 47);\n\n  var all = tax1 + tax2 + tax3 + tax4 + tax5 + tax6;\n\n  return all;\n\n}\n\nfunction calculate_tax_by_slice(total, from_currency, to_currency, percentage) {\n\n  if (total < from_currency) {\n\n    return 0;\n\n  }\n\n \n\n  if (total > to_currency) {\n\n    var to_subtract = Math.abs(to_currency - total);\n\n    total = total - to_subtract;\n\n  }\n\n \n\n  var taxable_amount = total - from_currency;\n\n  var percentage_factor = percentage/100;\n\n  var tax_amount = taxable_amount * percentage_factor;\n\n \n\n  return tax_amount;\n\n}\n\nfunction test_irpf() {\n\n  var salario_annual = 28000;\n\n  var cotizar = cotizar_autonomo_mensual(salario_annual/12);\n\n  var result = es_substract_income_tax_monthly(salario_annual/cotizar);\n\n  return result;\n\n}", "url": "https://wpnews.pro/news/google-sheets-irpf-seguridad-social-spain-formula", "canonical_source": "https://gist.github.com/straach/30789d4c30fb5174ec52ea7521cc4e4a", "published_at": "2022-01-01 10:12:55+00:00", "updated_at": "2026-05-22 08:59:13.011758+00:00", "lang": "en", "topics": [], "entities": ["Google Sheets", "Seguridad Social", "IRPF", "Spain", "Grupo 2000"], "alternates": {"html": "https://wpnews.pro/news/google-sheets-irpf-seguridad-social-spain-formula", "markdown": "https://wpnews.pro/news/google-sheets-irpf-seguridad-social-spain-formula.md", "text": "https://wpnews.pro/news/google-sheets-irpf-seguridad-social-spain-formula.txt", "jsonld": "https://wpnews.pro/news/google-sheets-irpf-seguridad-social-spain-formula.jsonld"}}