{
  "id": "class-width",
  "version": "0ff475d88aa8",
  "status": "published",
  "name": "Class Width Calculator",
  "question": "What class width do I use?",
  "summary": "Finds the class width for a frequency table or histogram from the smallest and largest data values and the number of classes, rounded up so that no value falls on a class boundary.",
  "category": "statistics",
  "subcategory": "descriptive",
  "url": "https://www.acalculator.org/statistics/class-width-calculator",
  "markdown": "https://www.acalculator.org/statistics/class-width-calculator.md",
  "kind": "function",
  "method": "Starting point = smallest − ½ × 10^−d; ending value = largest + ½ × 10^−d (d = decimal places in the data); width before rounding = (ending value − starting point) ÷ classes; class width = that width rounded up to a multiple of the step.",
  "assumptions": [
    "Classes have equal widths and start at the starting point, half a data unit below the smallest value, so no data value falls on a boundary.",
    "A width that is already a multiple of the rounding step is kept as it is.",
    "The suggested number of classes is √n rounded to the nearest whole number, a guideline some authors follow."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "min": {
        "title": "Smallest data value",
        "description": "The smallest number in the data set.",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      },
      "max": {
        "title": "Largest data value",
        "description": "The largest number in the data set.",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      },
      "k": {
        "title": "Number of classes",
        "description": "How many classes (bars) the table or histogram should have.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000
      },
      "dp": {
        "title": "Decimal places in the data",
        "description": "The most decimal places any data value has: 0 for whole numbers, 1 for values such as 61.5.",
        "type": "integer",
        "minimum": 0,
        "maximum": 6
      },
      "step": {
        "title": "Round the width up to a multiple of",
        "description": "The rounding step for the class width: 1 rounds up to a whole number, 0.1 to a tenth.",
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 1000000000000
      },
      "n": {
        "title": "Number of data values (optional)",
        "description": "How many values the data set has, for a suggested number of classes (about √n).",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000000000
      }
    }
  },
  "outputs": {
    "width": {
      "label": "Class width",
      "description": "The width before rounding, rounded up to the next multiple of the rounding step (kept if it is one).",
      "format": "number"
    },
    "raw": {
      "label": "Width before rounding",
      "description": "(Ending value − starting point) ÷ number of classes.",
      "format": "number"
    },
    "simple": {
      "label": "Range ÷ number of classes",
      "description": "(Largest − smallest) ÷ number of classes, the short formula.",
      "format": "number"
    },
    "range": {
      "label": "Range",
      "description": "Largest data value − smallest data value.",
      "format": "number"
    },
    "start": {
      "label": "Starting point",
      "description": "The lower boundary of the first class: the smallest value − half a data unit.",
      "format": "number"
    },
    "end": {
      "label": "Ending value",
      "description": "The largest value + half a data unit.",
      "format": "number"
    },
    "top": {
      "label": "Last class ends at",
      "description": "Starting point + number of classes × class width.",
      "format": "number"
    },
    "suggested": {
      "label": "Suggested number of classes (√n)",
      "description": "The square root of the number of data values, rounded to the nearest whole number.",
      "format": "integer"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "min": 60,
      "max": 74,
      "k": 8,
      "dp": 1,
      "step": 1
    },
    "outputs": {
      "width": 2,
      "raw": 1.7625,
      "simple": 1.75,
      "range": 14,
      "start": 59.95,
      "end": 74.05,
      "top": 75.95
    },
    "text": "With 8 classes from 60 to 74, use a class width of 2."
  },
  "examples": [
    {
      "given": {
        "min": 60,
        "max": 74,
        "k": 8,
        "dp": 1,
        "step": 1
      },
      "expect": {
        "start": 59.95,
        "end": 74.05,
        "raw": 1.7625,
        "width": 2,
        "simple": 1.75,
        "range": 14,
        "top": 75.95
      },
      "source": "OpenStax, Introductory Statistics 2e, §2.2 Histograms, Frequency Polygons, and Time Series Graphs (Example 2.7: start 60 − 0.05 = 59.95, end 74 + 0.05 = 74.05, (74.05 − 59.95) ÷ 8 = 1.76, rounded up to 2; Example 2.8: 0.5 to 6.5 in 6 bars of width 1; about √n bars), https://openstax.org/books/introductory-statistics-2e/pages/2-2-histograms-frequency-polygons-and-time-series-graphs (retrieved 2026-10-18); hand calculation in content.mdx"
    },
    {
      "given": {
        "min": 1,
        "max": 6,
        "k": 6,
        "dp": 0,
        "step": 1
      },
      "expect": {
        "start": 0.5,
        "end": 6.5,
        "raw": 1,
        "width": 1,
        "top": 6.5
      },
      "source": "OpenStax, Introductory Statistics 2e, §2.2 Histograms, Frequency Polygons, and Time Series Graphs (Example 2.7: start 60 − 0.05 = 59.95, end 74 + 0.05 = 74.05, (74.05 − 59.95) ÷ 8 = 1.76, rounded up to 2; Example 2.8: 0.5 to 6.5 in 6 bars of width 1; about √n bars), https://openstax.org/books/introductory-statistics-2e/pages/2-2-histograms-frequency-polygons-and-time-series-graphs (retrieved 2026-10-18); hand calculation in content.mdx"
    },
    {
      "given": {
        "min": 10,
        "max": 50,
        "k": 4,
        "dp": 0,
        "step": 1,
        "n": 150
      },
      "expect": {
        "raw": 10.25,
        "width": 11,
        "simple": 10,
        "start": 9.5,
        "top": 53.5,
        "suggested": 12
      },
      "source": "OpenStax, Introductory Statistics 2e, §2.2 Histograms, Frequency Polygons, and Time Series Graphs (Example 2.7: start 60 − 0.05 = 59.95, end 74 + 0.05 = 74.05, (74.05 − 59.95) ÷ 8 = 1.76, rounded up to 2; Example 2.8: 0.5 to 6.5 in 6 bars of width 1; about √n bars), https://openstax.org/books/introductory-statistics-2e/pages/2-2-histograms-frequency-polygons-and-time-series-graphs (retrieved 2026-10-18) (150 values: √150 ≈ 12.25, so 12 bars); hand calculation in content.mdx"
    },
    {
      "given": {
        "min": 2.13,
        "max": 9.87,
        "k": 5,
        "dp": 2,
        "step": 0.1
      },
      "expect": {
        "start": 2.125,
        "end": 9.875,
        "raw": 1.55,
        "width": 1.6,
        "top": 10.125
      },
      "source": "OpenStax, Introductory Statistics 2e, §2.2 Histograms, Frequency Polygons, and Time Series Graphs (Example 2.7: start 60 − 0.05 = 59.95, end 74 + 0.05 = 74.05, (74.05 − 59.95) ÷ 8 = 1.76, rounded up to 2; Example 2.8: 0.5 to 6.5 in 6 bars of width 1; about √n bars), https://openstax.org/books/introductory-statistics-2e/pages/2-2-histograms-frequency-polygons-and-time-series-graphs (retrieved 2026-10-18); hand calculation in content.mdx: (9.875 − 2.125) ÷ 5 = 1.55, up to 1.6"
    }
  ],
  "sources": [
    "OpenStax, Introductory Statistics 2e, §2.2 Histograms, Frequency Polygons, and Time Series Graphs: the starting point is one decimal place beyond the data (60 − 0.05 = 59.95), the ending value 74 + 0.05 = 74.05, the width (ending value − starting point) ÷ number of bars = 1.76, rounded up to 2; Example 2.8 runs from 0.5 to 6.5; five to 15 bars; about √n bars (150 values, 12 bars). https://openstax.org/books/introductory-statistics-2e/pages/2-2-histograms-frequency-polygons-and-time-series-graphs (retrieved 2026-10-18)"
  ],
  "related": [
    "frequency-distribution",
    "range",
    "box-plot",
    "percentile",
    "mean-median-mode"
  ],
  "changelog": []
}
