---
title: "Class Group and Unit Group"
canonical: "https://docs.magma-maths.org/v2.30-1/GlobalFields/NumberFields/class-unit-group.html"
source: "https://docs.magma-maths.org/v2.30-1/GlobalFields/NumberFields/class-unit-group.md"
part: "Global Fields"
chapter: "Number Fields"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Global Fields", "source": "https://docs.magma-maths.org/v2.30-1/GlobalFields/index-global-fields.md"}
  - {"title": "Number Fields", "source": "https://docs.magma-maths.org/v2.30-1/GlobalFields/NumberFields/index-number-fields.md"}
prev: {"title": "Element Operations", "source": "https://docs.magma-maths.org/v2.30-1/GlobalFields/NumberFields/operation-element.md"}
next: {"title": "Galois Theory", "source": "https://docs.magma-maths.org/v2.30-1/GlobalFields/NumberFields/galois-theory.md"}
examples:
  - "ex-c8082f"
---

# Class Group and Unit Group

The `ClassGroup` routine and related functions are described in Section [Ideal Class Groups](https://docs.magma-maths.org/v2.30-1/GlobalFields/NumberFieldsAndOrders/ideal-class-group.md#rngord-clg). The routines for computing units in maximal orders of number fields are described in Section [Unit Groups](https://docs.magma-maths.org/v2.30-1/GlobalFields/NumberFieldsAndOrders/unit-group.md#rngord-unit).

<a id="example-ex-c8082f"></a>
## `Example: Class Group and Unit Group (ex-c8082f)`

In our field defined by $x^4 - 420*x^2 + 40000$, we obtain the class and unit groups as follows.

```magma
> R<x> := PolynomialRing(Integers());
> f := x^4 - 420*x^2 + 40000;
> K<y> := NumberField(f);
> C := ClassGroup(K);
> C;
Abelian Group of order 1
> U := UnitGroup(K);
> U;
Abelian Group isomorphic to Z/2 + Z + Z + Z
Defined on 4 generators
Relations:
      2*U.1 = 0
> T := TorsionUnitGroup(K);
> T;
Abelian Group isomorphic to Z/2
Defined on 1 generator
Relations:
    2*T.1 = 0
```
